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

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

Issue 181123004: Eliminate the dependence of tts extension API for tts_controller.cc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix compile issue for mac. Created 6 years, 9 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 ExtensionSystem::Get(profile)->process_manager(); 53 ExtensionSystem::Get(profile)->process_manager();
54 extensions::ExtensionHost* host = 54 extensions::ExtensionHost* host =
55 process_manager->GetBackgroundHostForExtension(extension_id); 55 process_manager->GetBackgroundHostForExtension(extension_id);
56 host->render_process_host()->Send(new ExtensionMsg_AddMessageToConsole( 56 host->render_process_host()->Send(new ExtensionMsg_AddMessageToConsole(
57 host->render_view_host()->GetRoutingID(), 57 host->render_view_host()->GetRoutingID(),
58 content::CONSOLE_MESSAGE_LEVEL_WARNING, 58 content::CONSOLE_MESSAGE_LEVEL_WARNING,
59 constants::kErrorMissingPauseOrResume)); 59 constants::kErrorMissingPauseOrResume));
60 }; 60 };
61 } // anonymous namespace 61 } // anonymous namespace
62 62
63 void GetExtensionVoices(Profile* profile, std::vector<VoiceData>* out_voices) { 63 TtsExtensionEngine* TtsExtensionEngine::GetInstance() {
64 return Singleton<TtsExtensionEngine>::get();
65 }
66
67 void TtsExtensionEngine::GetVoices(Profile* profile,
68 std::vector<VoiceData>* out_voices) {
64 ExtensionService* service = profile->GetExtensionService(); 69 ExtensionService* service = profile->GetExtensionService();
65 DCHECK(service); 70 DCHECK(service);
66 EventRouter* event_router = 71 EventRouter* event_router =
67 ExtensionSystem::Get(profile)->event_router(); 72 ExtensionSystem::Get(profile)->event_router();
68 DCHECK(event_router); 73 DCHECK(event_router);
69 74
70 bool is_offline = (net::NetworkChangeNotifier::GetConnectionType() == 75 bool is_offline = (net::NetworkChangeNotifier::GetConnectionType() ==
71 net::NetworkChangeNotifier::CONNECTION_NONE); 76 net::NetworkChangeNotifier::CONNECTION_NONE);
72 77
73 const extensions::ExtensionSet* extensions = service->extensions(); 78 const extensions::ExtensionSet* extensions = service->extensions();
(...skipping 46 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 ExtensionSystem::Get(utterance->profile())->event_router()-> 176 ExtensionSystem::Get(utterance->profile())->event_router()->
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 ExtensionSystem::Get(utterance->profile())->event_router()-> 185 ExtensionSystem::Get(utterance->profile())->event_router()->
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 = ExtensionSystem::Get(profile)->event_router(); 195 EventRouter* event_router = ExtensionSystem::Get(profile)->event_router();
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 = ExtensionSystem::Get(profile)->event_router(); 207 EventRouter* event_router = ExtensionSystem::Get(profile)->event_router();
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