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

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

Issue 188633003: Revert of Eliminate the dependence of tts extension API for tts_controller.cc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 TtsExtensionEngine* TtsExtensionEngine::GetInstance() { 63 void GetExtensionVoices(Profile* profile, std::vector<VoiceData>* out_voices) {
64 return Singleton<TtsExtensionEngine>::get();
65 }
66
67 void TtsExtensionEngine::GetVoices(Profile* profile,
68 std::vector<VoiceData>* out_voices) {
69 ExtensionService* service = profile->GetExtensionService(); 64 ExtensionService* service = profile->GetExtensionService();
70 DCHECK(service); 65 DCHECK(service);
71 EventRouter* event_router = 66 EventRouter* event_router =
72 ExtensionSystem::Get(profile)->event_router(); 67 ExtensionSystem::Get(profile)->event_router();
73 DCHECK(event_router); 68 DCHECK(event_router);
74 69
75 bool is_offline = (net::NetworkChangeNotifier::GetConnectionType() == 70 bool is_offline = (net::NetworkChangeNotifier::GetConnectionType() ==
76 net::NetworkChangeNotifier::CONNECTION_NONE); 71 net::NetworkChangeNotifier::CONNECTION_NONE);
77 72
78 const extensions::ExtensionSet* extensions = service->extensions(); 73 const extensions::ExtensionSet* extensions = service->extensions();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 // queueing and send interrupted and cancelled events. 120 // queueing and send interrupted and cancelled events.
126 if (voice.event_types.find(constants::kEventTypeEnd) != 121 if (voice.event_types.find(constants::kEventTypeEnd) !=
127 voice.event_types.end()) { 122 voice.event_types.end()) {
128 result_voice.events.insert(TTS_EVENT_CANCELLED); 123 result_voice.events.insert(TTS_EVENT_CANCELLED);
129 result_voice.events.insert(TTS_EVENT_INTERRUPTED); 124 result_voice.events.insert(TTS_EVENT_INTERRUPTED);
130 } 125 }
131 } 126 }
132 } 127 }
133 } 128 }
134 129
135 void TtsExtensionEngine::Speak(Utterance* utterance, 130 void ExtensionTtsEngineSpeak(Utterance* utterance, const VoiceData& voice) {
136 const VoiceData& voice) {
137 // See if the engine supports the "end" event; if so, we can keep the 131 // See if the engine supports the "end" event; if so, we can keep the
138 // utterance around and track it. If not, we're finished with this 132 // utterance around and track it. If not, we're finished with this
139 // utterance now. 133 // utterance now.
140 bool sends_end_event = voice.events.find(TTS_EVENT_END) != voice.events.end(); 134 bool sends_end_event = voice.events.find(TTS_EVENT_END) != voice.events.end();
141 135
142 scoped_ptr<base::ListValue> args(new base::ListValue()); 136 scoped_ptr<base::ListValue> args(new base::ListValue());
143 args->Set(0, base::Value::CreateStringValue(utterance->text())); 137 args->Set(0, base::Value::CreateStringValue(utterance->text()));
144 138
145 // Pass through most options to the speech engine, but remove some 139 // Pass through most options to the speech engine, but remove some
146 // that are handled internally. 140 // that are handled internally.
(...skipping 23 matching lines...) Expand all
170 args->Set(1, options.release()); 164 args->Set(1, options.release());
171 args->Set(2, base::Value::CreateIntegerValue(utterance->id())); 165 args->Set(2, base::Value::CreateIntegerValue(utterance->id()));
172 166
173 scoped_ptr<extensions::Event> event(new extensions::Event( 167 scoped_ptr<extensions::Event> event(new extensions::Event(
174 tts_engine_events::kOnSpeak, args.Pass())); 168 tts_engine_events::kOnSpeak, args.Pass()));
175 event->restrict_to_browser_context = utterance->profile(); 169 event->restrict_to_browser_context = utterance->profile();
176 ExtensionSystem::Get(utterance->profile())->event_router()-> 170 ExtensionSystem::Get(utterance->profile())->event_router()->
177 DispatchEventToExtension(utterance->extension_id(), event.Pass()); 171 DispatchEventToExtension(utterance->extension_id(), event.Pass());
178 } 172 }
179 173
180 void TtsExtensionEngine::Stop(Utterance* utterance) { 174 void ExtensionTtsEngineStop(Utterance* utterance) {
181 scoped_ptr<base::ListValue> args(new base::ListValue()); 175 scoped_ptr<base::ListValue> args(new base::ListValue());
182 scoped_ptr<extensions::Event> event(new extensions::Event( 176 scoped_ptr<extensions::Event> event(new extensions::Event(
183 tts_engine_events::kOnStop, args.Pass())); 177 tts_engine_events::kOnStop, args.Pass()));
184 event->restrict_to_browser_context = utterance->profile(); 178 event->restrict_to_browser_context = utterance->profile();
185 ExtensionSystem::Get(utterance->profile())->event_router()-> 179 ExtensionSystem::Get(utterance->profile())->event_router()->
186 DispatchEventToExtension(utterance->extension_id(), event.Pass()); 180 DispatchEventToExtension(utterance->extension_id(), event.Pass());
187 } 181 }
188 182
189 void TtsExtensionEngine::Pause(Utterance* utterance) { 183 void ExtensionTtsEnginePause(Utterance* utterance) {
190 scoped_ptr<base::ListValue> args(new base::ListValue()); 184 scoped_ptr<base::ListValue> args(new base::ListValue());
191 scoped_ptr<extensions::Event> event(new extensions::Event( 185 scoped_ptr<extensions::Event> event(new extensions::Event(
192 tts_engine_events::kOnPause, args.Pass())); 186 tts_engine_events::kOnPause, args.Pass()));
193 Profile* profile = utterance->profile(); 187 Profile* profile = utterance->profile();
194 event->restrict_to_browser_context = profile; 188 event->restrict_to_browser_context = profile;
195 EventRouter* event_router = ExtensionSystem::Get(profile)->event_router(); 189 EventRouter* event_router = ExtensionSystem::Get(profile)->event_router();
196 std::string id = utterance->extension_id(); 190 std::string id = utterance->extension_id();
197 event_router->DispatchEventToExtension(id, event.Pass()); 191 event_router->DispatchEventToExtension(id, event.Pass());
198 WarnIfMissingPauseOrResumeListener(profile, event_router, id); 192 WarnIfMissingPauseOrResumeListener(profile, event_router, id);
199 } 193 }
200 194
201 void TtsExtensionEngine::Resume(Utterance* utterance) { 195 void ExtensionTtsEngineResume(Utterance* utterance) {
202 scoped_ptr<base::ListValue> args(new base::ListValue()); 196 scoped_ptr<base::ListValue> args(new base::ListValue());
203 scoped_ptr<extensions::Event> event(new extensions::Event( 197 scoped_ptr<extensions::Event> event(new extensions::Event(
204 tts_engine_events::kOnResume, args.Pass())); 198 tts_engine_events::kOnResume, args.Pass()));
205 Profile* profile = utterance->profile(); 199 Profile* profile = utterance->profile();
206 event->restrict_to_browser_context = profile; 200 event->restrict_to_browser_context = profile;
207 EventRouter* event_router = ExtensionSystem::Get(profile)->event_router(); 201 EventRouter* event_router = ExtensionSystem::Get(profile)->event_router();
208 std::string id = utterance->extension_id(); 202 std::string id = utterance->extension_id();
209 event_router->DispatchEventToExtension(id, event.Pass()); 203 event_router->DispatchEventToExtension(id, event.Pass());
210 WarnIfMissingPauseOrResumeListener(profile, event_router, id); 204 WarnIfMissingPauseOrResumeListener(profile, event_router, id);
211 } 205 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 utterance_id, TTS_EVENT_PAUSE, char_index, std::string()); 269 utterance_id, TTS_EVENT_PAUSE, char_index, std::string());
276 } else if (event_type == constants::kEventTypeResume) { 270 } else if (event_type == constants::kEventTypeResume) {
277 controller->OnTtsEvent( 271 controller->OnTtsEvent(
278 utterance_id, TTS_EVENT_RESUME, char_index, std::string()); 272 utterance_id, TTS_EVENT_RESUME, char_index, std::string());
279 } else { 273 } else {
280 EXTENSION_FUNCTION_VALIDATE(false); 274 EXTENSION_FUNCTION_VALIDATE(false);
281 } 275 }
282 276
283 return true; 277 return true;
284 } 278 }
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