| OLD | NEW |
| 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_extension_api.h" | 5 #include "chrome/browser/speech/extension_api/tts_extension_api.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
| 12 #include "base/memory/ptr_util.h" |
| 12 #include "base/values.h" | 13 #include "base/values.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/speech/extension_api/tts_engine_extension_api.h" | 15 #include "chrome/browser/speech/extension_api/tts_engine_extension_api.h" |
| 15 #include "chrome/browser/speech/extension_api/tts_engine_extension_observer.h" | 16 #include "chrome/browser/speech/extension_api/tts_engine_extension_observer.h" |
| 16 #include "chrome/browser/speech/extension_api/tts_extension_api_constants.h" | 17 #include "chrome/browser/speech/extension_api/tts_extension_api_constants.h" |
| 17 #include "chrome/browser/speech/tts_controller.h" | 18 #include "chrome/browser/speech/tts_controller.h" |
| 18 #include "extensions/browser/event_router.h" | 19 #include "extensions/browser/event_router.h" |
| 19 #include "extensions/browser/extension_function_registry.h" | 20 #include "extensions/browser/extension_function_registry.h" |
| 20 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
| 21 | 22 |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 TtsController::GetInstance()->Pause(); | 302 TtsController::GetInstance()->Pause(); |
| 302 return true; | 303 return true; |
| 303 } | 304 } |
| 304 | 305 |
| 305 bool TtsResumeFunction::RunSync() { | 306 bool TtsResumeFunction::RunSync() { |
| 306 TtsController::GetInstance()->Resume(); | 307 TtsController::GetInstance()->Resume(); |
| 307 return true; | 308 return true; |
| 308 } | 309 } |
| 309 | 310 |
| 310 bool TtsIsSpeakingFunction::RunSync() { | 311 bool TtsIsSpeakingFunction::RunSync() { |
| 311 SetResult( | 312 SetResult(base::MakeUnique<base::FundamentalValue>( |
| 312 new base::FundamentalValue(TtsController::GetInstance()->IsSpeaking())); | 313 TtsController::GetInstance()->IsSpeaking())); |
| 313 return true; | 314 return true; |
| 314 } | 315 } |
| 315 | 316 |
| 316 bool TtsGetVoicesFunction::RunSync() { | 317 bool TtsGetVoicesFunction::RunSync() { |
| 317 std::vector<VoiceData> voices; | 318 std::vector<VoiceData> voices; |
| 318 TtsController::GetInstance()->GetVoices(GetProfile(), &voices); | 319 TtsController::GetInstance()->GetVoices(GetProfile(), &voices); |
| 319 | 320 |
| 320 std::unique_ptr<base::ListValue> result_voices(new base::ListValue()); | 321 std::unique_ptr<base::ListValue> result_voices(new base::ListValue()); |
| 321 for (size_t i = 0; i < voices.size(); ++i) { | 322 for (size_t i = 0; i < voices.size(); ++i) { |
| 322 const VoiceData& voice = voices[i]; | 323 const VoiceData& voice = voices[i]; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 336 for (std::set<TtsEventType>::iterator iter = voice.events.begin(); | 337 for (std::set<TtsEventType>::iterator iter = voice.events.begin(); |
| 337 iter != voice.events.end(); ++iter) { | 338 iter != voice.events.end(); ++iter) { |
| 338 const char* event_name_constant = TtsEventTypeToString(*iter); | 339 const char* event_name_constant = TtsEventTypeToString(*iter); |
| 339 event_types->Append(new base::StringValue(event_name_constant)); | 340 event_types->Append(new base::StringValue(event_name_constant)); |
| 340 } | 341 } |
| 341 result_voice->Set(constants::kEventTypesKey, event_types); | 342 result_voice->Set(constants::kEventTypesKey, event_types); |
| 342 | 343 |
| 343 result_voices->Append(result_voice); | 344 result_voices->Append(result_voice); |
| 344 } | 345 } |
| 345 | 346 |
| 346 SetResult(result_voices.release()); | 347 SetResult(std::move(result_voices)); |
| 347 return true; | 348 return true; |
| 348 } | 349 } |
| 349 | 350 |
| 350 TtsAPI::TtsAPI(content::BrowserContext* context) { | 351 TtsAPI::TtsAPI(content::BrowserContext* context) { |
| 351 ExtensionFunctionRegistry* registry = | 352 ExtensionFunctionRegistry* registry = |
| 352 ExtensionFunctionRegistry::GetInstance(); | 353 ExtensionFunctionRegistry::GetInstance(); |
| 353 registry->RegisterFunction<ExtensionTtsEngineSendTtsEventFunction>(); | 354 registry->RegisterFunction<ExtensionTtsEngineSendTtsEventFunction>(); |
| 354 registry->RegisterFunction<TtsGetVoicesFunction>(); | 355 registry->RegisterFunction<TtsGetVoicesFunction>(); |
| 355 registry->RegisterFunction<TtsIsSpeakingFunction>(); | 356 registry->RegisterFunction<TtsIsSpeakingFunction>(); |
| 356 registry->RegisterFunction<TtsSpeakFunction>(); | 357 registry->RegisterFunction<TtsSpeakFunction>(); |
| 357 registry->RegisterFunction<TtsStopSpeakingFunction>(); | 358 registry->RegisterFunction<TtsStopSpeakingFunction>(); |
| 358 registry->RegisterFunction<TtsPauseFunction>(); | 359 registry->RegisterFunction<TtsPauseFunction>(); |
| 359 registry->RegisterFunction<TtsResumeFunction>(); | 360 registry->RegisterFunction<TtsResumeFunction>(); |
| 360 | 361 |
| 361 // Ensure we're observing newly added engines for the given context. | 362 // Ensure we're observing newly added engines for the given context. |
| 362 TtsEngineExtensionObserver::GetInstance(Profile::FromBrowserContext(context)); | 363 TtsEngineExtensionObserver::GetInstance(Profile::FromBrowserContext(context)); |
| 363 } | 364 } |
| 364 | 365 |
| 365 TtsAPI::~TtsAPI() { | 366 TtsAPI::~TtsAPI() { |
| 366 } | 367 } |
| 367 | 368 |
| 368 static base::LazyInstance<BrowserContextKeyedAPIFactory<TtsAPI> > g_factory = | 369 static base::LazyInstance<BrowserContextKeyedAPIFactory<TtsAPI> > g_factory = |
| 369 LAZY_INSTANCE_INITIALIZER; | 370 LAZY_INSTANCE_INITIALIZER; |
| 370 | 371 |
| 371 BrowserContextKeyedAPIFactory<TtsAPI>* TtsAPI::GetFactoryInstance() { | 372 BrowserContextKeyedAPIFactory<TtsAPI>* TtsAPI::GetFactoryInstance() { |
| 372 return g_factory.Pointer(); | 373 return g_factory.Pointer(); |
| 373 } | 374 } |
| 374 | 375 |
| 375 } // namespace extensions | 376 } // namespace extensions |
| OLD | NEW |