OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/extensions/api/hotword_private/hotword_private_api.h" | 5 #include "chrome/browser/extensions/api/hotword_private/hotword_private_api.h" |
6 | 6 |
| 7 #include <memory> |
7 #include <string> | 8 #include <string> |
8 #include <utility> | 9 #include <utility> |
9 | 10 |
10 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
11 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
12 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
13 #include "build/build_config.h" | 14 #include "build/build_config.h" |
14 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
15 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/search/hotword_audio_history_handler.h" | 17 #include "chrome/browser/search/hotword_audio_history_handler.h" |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 result.training_enabled = hotword_service->IsTraining(); | 214 result.training_enabled = hotword_service->IsTraining(); |
214 result.always_on_enabled = hotword_service->IsAlwaysOnEnabled(); | 215 result.always_on_enabled = hotword_service->IsAlwaysOnEnabled(); |
215 result.user_is_active = hotword_service->UserIsActive(); | 216 result.user_is_active = hotword_service->UserIsActive(); |
216 result.hotword_hardware_available = | 217 result.hotword_hardware_available = |
217 HotwordService::IsHotwordHardwareAvailable(); | 218 HotwordService::IsHotwordHardwareAvailable(); |
218 } | 219 } |
219 | 220 |
220 PrefService* prefs = GetProfile()->GetPrefs(); | 221 PrefService* prefs = GetProfile()->GetPrefs(); |
221 result.enabled_set = prefs->HasPrefPath(prefs::kHotwordSearchEnabled); | 222 result.enabled_set = prefs->HasPrefPath(prefs::kHotwordSearchEnabled); |
222 | 223 |
223 SetResult(result.ToValue().release()); | 224 SetResult(result.ToValue()); |
224 return true; | 225 return true; |
225 } | 226 } |
226 | 227 |
227 bool HotwordPrivateSetHotwordSessionStateFunction::RunSync() { | 228 bool HotwordPrivateSetHotwordSessionStateFunction::RunSync() { |
228 std::unique_ptr<api::hotword_private::SetHotwordSessionState::Params> params( | 229 std::unique_ptr<api::hotword_private::SetHotwordSessionState::Params> params( |
229 api::hotword_private::SetHotwordSessionState::Params::Create(*args_)); | 230 api::hotword_private::SetHotwordSessionState::Params::Create(*args_)); |
230 EXTENSION_FUNCTION_VALIDATE(params.get()); | 231 EXTENSION_FUNCTION_VALIDATE(params.get()); |
231 | 232 |
232 HotwordService* hotword_service = | 233 HotwordService* hotword_service = |
233 HotwordServiceFactory::GetForProfile(GetProfile()); | 234 HotwordServiceFactory::GetForProfile(GetProfile()); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 HotwordService* hotword_service = | 276 HotwordService* hotword_service = |
276 HotwordServiceFactory::GetForProfile(GetProfile()); | 277 HotwordServiceFactory::GetForProfile(GetProfile()); |
277 if (!hotword_service) { | 278 if (!hotword_service) { |
278 error_ = hotword_private_constants::kHotwordServiceUnavailable; | 279 error_ = hotword_private_constants::kHotwordServiceUnavailable; |
279 return false; | 280 return false; |
280 } | 281 } |
281 | 282 |
282 api::hotword_private::LaunchState result; | 283 api::hotword_private::LaunchState result; |
283 result.launch_mode = | 284 result.launch_mode = |
284 hotword_service->GetHotwordAudioVerificationLaunchMode(); | 285 hotword_service->GetHotwordAudioVerificationLaunchMode(); |
285 SetResult(result.ToValue().release()); | 286 SetResult(result.ToValue()); |
286 return true; | 287 return true; |
287 } | 288 } |
288 | 289 |
289 bool HotwordPrivateStartTrainingFunction::RunSync() { | 290 bool HotwordPrivateStartTrainingFunction::RunSync() { |
290 HotwordService* hotword_service = | 291 HotwordService* hotword_service = |
291 HotwordServiceFactory::GetForProfile(GetProfile()); | 292 HotwordServiceFactory::GetForProfile(GetProfile()); |
292 if (!hotword_service) { | 293 if (!hotword_service) { |
293 error_ = hotword_private_constants::kHotwordServiceUnavailable; | 294 error_ = hotword_private_constants::kHotwordServiceUnavailable; |
294 return false; | 295 return false; |
295 } | 296 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 bool HotwordPrivateGetLocalizedStringsFunction::RunSync() { | 339 bool HotwordPrivateGetLocalizedStringsFunction::RunSync() { |
339 #if defined(OS_CHROMEOS) | 340 #if defined(OS_CHROMEOS) |
340 base::string16 device_type = ash::GetChromeOSDeviceName(); | 341 base::string16 device_type = ash::GetChromeOSDeviceName(); |
341 #else | 342 #else |
342 base::string16 product_name = | 343 base::string16 product_name = |
343 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME); | 344 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME); |
344 base::string16 device_type = | 345 base::string16 device_type = |
345 l10n_util::GetStringFUTF16(IDS_HOTWORD_BROWSER_NAME, product_name); | 346 l10n_util::GetStringFUTF16(IDS_HOTWORD_BROWSER_NAME, product_name); |
346 #endif | 347 #endif |
347 | 348 |
348 base::DictionaryValue* localized_strings = new base::DictionaryValue(); | 349 std::unique_ptr<base::DictionaryValue> localized_strings( |
| 350 new base::DictionaryValue()); |
349 | 351 |
350 localized_strings->SetString( | 352 localized_strings->SetString( |
351 "close", | 353 "close", |
352 l10n_util::GetStringUTF16(IDS_HOTWORD_OPT_IN_CLOSE)); | 354 l10n_util::GetStringUTF16(IDS_HOTWORD_OPT_IN_CLOSE)); |
353 localized_strings->SetString( | 355 localized_strings->SetString( |
354 "cancel", | 356 "cancel", |
355 l10n_util::GetStringUTF16(IDS_HOTWORD_OPT_IN_CANCEL)); | 357 l10n_util::GetStringUTF16(IDS_HOTWORD_OPT_IN_CANCEL)); |
356 localized_strings->SetString( | 358 localized_strings->SetString( |
357 "introTitle", | 359 "introTitle", |
358 l10n_util::GetStringUTF16(IDS_HOTWORD_OPT_IN_INTRO_TITLE)); | 360 l10n_util::GetStringUTF16(IDS_HOTWORD_OPT_IN_INTRO_TITLE)); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 l10n_util::GetStringUTF16( | 446 l10n_util::GetStringUTF16( |
445 IDS_HOTWORD_OPT_IN_FINISHED_AUDIO_HISTORY)); | 447 IDS_HOTWORD_OPT_IN_FINISHED_AUDIO_HISTORY)); |
446 localized_strings->SetString( | 448 localized_strings->SetString( |
447 "finish", | 449 "finish", |
448 l10n_util::GetStringUTF16(IDS_HOTWORD_OPT_IN_FINISH)); | 450 l10n_util::GetStringUTF16(IDS_HOTWORD_OPT_IN_FINISH)); |
449 localized_strings->SetString( | 451 localized_strings->SetString( |
450 "finishedWait", | 452 "finishedWait", |
451 l10n_util::GetStringUTF16(IDS_HOTWORD_OPT_IN_FINISHED_WAIT)); | 453 l10n_util::GetStringUTF16(IDS_HOTWORD_OPT_IN_FINISHED_WAIT)); |
452 | 454 |
453 const std::string& app_locale = g_browser_process->GetApplicationLocale(); | 455 const std::string& app_locale = g_browser_process->GetApplicationLocale(); |
454 webui::SetLoadTimeDataDefaults(app_locale, localized_strings); | 456 webui::SetLoadTimeDataDefaults(app_locale, localized_strings.get()); |
455 | 457 |
456 SetResult(localized_strings); | 458 SetResult(std::move(localized_strings)); |
457 return true; | 459 return true; |
458 } | 460 } |
459 | 461 |
460 bool HotwordPrivateSetAudioHistoryEnabledFunction::RunAsync() { | 462 bool HotwordPrivateSetAudioHistoryEnabledFunction::RunAsync() { |
461 std::unique_ptr<api::hotword_private::SetAudioHistoryEnabled::Params> params( | 463 std::unique_ptr<api::hotword_private::SetAudioHistoryEnabled::Params> params( |
462 api::hotword_private::SetAudioHistoryEnabled::Params::Create(*args_)); | 464 api::hotword_private::SetAudioHistoryEnabled::Params::Create(*args_)); |
463 EXTENSION_FUNCTION_VALIDATE(params.get()); | 465 EXTENSION_FUNCTION_VALIDATE(params.get()); |
464 | 466 |
465 HotwordService* hotword_service = | 467 HotwordService* hotword_service = |
466 HotwordServiceFactory::GetForProfile(GetProfile()); | 468 HotwordServiceFactory::GetForProfile(GetProfile()); |
467 if (!hotword_service || !hotword_service->GetAudioHistoryHandler()) { | 469 if (!hotword_service || !hotword_service->GetAudioHistoryHandler()) { |
468 error_ = hotword_private_constants::kHotwordServiceUnavailable; | 470 error_ = hotword_private_constants::kHotwordServiceUnavailable; |
469 return false; | 471 return false; |
470 } | 472 } |
471 | 473 |
472 hotword_service->GetAudioHistoryHandler()->SetAudioHistoryEnabled( | 474 hotword_service->GetAudioHistoryHandler()->SetAudioHistoryEnabled( |
473 params->enabled, | 475 params->enabled, |
474 base::Bind( | 476 base::Bind( |
475 &HotwordPrivateSetAudioHistoryEnabledFunction::SetResultAndSendResponse, | 477 &HotwordPrivateSetAudioHistoryEnabledFunction::SetResultAndSendResponse, |
476 this)); | 478 this)); |
477 return true; | 479 return true; |
478 } | 480 } |
479 | 481 |
480 void HotwordPrivateSetAudioHistoryEnabledFunction::SetResultAndSendResponse( | 482 void HotwordPrivateSetAudioHistoryEnabledFunction::SetResultAndSendResponse( |
481 bool success, bool new_enabled_value) { | 483 bool success, bool new_enabled_value) { |
482 api::hotword_private::AudioHistoryState result; | 484 api::hotword_private::AudioHistoryState result; |
483 result.success = success; | 485 result.success = success; |
484 result.enabled = new_enabled_value; | 486 result.enabled = new_enabled_value; |
485 SetResult(result.ToValue().release()); | 487 SetResult(result.ToValue()); |
486 SendResponse(true); | 488 SendResponse(true); |
487 } | 489 } |
488 | 490 |
489 bool HotwordPrivateGetAudioHistoryEnabledFunction::RunAsync() { | 491 bool HotwordPrivateGetAudioHistoryEnabledFunction::RunAsync() { |
490 HotwordService* hotword_service = | 492 HotwordService* hotword_service = |
491 HotwordServiceFactory::GetForProfile(GetProfile()); | 493 HotwordServiceFactory::GetForProfile(GetProfile()); |
492 if (!hotword_service || !hotword_service->GetAudioHistoryHandler()) { | 494 if (!hotword_service || !hotword_service->GetAudioHistoryHandler()) { |
493 error_ = hotword_private_constants::kHotwordServiceUnavailable; | 495 error_ = hotword_private_constants::kHotwordServiceUnavailable; |
494 return false; | 496 return false; |
495 } | 497 } |
496 | 498 |
497 hotword_service->GetAudioHistoryHandler()->GetAudioHistoryEnabled(base::Bind( | 499 hotword_service->GetAudioHistoryHandler()->GetAudioHistoryEnabled(base::Bind( |
498 &HotwordPrivateGetAudioHistoryEnabledFunction::SetResultAndSendResponse, | 500 &HotwordPrivateGetAudioHistoryEnabledFunction::SetResultAndSendResponse, |
499 this)); | 501 this)); |
500 | 502 |
501 return true; | 503 return true; |
502 } | 504 } |
503 | 505 |
504 void HotwordPrivateGetAudioHistoryEnabledFunction::SetResultAndSendResponse( | 506 void HotwordPrivateGetAudioHistoryEnabledFunction::SetResultAndSendResponse( |
505 bool success, bool new_enabled_value) { | 507 bool success, bool new_enabled_value) { |
506 api::hotword_private::AudioHistoryState result; | 508 api::hotword_private::AudioHistoryState result; |
507 result.success = success; | 509 result.success = success; |
508 result.enabled = new_enabled_value; | 510 result.enabled = new_enabled_value; |
509 SetResult(result.ToValue().release()); | 511 SetResult(result.ToValue()); |
510 SendResponse(true); | 512 SendResponse(true); |
511 } | 513 } |
512 | 514 |
513 bool HotwordPrivateSpeakerModelExistsResultFunction::RunSync() { | 515 bool HotwordPrivateSpeakerModelExistsResultFunction::RunSync() { |
514 std::unique_ptr<api::hotword_private::SpeakerModelExistsResult::Params> | 516 std::unique_ptr<api::hotword_private::SpeakerModelExistsResult::Params> |
515 params(api::hotword_private::SpeakerModelExistsResult::Params::Create( | 517 params(api::hotword_private::SpeakerModelExistsResult::Params::Create( |
516 *args_)); | 518 *args_)); |
517 EXTENSION_FUNCTION_VALIDATE(params.get()); | 519 EXTENSION_FUNCTION_VALIDATE(params.get()); |
518 | 520 |
519 HotwordService* hotword_service = | 521 HotwordService* hotword_service = |
520 HotwordServiceFactory::GetForProfile(GetProfile()); | 522 HotwordServiceFactory::GetForProfile(GetProfile()); |
521 if (!hotword_service) | 523 if (!hotword_service) |
522 return false; | 524 return false; |
523 | 525 |
524 hotword_service->SpeakerModelExistsComplete(params->exists); | 526 hotword_service->SpeakerModelExistsComplete(params->exists); |
525 return true; | 527 return true; |
526 } | 528 } |
527 | 529 |
528 } // namespace extensions | 530 } // namespace extensions |
OLD | NEW |