OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/speech/tts_message_filter.h" | 5 #include "chrome/browser/speech/tts_message_filter.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/speech/tts_controller.h" | 10 #include "chrome/browser/speech/tts_controller.h" |
11 #include "chrome/browser/speech/tts_message_filter.h" | 11 #include "chrome/browser/speech/tts_message_filter.h" |
12 #include "content/public/browser/browser_context.h" | 12 #include "content/public/browser/browser_context.h" |
13 #include "content/public/browser/render_process_host.h" | 13 #include "content/public/browser/render_process_host.h" |
14 | 14 |
15 using content::BrowserThread; | 15 using content::BrowserThread; |
16 | 16 |
17 TtsMessageFilter::TtsMessageFilter(int render_process_id, Profile* profile) | 17 TtsMessageFilter::TtsMessageFilter(int render_process_id, Profile* profile) |
18 : render_process_id_(render_process_id), | 18 : render_process_id_(render_process_id), |
19 profile_(profile) { | 19 profile_(profile) { |
20 } | 20 TtsController::GetInstance()->AddVoicesChangedDelegate(this); |
21 | |
22 TtsMessageFilter::~TtsMessageFilter() { | |
23 } | 21 } |
24 | 22 |
25 void TtsMessageFilter::OverrideThreadForMessage( | 23 void TtsMessageFilter::OverrideThreadForMessage( |
26 const IPC::Message& message, BrowserThread::ID* thread) { | 24 const IPC::Message& message, BrowserThread::ID* thread) { |
27 switch (message.type()) { | 25 switch (message.type()) { |
28 case TtsHostMsg_InitializeVoiceList::ID: | 26 case TtsHostMsg_InitializeVoiceList::ID: |
29 case TtsHostMsg_Speak::ID: | 27 case TtsHostMsg_Speak::ID: |
30 case TtsHostMsg_Pause::ID: | 28 case TtsHostMsg_Pause::ID: |
31 case TtsHostMsg_Resume::ID: | 29 case TtsHostMsg_Resume::ID: |
32 case TtsHostMsg_Cancel::ID: | 30 case TtsHostMsg_Cancel::ID: |
33 *thread = BrowserThread::UI; | 31 *thread = BrowserThread::UI; |
34 break; | 32 break; |
35 } | 33 } |
36 } | 34 } |
37 | 35 |
38 bool TtsMessageFilter::OnMessageReceived(const IPC::Message& message, | 36 bool TtsMessageFilter::OnMessageReceived(const IPC::Message& message, |
39 bool* message_was_ok) { | 37 bool* message_was_ok) { |
40 bool handled = true; | 38 bool handled = true; |
41 IPC_BEGIN_MESSAGE_MAP_EX(TtsMessageFilter, message, *message_was_ok) | 39 IPC_BEGIN_MESSAGE_MAP_EX(TtsMessageFilter, message, *message_was_ok) |
42 IPC_MESSAGE_HANDLER(TtsHostMsg_InitializeVoiceList, OnInitializeVoiceList) | 40 IPC_MESSAGE_HANDLER(TtsHostMsg_InitializeVoiceList, OnInitializeVoiceList) |
43 IPC_MESSAGE_HANDLER(TtsHostMsg_Speak, OnSpeak) | 41 IPC_MESSAGE_HANDLER(TtsHostMsg_Speak, OnSpeak) |
44 IPC_MESSAGE_HANDLER(TtsHostMsg_Pause, OnPause) | 42 IPC_MESSAGE_HANDLER(TtsHostMsg_Pause, OnPause) |
45 IPC_MESSAGE_HANDLER(TtsHostMsg_Resume, OnResume) | 43 IPC_MESSAGE_HANDLER(TtsHostMsg_Resume, OnResume) |
46 IPC_MESSAGE_HANDLER(TtsHostMsg_Cancel, OnCancel) | 44 IPC_MESSAGE_HANDLER(TtsHostMsg_Cancel, OnCancel) |
47 IPC_MESSAGE_UNHANDLED(handled = false) | 45 IPC_MESSAGE_UNHANDLED(handled = false) |
48 IPC_END_MESSAGE_MAP() | 46 IPC_END_MESSAGE_MAP() |
49 return handled; | 47 return handled; |
50 } | 48 } |
51 | 49 |
| 50 void TtsMessageFilter::OnChannelClosing() { |
| 51 TtsController::GetInstance()->RemoveVoicesChangedDelegate(this); |
| 52 } |
| 53 |
52 void TtsMessageFilter::OnInitializeVoiceList() { | 54 void TtsMessageFilter::OnInitializeVoiceList() { |
53 TtsController* tts_controller = TtsController::GetInstance(); | 55 TtsController* tts_controller = TtsController::GetInstance(); |
54 std::vector<VoiceData> voices; | 56 std::vector<VoiceData> voices; |
55 tts_controller->GetVoices(profile_, &voices); | 57 tts_controller->GetVoices(profile_, &voices); |
56 | 58 |
57 std::vector<TtsVoice> out_voices; | 59 std::vector<TtsVoice> out_voices; |
58 out_voices.resize(voices.size()); | 60 out_voices.resize(voices.size()); |
59 for (size_t i = 0; i < voices.size(); ++i) { | 61 for (size_t i = 0; i < voices.size(); ++i) { |
60 TtsVoice& out_voice = out_voices[i]; | 62 TtsVoice& out_voice = out_voices[i]; |
61 out_voice.voice_uri = voices[i].name; | 63 out_voice.voice_uri = voices[i].name; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 break; | 125 break; |
124 case TTS_EVENT_CANCELLED: | 126 case TTS_EVENT_CANCELLED: |
125 Send(new TtsMsg_WasCancelled(utterance->src_id())); | 127 Send(new TtsMsg_WasCancelled(utterance->src_id())); |
126 break; | 128 break; |
127 case TTS_EVENT_ERROR: | 129 case TTS_EVENT_ERROR: |
128 Send(new TtsMsg_SpeakingErrorOccurred( | 130 Send(new TtsMsg_SpeakingErrorOccurred( |
129 utterance->src_id(), error_message)); | 131 utterance->src_id(), error_message)); |
130 break; | 132 break; |
131 } | 133 } |
132 } | 134 } |
| 135 |
| 136 void TtsMessageFilter::OnVoicesChanged() { |
| 137 OnInitializeVoiceList(); |
| 138 } |
| 139 |
| 140 TtsMessageFilter::~TtsMessageFilter() { |
| 141 } |
OLD | NEW |