Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(572)

Side by Side Diff: chrome/browser/speech/extension_api/tts_engine_extension_api.cc

Issue 374243004: Eliminate the dependence of tts extension API form tts_controller.cc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Skip the instantiation of TtsExtensionEngine for android. Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/extension_api/tts_engine_extension_api.h" 5 #include "chrome/browser/speech/extension_api/tts_engine_extension_api.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 extensions::ExtensionHost* host = 55 extensions::ExtensionHost* host =
56 process_manager->GetBackgroundHostForExtension(extension_id); 56 process_manager->GetBackgroundHostForExtension(extension_id);
57 host->render_process_host()->Send(new ExtensionMsg_AddMessageToConsole( 57 host->render_process_host()->Send(new ExtensionMsg_AddMessageToConsole(
58 host->render_view_host()->GetRoutingID(), 58 host->render_view_host()->GetRoutingID(),
59 content::CONSOLE_MESSAGE_LEVEL_WARNING, 59 content::CONSOLE_MESSAGE_LEVEL_WARNING,
60 constants::kErrorMissingPauseOrResume)); 60 constants::kErrorMissingPauseOrResume));
61 } 61 }
62 62
63 } // namespace 63 } // namespace
64 64
65 void GetExtensionVoices(Profile* profile, std::vector<VoiceData>* out_voices) { 65 TtsExtensionEngine* TtsExtensionEngine::GetInstance() {
66 return Singleton<TtsExtensionEngine>::get();
67 }
68
69 void TtsExtensionEngine::GetVoices(Profile* profile,
70 std::vector<VoiceData>* out_voices) {
66 EventRouter* event_router = EventRouter::Get(profile); 71 EventRouter* event_router = EventRouter::Get(profile);
67 DCHECK(event_router); 72 DCHECK(event_router);
68 73
69 bool is_offline = (net::NetworkChangeNotifier::GetConnectionType() == 74 bool is_offline = (net::NetworkChangeNotifier::GetConnectionType() ==
70 net::NetworkChangeNotifier::CONNECTION_NONE); 75 net::NetworkChangeNotifier::CONNECTION_NONE);
71 76
72 const extensions::ExtensionSet& extensions = 77 const extensions::ExtensionSet& extensions =
73 extensions::ExtensionRegistry::Get(profile)->enabled_extensions(); 78 extensions::ExtensionRegistry::Get(profile)->enabled_extensions();
74 extensions::ExtensionSet::const_iterator iter; 79 extensions::ExtensionSet::const_iterator iter;
75 for (iter = extensions.begin(); iter != extensions.end(); ++iter) { 80 for (iter = extensions.begin(); iter != extensions.end(); ++iter) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 // queueing and send interrupted and cancelled events. 125 // queueing and send interrupted and cancelled events.
121 if (voice.event_types.find(constants::kEventTypeEnd) != 126 if (voice.event_types.find(constants::kEventTypeEnd) !=
122 voice.event_types.end()) { 127 voice.event_types.end()) {
123 result_voice.events.insert(TTS_EVENT_CANCELLED); 128 result_voice.events.insert(TTS_EVENT_CANCELLED);
124 result_voice.events.insert(TTS_EVENT_INTERRUPTED); 129 result_voice.events.insert(TTS_EVENT_INTERRUPTED);
125 } 130 }
126 } 131 }
127 } 132 }
128 } 133 }
129 134
130 void ExtensionTtsEngineSpeak(Utterance* utterance, const VoiceData& voice) { 135 void TtsExtensionEngine::Speak(Utterance* utterance,
136 const VoiceData& voice) {
131 // See if the engine supports the "end" event; if so, we can keep the 137 // See if the engine supports the "end" event; if so, we can keep the
132 // utterance around and track it. If not, we're finished with this 138 // utterance around and track it. If not, we're finished with this
133 // utterance now. 139 // utterance now.
134 bool sends_end_event = voice.events.find(TTS_EVENT_END) != voice.events.end(); 140 bool sends_end_event = voice.events.find(TTS_EVENT_END) != voice.events.end();
135 141
136 scoped_ptr<base::ListValue> args(new base::ListValue()); 142 scoped_ptr<base::ListValue> args(new base::ListValue());
137 args->Set(0, base::Value::CreateStringValue(utterance->text())); 143 args->Set(0, base::Value::CreateStringValue(utterance->text()));
138 144
139 // Pass through most options to the speech engine, but remove some 145 // Pass through most options to the speech engine, but remove some
140 // that are handled internally. 146 // that are handled internally.
(...skipping 23 matching lines...) Expand all
164 args->Set(1, options.release()); 170 args->Set(1, options.release());
165 args->Set(2, base::Value::CreateIntegerValue(utterance->id())); 171 args->Set(2, base::Value::CreateIntegerValue(utterance->id()));
166 172
167 scoped_ptr<extensions::Event> event(new extensions::Event( 173 scoped_ptr<extensions::Event> event(new extensions::Event(
168 tts_engine_events::kOnSpeak, args.Pass())); 174 tts_engine_events::kOnSpeak, args.Pass()));
169 event->restrict_to_browser_context = utterance->profile(); 175 event->restrict_to_browser_context = utterance->profile();
170 EventRouter::Get(utterance->profile()) 176 EventRouter::Get(utterance->profile())
171 ->DispatchEventToExtension(utterance->extension_id(), event.Pass()); 177 ->DispatchEventToExtension(utterance->extension_id(), event.Pass());
172 } 178 }
173 179
174 void ExtensionTtsEngineStop(Utterance* utterance) { 180 void TtsExtensionEngine::Stop(Utterance* utterance) {
175 scoped_ptr<base::ListValue> args(new base::ListValue()); 181 scoped_ptr<base::ListValue> args(new base::ListValue());
176 scoped_ptr<extensions::Event> event(new extensions::Event( 182 scoped_ptr<extensions::Event> event(new extensions::Event(
177 tts_engine_events::kOnStop, args.Pass())); 183 tts_engine_events::kOnStop, args.Pass()));
178 event->restrict_to_browser_context = utterance->profile(); 184 event->restrict_to_browser_context = utterance->profile();
179 EventRouter::Get(utterance->profile()) 185 EventRouter::Get(utterance->profile())
180 ->DispatchEventToExtension(utterance->extension_id(), event.Pass()); 186 ->DispatchEventToExtension(utterance->extension_id(), event.Pass());
181 } 187 }
182 188
183 void ExtensionTtsEnginePause(Utterance* utterance) { 189 void TtsExtensionEngine::Pause(Utterance* utterance) {
184 scoped_ptr<base::ListValue> args(new base::ListValue()); 190 scoped_ptr<base::ListValue> args(new base::ListValue());
185 scoped_ptr<extensions::Event> event(new extensions::Event( 191 scoped_ptr<extensions::Event> event(new extensions::Event(
186 tts_engine_events::kOnPause, args.Pass())); 192 tts_engine_events::kOnPause, args.Pass()));
187 Profile* profile = utterance->profile(); 193 Profile* profile = utterance->profile();
188 event->restrict_to_browser_context = profile; 194 event->restrict_to_browser_context = profile;
189 EventRouter* event_router = EventRouter::Get(profile); 195 EventRouter* event_router = EventRouter::Get(profile);
190 std::string id = utterance->extension_id(); 196 std::string id = utterance->extension_id();
191 event_router->DispatchEventToExtension(id, event.Pass()); 197 event_router->DispatchEventToExtension(id, event.Pass());
192 WarnIfMissingPauseOrResumeListener(profile, event_router, id); 198 WarnIfMissingPauseOrResumeListener(profile, event_router, id);
193 } 199 }
194 200
195 void ExtensionTtsEngineResume(Utterance* utterance) { 201 void TtsExtensionEngine::Resume(Utterance* utterance) {
196 scoped_ptr<base::ListValue> args(new base::ListValue()); 202 scoped_ptr<base::ListValue> args(new base::ListValue());
197 scoped_ptr<extensions::Event> event(new extensions::Event( 203 scoped_ptr<extensions::Event> event(new extensions::Event(
198 tts_engine_events::kOnResume, args.Pass())); 204 tts_engine_events::kOnResume, args.Pass()));
199 Profile* profile = utterance->profile(); 205 Profile* profile = utterance->profile();
200 event->restrict_to_browser_context = profile; 206 event->restrict_to_browser_context = profile;
201 EventRouter* event_router = EventRouter::Get(profile); 207 EventRouter* event_router = EventRouter::Get(profile);
202 std::string id = utterance->extension_id(); 208 std::string id = utterance->extension_id();
203 event_router->DispatchEventToExtension(id, event.Pass()); 209 event_router->DispatchEventToExtension(id, event.Pass());
204 WarnIfMissingPauseOrResumeListener(profile, event_router, id); 210 WarnIfMissingPauseOrResumeListener(profile, event_router, id);
205 } 211 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 utterance_id, TTS_EVENT_PAUSE, char_index, std::string()); 275 utterance_id, TTS_EVENT_PAUSE, char_index, std::string());
270 } else if (event_type == constants::kEventTypeResume) { 276 } else if (event_type == constants::kEventTypeResume) {
271 controller->OnTtsEvent( 277 controller->OnTtsEvent(
272 utterance_id, TTS_EVENT_RESUME, char_index, std::string()); 278 utterance_id, TTS_EVENT_RESUME, char_index, std::string());
273 } else { 279 } else {
274 EXTENSION_FUNCTION_VALIDATE(false); 280 EXTENSION_FUNCTION_VALIDATE(false);
275 } 281 }
276 282
277 return true; 283 return true;
278 } 284 }
OLDNEW
« no previous file with comments | « chrome/browser/speech/extension_api/tts_engine_extension_api.h ('k') | chrome/browser/speech/tts_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698