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.
5 #ifndef CHROME_BROWSER_SPEECH_TTS_MESSAGE_FILTER_H_
6 #define CHROME_BROWSER_SPEECH_TTS_MESSAGE_FILTER_H_
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"
18 class TtsMessageFilter
19 : public content::BrowserMessageFilter,
20 public UtteranceEventDelegate,
21 public VoicesChangedDelegate {
23 explicit TtsMessageFilter(int render_process_id,
24 content::BrowserContext* browser_context);
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;
33 // UtteranceEventDelegate implementation.
34 void OnTtsEvent(Utterance* utterance,
35 TtsEventType event_type,
37 const std::string& error_message) override;
39 // VoicesChangedDelegate implementation.
40 void OnVoicesChanged() override;
43 friend class content::BrowserThread;
44 friend class base::DeleteHelper<TtsMessageFilter>;
46 ~TtsMessageFilter() override;
48 void OnInitializeVoiceList();
49 void OnSpeak(const TtsUtteranceRequest& utterance);
54 void OnChannelClosingInUIThread();
58 // Thread-safe check to make sure this class is still valid and not
59 // about to be deleted.
62 int render_process_id_;
63 content::BrowserContext* browser_context_;
64 mutable base::Lock mutex_;
67 DISALLOW_COPY_AND_ASSIGN(TtsMessageFilter);
70 #endif // CHROME_BROWSER_SPEECH_TTS_MESSAGE_FILTER_H_