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

Side by Side Diff: chrome/browser/search/hotword_service.cc

Issue 528113003: Hotword Audio Verification App: Adds to hotwordPrivate API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@page-one
Patch Set: Rebase Created 6 years, 3 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/search/hotword_service.h" 5 #include "chrome/browser/search/hotword_service.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/i18n/case_conversion.h" 8 #include "base/i18n/case_conversion.h"
9 #include "base/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 } 208 }
209 UMA_HISTOGRAM_ENUMERATION("Hotword.Enabled", enabled_state, 209 UMA_HISTOGRAM_ENUMERATION("Hotword.Enabled", enabled_state,
210 NUM_HOTWORD_ENABLED_METRICS); 210 NUM_HOTWORD_ENABLED_METRICS);
211 211
212 pref_registrar_.Init(profile_->GetPrefs()); 212 pref_registrar_.Init(profile_->GetPrefs());
213 pref_registrar_.Add( 213 pref_registrar_.Add(
214 prefs::kHotwordSearchEnabled, 214 prefs::kHotwordSearchEnabled,
215 base::Bind(&HotwordService::OnHotwordSearchEnabledChanged, 215 base::Bind(&HotwordService::OnHotwordSearchEnabledChanged,
216 base::Unretained(this))); 216 base::Unretained(this)));
217 217
218 // TODO(kcarattini): Control the enabling of the pref with the Hotword
219 // Audio Verification app, rather than listening for a change in the
220 // enabled state.
218 pref_registrar_.Add( 221 pref_registrar_.Add(
219 prefs::kHotwordAlwaysOnSearchEnabled, 222 prefs::kHotwordAlwaysOnSearchEnabled,
220 base::Bind(&HotwordService::OnHotwordAlwaysOnSearchEnabledChanged, 223 base::Bind(&HotwordService::OnHotwordAlwaysOnSearchEnabledChanged,
221 base::Unretained(this))); 224 base::Unretained(this)));
222 225
223 registrar_.Add(this, 226 registrar_.Add(this,
224 chrome::NOTIFICATION_BROWSER_WINDOW_READY, 227 chrome::NOTIFICATION_BROWSER_WINDOW_READY,
225 content::NotificationService::AllSources()); 228 content::NotificationService::AllSources());
226 229
227 extensions::ExtensionSystem::Get(profile_)->ready().Post( 230 extensions::ExtensionSystem::Get(profile_)->ready().Post(
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 if (extension_service) { 449 if (extension_service) {
447 extension_service->DisableExtension( 450 extension_service->DisableExtension(
448 extension_misc::kHotwordExtensionId, 451 extension_misc::kHotwordExtensionId,
449 extensions::Extension::DISABLE_USER_ACTION); 452 extensions::Extension::DISABLE_USER_ACTION);
450 } 453 }
451 } 454 }
452 455
453 void HotwordService::OnHotwordAlwaysOnSearchEnabledChanged( 456 void HotwordService::OnHotwordAlwaysOnSearchEnabledChanged(
454 const std::string& pref_name) { 457 const std::string& pref_name) {
455 DCHECK_EQ(pref_name, std::string(prefs::kHotwordAlwaysOnSearchEnabled)); 458 DCHECK_EQ(pref_name, std::string(prefs::kHotwordAlwaysOnSearchEnabled));
459 // TODO(kcarattini): Launch in the appropriate mode given the state of
460 // the account-level Audio History setting.
461 LaunchHotwordAudioVerificationApp(HOTWORD_AND_AUDIO_HISTORY);
462 }
463
464 void HotwordService::LaunchHotwordAudioVerificationApp(
465 const LaunchMode& launch_mode) {
466 hotword_audio_verification_launch_mode_ = launch_mode;
456 467
457 ExtensionService* extension_service = GetExtensionService(profile_); 468 ExtensionService* extension_service = GetExtensionService(profile_);
458 if (!extension_service) 469 if (!extension_service)
459 return; 470 return;
460
461 const extensions::Extension* extension = extension_service->GetExtensionById( 471 const extensions::Extension* extension = extension_service->GetExtensionById(
462 extension_misc::kHotwordAudioVerificationAppId, true); 472 extension_misc::kHotwordAudioVerificationAppId, true);
463 if (!extension) 473 if (!extension)
464 return; 474 return;
465 475
466 if (profile_->GetPrefs()->GetBoolean(prefs::kHotwordAlwaysOnSearchEnabled)) { 476 OpenApplication(AppLaunchParams(
467 OpenApplication(AppLaunchParams( 477 profile_, extension, extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW));
468 profile_, extension, extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW)); 478 }
469 } 479
480 HotwordService::LaunchMode
481 HotwordService::GetHotwordAudioVerificationLaunchMode() {
482 return hotword_audio_verification_launch_mode_;
470 } 483 }
471 484
472 void HotwordService::OnHotwordSearchEnabledChanged( 485 void HotwordService::OnHotwordSearchEnabledChanged(
473 const std::string& pref_name) { 486 const std::string& pref_name) {
474 DCHECK_EQ(pref_name, std::string(prefs::kHotwordSearchEnabled)); 487 DCHECK_EQ(pref_name, std::string(prefs::kHotwordSearchEnabled));
475 488
476 ExtensionService* extension_service = GetExtensionService(profile_); 489 ExtensionService* extension_service = GetExtensionService(profile_);
477 if (profile_->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled)) 490 if (profile_->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled))
478 EnableHotwordExtension(extension_service); 491 EnableHotwordExtension(extension_service);
479 else 492 else
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 return false; 530 return false;
518 531
519 std::string previous_locale = 532 std::string previous_locale =
520 profile_->GetPrefs()->GetString(prefs::kHotwordPreviousLanguage); 533 profile_->GetPrefs()->GetString(prefs::kHotwordPreviousLanguage);
521 std::string locale = GetCurrentLocale(profile_); 534 std::string locale = GetCurrentLocale(profile_);
522 535
523 // If it's a new locale, then the old extension should be uninstalled. 536 // If it's a new locale, then the old extension should be uninstalled.
524 return locale != previous_locale && 537 return locale != previous_locale &&
525 HotwordService::DoesHotwordSupportLanguage(profile_); 538 HotwordService::DoesHotwordSupportLanguage(profile_);
526 } 539 }
OLDNEW
« no previous file with comments | « chrome/browser/search/hotword_service.h ('k') | chrome/common/extensions/api/_permission_features.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698