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 |
| 9 #include <memory> |
8 #include <string> | 10 #include <string> |
9 #include <utility> | 11 #include <utility> |
10 | 12 |
11 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
12 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
13 #include "base/values.h" | 15 #include "base/values.h" |
14 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/speech/extension_api/tts_engine_extension_api.h" | 17 #include "chrome/browser/speech/extension_api/tts_engine_extension_api.h" |
16 #include "chrome/browser/speech/extension_api/tts_engine_extension_observer.h" | 18 #include "chrome/browser/speech/extension_api/tts_engine_extension_observer.h" |
17 #include "chrome/browser/speech/extension_api/tts_extension_api_constants.h" | 19 #include "chrome/browser/speech/extension_api/tts_extension_api_constants.h" |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 return true; | 316 return true; |
315 } | 317 } |
316 | 318 |
317 bool TtsGetVoicesFunction::RunSync() { | 319 bool TtsGetVoicesFunction::RunSync() { |
318 std::vector<VoiceData> voices; | 320 std::vector<VoiceData> voices; |
319 TtsController::GetInstance()->GetVoices(GetProfile(), &voices); | 321 TtsController::GetInstance()->GetVoices(GetProfile(), &voices); |
320 | 322 |
321 std::unique_ptr<base::ListValue> result_voices(new base::ListValue()); | 323 std::unique_ptr<base::ListValue> result_voices(new base::ListValue()); |
322 for (size_t i = 0; i < voices.size(); ++i) { | 324 for (size_t i = 0; i < voices.size(); ++i) { |
323 const VoiceData& voice = voices[i]; | 325 const VoiceData& voice = voices[i]; |
324 base::DictionaryValue* result_voice = new base::DictionaryValue(); | 326 std::unique_ptr<base::DictionaryValue> result_voice( |
| 327 new base::DictionaryValue()); |
325 result_voice->SetString(constants::kVoiceNameKey, voice.name); | 328 result_voice->SetString(constants::kVoiceNameKey, voice.name); |
326 result_voice->SetBoolean(constants::kRemoteKey, voice.remote); | 329 result_voice->SetBoolean(constants::kRemoteKey, voice.remote); |
327 if (!voice.lang.empty()) | 330 if (!voice.lang.empty()) |
328 result_voice->SetString(constants::kLangKey, voice.lang); | 331 result_voice->SetString(constants::kLangKey, voice.lang); |
329 if (voice.gender == TTS_GENDER_MALE) | 332 if (voice.gender == TTS_GENDER_MALE) |
330 result_voice->SetString(constants::kGenderKey, constants::kGenderMale); | 333 result_voice->SetString(constants::kGenderKey, constants::kGenderMale); |
331 else if (voice.gender == TTS_GENDER_FEMALE) | 334 else if (voice.gender == TTS_GENDER_FEMALE) |
332 result_voice->SetString(constants::kGenderKey, constants::kGenderFemale); | 335 result_voice->SetString(constants::kGenderKey, constants::kGenderFemale); |
333 if (!voice.extension_id.empty()) | 336 if (!voice.extension_id.empty()) |
334 result_voice->SetString(constants::kExtensionIdKey, voice.extension_id); | 337 result_voice->SetString(constants::kExtensionIdKey, voice.extension_id); |
335 | 338 |
336 base::ListValue* event_types = new base::ListValue(); | 339 base::ListValue* event_types = new base::ListValue(); |
337 for (std::set<TtsEventType>::iterator iter = voice.events.begin(); | 340 for (std::set<TtsEventType>::iterator iter = voice.events.begin(); |
338 iter != voice.events.end(); ++iter) { | 341 iter != voice.events.end(); ++iter) { |
339 const char* event_name_constant = TtsEventTypeToString(*iter); | 342 const char* event_name_constant = TtsEventTypeToString(*iter); |
340 event_types->AppendString(event_name_constant); | 343 event_types->AppendString(event_name_constant); |
341 } | 344 } |
342 result_voice->Set(constants::kEventTypesKey, event_types); | 345 result_voice->Set(constants::kEventTypesKey, event_types); |
343 | 346 |
344 result_voices->Append(result_voice); | 347 result_voices->Append(std::move(result_voice)); |
345 } | 348 } |
346 | 349 |
347 SetResult(std::move(result_voices)); | 350 SetResult(std::move(result_voices)); |
348 return true; | 351 return true; |
349 } | 352 } |
350 | 353 |
351 TtsAPI::TtsAPI(content::BrowserContext* context) { | 354 TtsAPI::TtsAPI(content::BrowserContext* context) { |
352 ExtensionFunctionRegistry* registry = | 355 ExtensionFunctionRegistry* registry = |
353 ExtensionFunctionRegistry::GetInstance(); | 356 ExtensionFunctionRegistry::GetInstance(); |
354 registry->RegisterFunction<ExtensionTtsEngineSendTtsEventFunction>(); | 357 registry->RegisterFunction<ExtensionTtsEngineSendTtsEventFunction>(); |
(...skipping 12 matching lines...) Expand all Loading... |
367 } | 370 } |
368 | 371 |
369 static base::LazyInstance<BrowserContextKeyedAPIFactory<TtsAPI> > g_factory = | 372 static base::LazyInstance<BrowserContextKeyedAPIFactory<TtsAPI> > g_factory = |
370 LAZY_INSTANCE_INITIALIZER; | 373 LAZY_INSTANCE_INITIALIZER; |
371 | 374 |
372 BrowserContextKeyedAPIFactory<TtsAPI>* TtsAPI::GetFactoryInstance() { | 375 BrowserContextKeyedAPIFactory<TtsAPI>* TtsAPI::GetFactoryInstance() { |
373 return g_factory.Pointer(); | 376 return g_factory.Pointer(); |
374 } | 377 } |
375 | 378 |
376 } // namespace extensions | 379 } // namespace extensions |
OLD | NEW |