Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / speech / tts_message_filter.h
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_SPEECH_TTS_MESSAGE_FILTER_H_
6 #define CHROME_BROWSER_SPEECH_TTS_MESSAGE_FILTER_H_
7
8 #include "base/memory/weak_ptr.h"
9 #include "base/synchronization/lock.h"
10 #include "chrome/browser/speech/tts_controller.h"
11 #include "chrome/common/tts_messages.h"
12 #include "content/public/browser/browser_message_filter.h"
13
14 namespace content {
15 class BrowserContext;
16 }
17
18 class TtsMessageFilter
19     : public content::BrowserMessageFilter,
20       public UtteranceEventDelegate,
21       public VoicesChangedDelegate {
22  public:
23   explicit TtsMessageFilter(int render_process_id,
24       content::BrowserContext* browser_context);
25
26   // content::BrowserMessageFilter implementation.
27   void OverrideThreadForMessage(const IPC::Message& message,
28                                 content::BrowserThread::ID* thread) override;
29   bool OnMessageReceived(const IPC::Message& message) override;
30   void OnChannelClosing() override;
31   void OnDestruct() const override;
32
33   // UtteranceEventDelegate implementation.
34   void OnTtsEvent(Utterance* utterance,
35                   TtsEventType event_type,
36                   int char_index,
37                   const std::string& error_message) override;
38
39   // VoicesChangedDelegate implementation.
40   void OnVoicesChanged() override;
41
42  private:
43   friend class content::BrowserThread;
44   friend class base::DeleteHelper<TtsMessageFilter>;
45
46   ~TtsMessageFilter() override;
47
48   void OnInitializeVoiceList();
49   void OnSpeak(const TtsUtteranceRequest& utterance);
50   void OnPause();
51   void OnResume();
52   void OnCancel();
53
54   void OnChannelClosingInUIThread();
55
56   void Cleanup();
57
58   // Thread-safe check to make sure this class is still valid and not
59   // about to be deleted.
60   bool Valid();
61
62   int render_process_id_;
63   content::BrowserContext* browser_context_;
64   mutable base::Lock mutex_;
65   mutable bool valid_;
66
67   DISALLOW_COPY_AND_ASSIGN(TtsMessageFilter);
68 };
69
70 #endif  // CHROME_BROWSER_SPEECH_TTS_MESSAGE_FILTER_H_