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

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

Issue 448033002: Eliminate the dependency of Profile from TtsMessageFilter. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed compilation error on ChromeOS Created 6 years, 4 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 content::CONSOLE_MESSAGE_LEVEL_WARNING, 63 content::CONSOLE_MESSAGE_LEVEL_WARNING,
64 constants::kErrorMissingPauseOrResume)); 64 constants::kErrorMissingPauseOrResume));
65 } 65 }
66 66
67 } // namespace 67 } // namespace
68 68
69 TtsExtensionEngine* TtsExtensionEngine::GetInstance() { 69 TtsExtensionEngine* TtsExtensionEngine::GetInstance() {
70 return Singleton<TtsExtensionEngine>::get(); 70 return Singleton<TtsExtensionEngine>::get();
71 } 71 }
72 72
73 void TtsExtensionEngine::GetVoices(Profile* profile, 73 void TtsExtensionEngine::GetVoices(content::BrowserContext* browser_context,
74 std::vector<VoiceData>* out_voices) { 74 std::vector<VoiceData>* out_voices) {
75 Profile* profile = Profile::FromBrowserContext(browser_context);
75 EventRouter* event_router = EventRouter::Get(profile); 76 EventRouter* event_router = EventRouter::Get(profile);
76 DCHECK(event_router); 77 DCHECK(event_router);
77 78
78 bool is_offline = (net::NetworkChangeNotifier::GetConnectionType() == 79 bool is_offline = (net::NetworkChangeNotifier::GetConnectionType() ==
79 net::NetworkChangeNotifier::CONNECTION_NONE); 80 net::NetworkChangeNotifier::CONNECTION_NONE);
80 81
81 const extensions::ExtensionSet& extensions = 82 const extensions::ExtensionSet& extensions =
82 extensions::ExtensionRegistry::Get(profile)->enabled_extensions(); 83 extensions::ExtensionRegistry::Get(profile)->enabled_extensions();
83 extensions::ExtensionSet::const_iterator iter; 84 extensions::ExtensionSet::const_iterator iter;
84 for (iter = extensions.begin(); iter != extensions.end(); ++iter) { 85 for (iter = extensions.begin(); iter != extensions.end(); ++iter) {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 if (!options->HasKey(constants::kVoiceNameKey)) 170 if (!options->HasKey(constants::kVoiceNameKey))
170 options->SetString(constants::kVoiceNameKey, voice.name); 171 options->SetString(constants::kVoiceNameKey, voice.name);
171 if (!options->HasKey(constants::kLangKey)) 172 if (!options->HasKey(constants::kLangKey))
172 options->SetString(constants::kLangKey, voice.lang); 173 options->SetString(constants::kLangKey, voice.lang);
173 174
174 args->Append(options.release()); 175 args->Append(options.release());
175 args->AppendInteger(utterance->id()); 176 args->AppendInteger(utterance->id());
176 177
177 scoped_ptr<extensions::Event> event(new extensions::Event( 178 scoped_ptr<extensions::Event> event(new extensions::Event(
178 tts_engine_events::kOnSpeak, args.Pass())); 179 tts_engine_events::kOnSpeak, args.Pass()));
179 event->restrict_to_browser_context = utterance->profile(); 180 Profile* profile = Profile::FromBrowserContext(utterance->browser_context());
180 EventRouter::Get(utterance->profile()) 181 event->restrict_to_browser_context = profile;
182 EventRouter::Get(profile)
181 ->DispatchEventToExtension(utterance->extension_id(), event.Pass()); 183 ->DispatchEventToExtension(utterance->extension_id(), event.Pass());
182 } 184 }
183 185
184 void TtsExtensionEngine::Stop(Utterance* utterance) { 186 void TtsExtensionEngine::Stop(Utterance* utterance) {
185 scoped_ptr<base::ListValue> args(new base::ListValue()); 187 scoped_ptr<base::ListValue> args(new base::ListValue());
186 scoped_ptr<extensions::Event> event(new extensions::Event( 188 scoped_ptr<extensions::Event> event(new extensions::Event(
187 tts_engine_events::kOnStop, args.Pass())); 189 tts_engine_events::kOnStop, args.Pass()));
188 event->restrict_to_browser_context = utterance->profile(); 190 Profile* profile = Profile::FromBrowserContext(utterance->browser_context());
189 EventRouter::Get(utterance->profile()) 191 event->restrict_to_browser_context = profile;
192 EventRouter::Get(profile)
190 ->DispatchEventToExtension(utterance->extension_id(), event.Pass()); 193 ->DispatchEventToExtension(utterance->extension_id(), event.Pass());
191 } 194 }
192 195
193 void TtsExtensionEngine::Pause(Utterance* utterance) { 196 void TtsExtensionEngine::Pause(Utterance* utterance) {
194 scoped_ptr<base::ListValue> args(new base::ListValue()); 197 scoped_ptr<base::ListValue> args(new base::ListValue());
195 scoped_ptr<extensions::Event> event(new extensions::Event( 198 scoped_ptr<extensions::Event> event(new extensions::Event(
196 tts_engine_events::kOnPause, args.Pass())); 199 tts_engine_events::kOnPause, args.Pass()));
197 Profile* profile = utterance->profile(); 200 Profile* profile = Profile::FromBrowserContext(utterance->browser_context());
198 event->restrict_to_browser_context = profile; 201 event->restrict_to_browser_context = profile;
199 EventRouter* event_router = EventRouter::Get(profile); 202 EventRouter* event_router = EventRouter::Get(profile);
200 std::string id = utterance->extension_id(); 203 std::string id = utterance->extension_id();
201 event_router->DispatchEventToExtension(id, event.Pass()); 204 event_router->DispatchEventToExtension(id, event.Pass());
202 WarnIfMissingPauseOrResumeListener(profile, event_router, id); 205 WarnIfMissingPauseOrResumeListener(profile, event_router, id);
203 } 206 }
204 207
205 void TtsExtensionEngine::Resume(Utterance* utterance) { 208 void TtsExtensionEngine::Resume(Utterance* utterance) {
206 scoped_ptr<base::ListValue> args(new base::ListValue()); 209 scoped_ptr<base::ListValue> args(new base::ListValue());
207 scoped_ptr<extensions::Event> event(new extensions::Event( 210 scoped_ptr<extensions::Event> event(new extensions::Event(
208 tts_engine_events::kOnResume, args.Pass())); 211 tts_engine_events::kOnResume, args.Pass()));
209 Profile* profile = utterance->profile(); 212 Profile* profile = Profile::FromBrowserContext(utterance->browser_context());
210 event->restrict_to_browser_context = profile; 213 event->restrict_to_browser_context = profile;
211 EventRouter* event_router = EventRouter::Get(profile); 214 EventRouter* event_router = EventRouter::Get(profile);
212 std::string id = utterance->extension_id(); 215 std::string id = utterance->extension_id();
213 event_router->DispatchEventToExtension(id, event.Pass()); 216 event_router->DispatchEventToExtension(id, event.Pass());
214 WarnIfMissingPauseOrResumeListener(profile, event_router, id); 217 WarnIfMissingPauseOrResumeListener(profile, event_router, id);
215 } 218 }
216 219
217 bool TtsExtensionEngine::LoadBuiltInTtsExtension(Profile* profile) { 220 bool TtsExtensionEngine::LoadBuiltInTtsExtension(
221 content::BrowserContext* browser_context) {
218 #if defined(OS_CHROMEOS) 222 #if defined(OS_CHROMEOS)
223 Profile* profile = Profile::FromBrowserContext(browser_context);
219 // Check to see if the engine was previously loaded. 224 // Check to see if the engine was previously loaded.
220 if (TtsEngineExtensionObserver::GetInstance(profile)->SawExtensionLoad( 225 if (TtsEngineExtensionObserver::GetInstance(profile)->SawExtensionLoad(
221 extension_misc::kSpeechSynthesisExtensionId, true)) { 226 extension_misc::kSpeechSynthesisExtensionId, true)) {
222 return false; 227 return false;
223 } 228 }
224 229
225 // Load the component extension into this profile. 230 // Load the component extension into this profile.
226 ExtensionService* extension_service = 231 ExtensionService* extension_service =
227 extensions::ExtensionSystem::Get(profile)->extension_service(); 232 extensions::ExtensionSystem::Get(profile)->extension_service();
228 DCHECK(extension_service); 233 DCHECK(extension_service);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 utterance_id, TTS_EVENT_PAUSE, char_index, std::string()); 303 utterance_id, TTS_EVENT_PAUSE, char_index, std::string());
299 } else if (event_type == constants::kEventTypeResume) { 304 } else if (event_type == constants::kEventTypeResume) {
300 controller->OnTtsEvent( 305 controller->OnTtsEvent(
301 utterance_id, TTS_EVENT_RESUME, char_index, std::string()); 306 utterance_id, TTS_EVENT_RESUME, char_index, std::string());
302 } else { 307 } else {
303 EXTENSION_FUNCTION_VALIDATE(false); 308 EXTENSION_FUNCTION_VALIDATE(false);
304 } 309 }
305 310
306 return true; 311 return true;
307 } 312 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698