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

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

Issue 2888073002: Remove raw DictionaryValue::Set in //chrome (Closed)
Patch Set: Fix Tests Created 3 years, 7 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_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 8
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 312
313 ExtensionFunction::ResponseAction TtsIsSpeakingFunction::Run() { 313 ExtensionFunction::ResponseAction TtsIsSpeakingFunction::Run() {
314 return RespondNow(OneArgument(base::MakeUnique<base::Value>( 314 return RespondNow(OneArgument(base::MakeUnique<base::Value>(
315 TtsController::GetInstance()->IsSpeaking()))); 315 TtsController::GetInstance()->IsSpeaking())));
316 } 316 }
317 317
318 ExtensionFunction::ResponseAction TtsGetVoicesFunction::Run() { 318 ExtensionFunction::ResponseAction TtsGetVoicesFunction::Run() {
319 std::vector<VoiceData> voices; 319 std::vector<VoiceData> voices;
320 TtsController::GetInstance()->GetVoices(browser_context(), &voices); 320 TtsController::GetInstance()->GetVoices(browser_context(), &voices);
321 321
322 std::unique_ptr<base::ListValue> result_voices(new base::ListValue()); 322 auto result_voices = base::MakeUnique<base::ListValue>();
323 for (size_t i = 0; i < voices.size(); ++i) { 323 for (size_t i = 0; i < voices.size(); ++i) {
324 const VoiceData& voice = voices[i]; 324 const VoiceData& voice = voices[i];
325 std::unique_ptr<base::DictionaryValue> result_voice( 325 std::unique_ptr<base::DictionaryValue> result_voice(
326 new base::DictionaryValue()); 326 new base::DictionaryValue());
327 result_voice->SetString(constants::kVoiceNameKey, voice.name); 327 result_voice->SetString(constants::kVoiceNameKey, voice.name);
328 result_voice->SetBoolean(constants::kRemoteKey, voice.remote); 328 result_voice->SetBoolean(constants::kRemoteKey, voice.remote);
329 if (!voice.lang.empty()) 329 if (!voice.lang.empty())
330 result_voice->SetString(constants::kLangKey, voice.lang); 330 result_voice->SetString(constants::kLangKey, voice.lang);
331 if (voice.gender == TTS_GENDER_MALE) 331 if (voice.gender == TTS_GENDER_MALE)
332 result_voice->SetString(constants::kGenderKey, constants::kGenderMale); 332 result_voice->SetString(constants::kGenderKey, constants::kGenderMale);
333 else if (voice.gender == TTS_GENDER_FEMALE) 333 else if (voice.gender == TTS_GENDER_FEMALE)
334 result_voice->SetString(constants::kGenderKey, constants::kGenderFemale); 334 result_voice->SetString(constants::kGenderKey, constants::kGenderFemale);
335 if (!voice.extension_id.empty()) 335 if (!voice.extension_id.empty())
336 result_voice->SetString(constants::kExtensionIdKey, voice.extension_id); 336 result_voice->SetString(constants::kExtensionIdKey, voice.extension_id);
337 337
338 base::ListValue* event_types = new base::ListValue(); 338 auto event_types = base::MakeUnique<base::ListValue>();
339 for (std::set<TtsEventType>::iterator iter = voice.events.begin(); 339 for (std::set<TtsEventType>::iterator iter = voice.events.begin();
340 iter != voice.events.end(); ++iter) { 340 iter != voice.events.end(); ++iter) {
341 const char* event_name_constant = TtsEventTypeToString(*iter); 341 const char* event_name_constant = TtsEventTypeToString(*iter);
342 event_types->AppendString(event_name_constant); 342 event_types->AppendString(event_name_constant);
343 } 343 }
344 result_voice->Set(constants::kEventTypesKey, event_types); 344 result_voice->Set(constants::kEventTypesKey, std::move(event_types));
345 345
346 result_voices->Append(std::move(result_voice)); 346 result_voices->Append(std::move(result_voice));
347 } 347 }
348 348
349 return RespondNow(OneArgument(std::move(result_voices))); 349 return RespondNow(OneArgument(std::move(result_voices)));
350 } 350 }
351 351
352 TtsAPI::TtsAPI(content::BrowserContext* context) { 352 TtsAPI::TtsAPI(content::BrowserContext* context) {
353 ExtensionFunctionRegistry* registry = 353 ExtensionFunctionRegistry* registry =
354 ExtensionFunctionRegistry::GetInstance(); 354 ExtensionFunctionRegistry::GetInstance();
(...skipping 14 matching lines...) Expand all
369 369
370 static base::LazyInstance< 370 static base::LazyInstance<
371 BrowserContextKeyedAPIFactory<TtsAPI>>::DestructorAtExit g_factory = 371 BrowserContextKeyedAPIFactory<TtsAPI>>::DestructorAtExit g_factory =
372 LAZY_INSTANCE_INITIALIZER; 372 LAZY_INSTANCE_INITIALIZER;
373 373
374 BrowserContextKeyedAPIFactory<TtsAPI>* TtsAPI::GetFactoryInstance() { 374 BrowserContextKeyedAPIFactory<TtsAPI>* TtsAPI::GetFactoryInstance() {
375 return g_factory.Pointer(); 375 return g_factory.Pointer();
376 } 376 }
377 377
378 } // namespace extensions 378 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698