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

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

Issue 992173002: Delete the old hotwording integration. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@hotword-remove-disable-option
Patch Set: Rebase Created 5 years, 9 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 <string> 7 #include <string>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/i18n/case_conversion.h" 10 #include "base/i18n/case_conversion.h"
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 }; 129 };
130 130
131 void RecordExtensionAvailabilityMetrics( 131 void RecordExtensionAvailabilityMetrics(
132 ExtensionService* service, 132 ExtensionService* service,
133 const extensions::Extension* extension) { 133 const extensions::Extension* extension) {
134 HotwordExtensionAvailability availability_state = UNAVAILABLE; 134 HotwordExtensionAvailability availability_state = UNAVAILABLE;
135 if (extension) { 135 if (extension) {
136 availability_state = AVAILABLE; 136 availability_state = AVAILABLE;
137 } else if (service->pending_extension_manager() && 137 } else if (service->pending_extension_manager() &&
138 service->pending_extension_manager()->IsIdPending( 138 service->pending_extension_manager()->IsIdPending(
139 extension_misc::kHotwordExtensionId)) { 139 extension_misc::kHotwordSharedModuleId)) {
kcarattini 2015/03/17 00:41:13 If you are changing the meaning of the stat, I thi
Anand Mistry (off Chromium) 2015/03/17 03:00:46 Hmm. I don't think we should be changing the meani
140 availability_state = PENDING_DOWNLOAD; 140 availability_state = PENDING_DOWNLOAD;
141 } else if (!service->IsExtensionEnabled(
142 extension_misc::kHotwordExtensionId)) {
143 availability_state = DISABLED_EXTENSION;
144 } 141 }
145 UMA_HISTOGRAM_ENUMERATION("Hotword.HotwordExtensionAvailability", 142 UMA_HISTOGRAM_ENUMERATION("Hotword.HotwordExtensionAvailability",
146 availability_state, 143 availability_state,
147 NUM_HOTWORD_EXTENSION_AVAILABILITY_METRICS); 144 NUM_HOTWORD_EXTENSION_AVAILABILITY_METRICS);
148 } 145 }
149 146
150 void RecordLoggingMetrics(Profile* profile) { 147 void RecordLoggingMetrics(Profile* profile) {
151 // If the user is not opted in to hotword voice search, the audio logging 148 // If the user is not opted in to hotword voice search, the audio logging
152 // metric is not valid so it is not recorded. 149 // metric is not valid so it is not recorded.
153 if (!profile->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled)) 150 if (!profile->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled))
(...skipping 24 matching lines...) Expand all
178 error, 175 error,
179 NUM_HOTWORD_ERROR_METRICS); 176 NUM_HOTWORD_ERROR_METRICS);
180 } 177 }
181 178
182 void RecordHotwordEnabledMetric(HotwordService *service, Profile* profile) { 179 void RecordHotwordEnabledMetric(HotwordService *service, Profile* profile) {
183 HotwordEnabled enabled_state = DISABLED; 180 HotwordEnabled enabled_state = DISABLED;
184 auto prefs = profile->GetPrefs(); 181 auto prefs = profile->GetPrefs();
185 if (!prefs->HasPrefPath(prefs::kHotwordSearchEnabled) && 182 if (!prefs->HasPrefPath(prefs::kHotwordSearchEnabled) &&
186 !prefs->HasPrefPath(prefs::kHotwordAlwaysOnSearchEnabled)) { 183 !prefs->HasPrefPath(prefs::kHotwordAlwaysOnSearchEnabled)) {
187 enabled_state = UNSET; 184 enabled_state = UNSET;
188 } else if (service->IsExperimentalHotwordingEnabled() && 185 } else if (service->IsAlwaysOnEnabled()) {
189 service->IsAlwaysOnEnabled()) {
190 enabled_state = ALWAYS_ON_ENABLED; 186 enabled_state = ALWAYS_ON_ENABLED;
191 } else if (prefs->GetBoolean(prefs::kHotwordSearchEnabled)) { 187 } else if (prefs->GetBoolean(prefs::kHotwordSearchEnabled)) {
192 enabled_state = ENABLED; 188 enabled_state = ENABLED;
193 } 189 }
194 UMA_HISTOGRAM_ENUMERATION("Hotword.Enabled", enabled_state, 190 UMA_HISTOGRAM_ENUMERATION("Hotword.Enabled", enabled_state,
195 NUM_HOTWORD_ENABLED_METRICS); 191 NUM_HOTWORD_ENABLED_METRICS);
196 } 192 }
197 193
198 ExtensionService* GetExtensionService(Profile* profile) { 194 ExtensionService* GetExtensionService(Profile* profile) {
199 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 195 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 l10n_util::NormalizeLocale(GetCurrentLocale(profile)); 282 l10n_util::NormalizeLocale(GetCurrentLocale(profile));
287 base::StringToLowerASCII(&normalized_locale); 283 base::StringToLowerASCII(&normalized_locale);
288 284
289 for (size_t i = 0; i < arraysize(kSupportedLocales); i++) { 285 for (size_t i = 0; i < arraysize(kSupportedLocales); i++) {
290 if (normalized_locale == kSupportedLocales[i]) 286 if (normalized_locale == kSupportedLocales[i])
291 return true; 287 return true;
292 } 288 }
293 return false; 289 return false;
294 } 290 }
295 291
296 // static
297 bool HotwordService::IsExperimentalHotwordingEnabled() {
298 return true;
299 }
300
301 #if defined(OS_CHROMEOS) 292 #if defined(OS_CHROMEOS)
302 class HotwordService::HotwordUserSessionStateObserver 293 class HotwordService::HotwordUserSessionStateObserver
303 : public user_manager::UserManager::UserSessionStateObserver { 294 : public user_manager::UserManager::UserSessionStateObserver {
304 public: 295 public:
305 explicit HotwordUserSessionStateObserver(HotwordService* service) 296 explicit HotwordUserSessionStateObserver(HotwordService* service)
306 : service_(service) {} 297 : service_(service) {}
307 298
308 // Overridden from UserSessionStateObserver: 299 // Overridden from UserSessionStateObserver:
309 void ActiveUserChanged(const user_manager::User* active_user) override { 300 void ActiveUserChanged(const user_manager::User* active_user) override {
310 service_->ActiveUserChanged(); 301 service_->ActiveUserChanged();
(...skipping 14 matching lines...) Expand all
325 316
326 HotwordService::HotwordService(Profile* profile) 317 HotwordService::HotwordService(Profile* profile)
327 : profile_(profile), 318 : profile_(profile),
328 extension_registry_observer_(this), 319 extension_registry_observer_(this),
329 client_(NULL), 320 client_(NULL),
330 error_message_(0), 321 error_message_(0),
331 reinstall_pending_(false), 322 reinstall_pending_(false),
332 training_(false), 323 training_(false),
333 weak_factory_(this) { 324 weak_factory_(this) {
334 extension_registry_observer_.Add(extensions::ExtensionRegistry::Get(profile)); 325 extension_registry_observer_.Add(extensions::ExtensionRegistry::Get(profile));
335 if (IsExperimentalHotwordingEnabled()) { 326
336 // Disable the old extension so it doesn't interfere with the new stuff. 327 // Disable the old extension so it doesn't interfere with the new stuff.
kcarattini 2015/03/17 00:41:13 Do we need to disable the hotword helper here as w
Anand Mistry (off Chromium) 2015/03/17 03:00:46 hotword_helper is a component that's being deleted
337 DisableHotwordExtension(GetExtensionService(profile_)); 328 ExtensionService* extension_service = GetExtensionService(profile_);
338 } else { 329 if (extension_service) {
339 if (!profile_->GetPrefs()->HasPrefPath(prefs::kHotwordSearchEnabled) && 330 extension_service->DisableExtension(
340 IsHotwordAllowed()) { 331 extension_misc::kHotwordOldExtensionId,
341 // If the preference has not been set the hotword extension should 332 extensions::Extension::DISABLE_USER_ACTION);
342 // not be running. However, this should only be done if auto-install
343 // is enabled which is gated through the IsHotwordAllowed check.
344 DisableHotwordExtension(GetExtensionService(profile_));
345 }
346 } 333 }
334
347 // This will be called during profile initialization which is a good time 335 // This will be called during profile initialization which is a good time
348 // to check the user's hotword state. 336 // to check the user's hotword state.
349 RecordHotwordEnabledMetric(this, profile_); 337 RecordHotwordEnabledMetric(this, profile_);
350 338
351 pref_registrar_.Init(profile_->GetPrefs()); 339 pref_registrar_.Init(profile_->GetPrefs());
352 pref_registrar_.Add( 340 pref_registrar_.Add(
353 prefs::kHotwordSearchEnabled,
354 base::Bind(&HotwordService::OnHotwordSearchEnabledChanged,
355 base::Unretained(this)));
356 pref_registrar_.Add(
357 prefs::kHotwordAlwaysOnSearchEnabled, 341 prefs::kHotwordAlwaysOnSearchEnabled,
358 base::Bind(&HotwordService::OnHotwordAlwaysOnSearchEnabledChanged, 342 base::Bind(&HotwordService::OnHotwordAlwaysOnSearchEnabledChanged,
359 base::Unretained(this))); 343 base::Unretained(this)));
360 344
361 extensions::ExtensionSystem::Get(profile_)->ready().Post( 345 extensions::ExtensionSystem::Get(profile_)->ready().Post(
362 FROM_HERE, 346 FROM_HERE,
363 base::Bind(base::IgnoreResult( 347 base::Bind(base::IgnoreResult(
364 &HotwordService::MaybeReinstallHotwordExtension), 348 &HotwordService::MaybeReinstallHotwordExtension),
365 weak_factory_.GetWeakPtr())); 349 weak_factory_.GetWeakPtr()));
366 350
367 // Clear the old user pref because it became unusable. 351 // Clear the old user pref because it became unusable.
368 // TODO(rlp): Remove this code per crbug.com/358789. 352 // TODO(rlp): Remove this code per crbug.com/358789.
369 if (profile_->GetPrefs()->HasPrefPath( 353 if (profile_->GetPrefs()->HasPrefPath(
370 hotword_internal::kHotwordUnusablePrefName)) { 354 hotword_internal::kHotwordUnusablePrefName)) {
371 profile_->GetPrefs()->ClearPref(hotword_internal::kHotwordUnusablePrefName); 355 profile_->GetPrefs()->ClearPref(hotword_internal::kHotwordUnusablePrefName);
372 } 356 }
373 357
374 SetAudioHistoryHandler(new HotwordAudioHistoryHandler( 358 SetAudioHistoryHandler(new HotwordAudioHistoryHandler(
375 profile_, base::MessageLoop::current()->task_runner())); 359 profile_, base::MessageLoop::current()->task_runner()));
376 360
377 if (HotwordServiceFactory::IsAlwaysOnAvailable() && 361 if (HotwordServiceFactory::IsAlwaysOnAvailable() &&
378 IsHotwordAllowed() && 362 IsHotwordAllowed()) {
379 IsExperimentalHotwordingEnabled()) {
380 // Show the hotword notification in 5 seconds if the experimental flag is 363 // Show the hotword notification in 5 seconds if the experimental flag is
381 // on, or in 30 minutes if not. We need to wait at least a few seconds 364 // on, or in 30 minutes if not. We need to wait at least a few seconds
382 // for the hotword extension to be installed. 365 // for the hotword extension to be installed.
383 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 366 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
384 if (command_line->HasSwitch(switches::kEnableExperimentalHotwordHardware)) { 367 if (command_line->HasSwitch(switches::kEnableExperimentalHotwordHardware)) {
385 base::MessageLoop::current()->PostDelayedTask( 368 base::MessageLoop::current()->PostDelayedTask(
386 FROM_HERE, 369 FROM_HERE,
387 base::Bind(&HotwordService::ShowHotwordNotification, 370 base::Bind(&HotwordService::ShowHotwordNotification,
388 weak_factory_.GetWeakPtr()), 371 weak_factory_.GetWeakPtr()),
389 base::TimeDelta::FromSeconds(5)); 372 base::TimeDelta::FromSeconds(5));
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 profile_->GetPrefs()->SetBoolean( 432 profile_->GetPrefs()->SetBoolean(
450 prefs::kHotwordAlwaysOnNotificationSeen, true); 433 prefs::kHotwordAlwaysOnNotificationSeen, true);
451 } 434 }
452 435
453 void HotwordService::OnExtensionUninstalled( 436 void HotwordService::OnExtensionUninstalled(
454 content::BrowserContext* browser_context, 437 content::BrowserContext* browser_context,
455 const extensions::Extension* extension, 438 const extensions::Extension* extension,
456 extensions::UninstallReason reason) { 439 extensions::UninstallReason reason) {
457 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 440 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
458 441
459 if ((extension->id() != extension_misc::kHotwordExtensionId && 442 if (extension->id() != extension_misc::kHotwordSharedModuleId ||
460 extension->id() != extension_misc::kHotwordSharedModuleId) || 443 profile_ != Profile::FromBrowserContext(browser_context) ||
461 profile_ != Profile::FromBrowserContext(browser_context) ||
462 !GetExtensionService(profile_)) 444 !GetExtensionService(profile_))
463 return; 445 return;
464 446
465 // If the extension wasn't uninstalled due to language change, don't try to 447 // If the extension wasn't uninstalled due to language change, don't try to
466 // reinstall it. 448 // reinstall it.
467 if (!reinstall_pending_) 449 if (!reinstall_pending_)
468 return; 450 return;
469 451
470 InstallHotwordExtensionFromWebstore(kMaxInstallRetries); 452 InstallHotwordExtensionFromWebstore(kMaxInstallRetries);
471 SetPreviousLanguagePref(); 453 SetPreviousLanguagePref();
472 } 454 }
473 455
474 std::string HotwordService::ReinstalledExtensionId() { 456 std::string HotwordService::ReinstalledExtensionId() {
475 if (IsExperimentalHotwordingEnabled()) 457 return extension_misc::kHotwordSharedModuleId;
476 return extension_misc::kHotwordSharedModuleId;
477
478 return extension_misc::kHotwordExtensionId;
479 } 458 }
480 459
481 void HotwordService::InstalledFromWebstoreCallback( 460 void HotwordService::InstalledFromWebstoreCallback(
482 int num_tries, 461 int num_tries,
483 bool success, 462 bool success,
484 const std::string& error, 463 const std::string& error,
485 extensions::webstore_install::Result result) { 464 extensions::webstore_install::Result result) {
486 if (result != extensions::webstore_install::SUCCESS && num_tries) { 465 if (result != extensions::webstore_install::SUCCESS && num_tries) {
487 // Try again on failure. 466 // Try again on failure.
488 content::BrowserThread::PostDelayedTask( 467 content::BrowserThread::PostDelayedTask(
(...skipping 14 matching lines...) Expand all
503 weak_factory_.GetWeakPtr(), 482 weak_factory_.GetWeakPtr(),
504 num_tries - 1)); 483 num_tries - 1));
505 installer_->BeginInstall(); 484 installer_->BeginInstall();
506 } 485 }
507 486
508 void HotwordService::OnExtensionInstalled( 487 void HotwordService::OnExtensionInstalled(
509 content::BrowserContext* browser_context, 488 content::BrowserContext* browser_context,
510 const extensions::Extension* extension, 489 const extensions::Extension* extension,
511 bool is_update) { 490 bool is_update) {
512 491
513 if ((extension->id() != extension_misc::kHotwordExtensionId && 492 if (extension->id() != extension_misc::kHotwordSharedModuleId ||
514 extension->id() != extension_misc::kHotwordSharedModuleId) || 493 profile_ != Profile::FromBrowserContext(browser_context))
515 profile_ != Profile::FromBrowserContext(browser_context))
516 return; 494 return;
517 495
518 // If the previous locale pref has never been set, set it now since 496 // If the previous locale pref has never been set, set it now since
519 // the extension has been installed. 497 // the extension has been installed.
520 if (!profile_->GetPrefs()->HasPrefPath(prefs::kHotwordPreviousLanguage)) 498 if (!profile_->GetPrefs()->HasPrefPath(prefs::kHotwordPreviousLanguage))
521 SetPreviousLanguagePref(); 499 SetPreviousLanguagePref();
522 500
523 // If MaybeReinstallHotwordExtension already triggered an uninstall, we 501 // If MaybeReinstallHotwordExtension already triggered an uninstall, we
524 // don't want to loop and trigger another uninstall-install cycle. 502 // don't want to loop and trigger another uninstall-install cycle.
525 // However, if we arrived here via an uninstall-triggered-install (and in 503 // However, if we arrived here via an uninstall-triggered-install (and in
526 // that case |reinstall_pending_| will be true) then we know install 504 // that case |reinstall_pending_| will be true) then we know install
527 // has completed and we can reset |reinstall_pending_|. 505 // has completed and we can reset |reinstall_pending_|.
528 if (!reinstall_pending_) 506 if (!reinstall_pending_)
529 MaybeReinstallHotwordExtension(); 507 MaybeReinstallHotwordExtension();
530 else 508 else
531 reinstall_pending_ = false; 509 reinstall_pending_ = false;
532
533 // Now that the extension is installed, if the user has not selected
534 // the preference on, make sure it is turned off.
535 //
536 // Disabling the extension automatically on install should only occur
537 // if the user is in the field trial for auto-install which is gated
538 // by the IsHotwordAllowed check. The check for IsHotwordAllowed() here
539 // can be removed once it's known that few people have manually
540 // installed extension.
541 if (IsHotwordAllowed() && !IsSometimesOnEnabled())
542 DisableHotwordExtension(GetExtensionService(profile_));
543 } 510 }
544 511
545 bool HotwordService::MaybeReinstallHotwordExtension() { 512 bool HotwordService::MaybeReinstallHotwordExtension() {
546 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 513 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
547 514
548 ExtensionService* extension_service = GetExtensionService(profile_); 515 ExtensionService* extension_service = GetExtensionService(profile_);
549 if (!extension_service) 516 if (!extension_service)
550 return false; 517 return false;
551 518
552 const extensions::Extension* extension = extension_service->GetExtensionById( 519 const extensions::Extension* extension = extension_service->GetExtensionById(
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 profile_->GetPrefs()->GetBoolean(prefs::kHotwordAlwaysOnSearchEnabled) && 649 profile_->GetPrefs()->GetBoolean(prefs::kHotwordAlwaysOnSearchEnabled) &&
683 HotwordServiceFactory::IsAlwaysOnAvailable(); 650 HotwordServiceFactory::IsAlwaysOnAvailable();
684 } 651 }
685 652
686 bool HotwordService::IsSometimesOnEnabled() { 653 bool HotwordService::IsSometimesOnEnabled() {
687 return profile_->GetPrefs()->HasPrefPath(prefs::kHotwordSearchEnabled) && 654 return profile_->GetPrefs()->HasPrefPath(prefs::kHotwordSearchEnabled) &&
688 profile_->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled) && 655 profile_->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled) &&
689 !HotwordServiceFactory::IsAlwaysOnAvailable(); 656 !HotwordServiceFactory::IsAlwaysOnAvailable();
690 } 657 }
691 658
692 void HotwordService::EnableHotwordExtension(
693 ExtensionService* extension_service) {
694 if (extension_service && !IsExperimentalHotwordingEnabled())
695 extension_service->EnableExtension(extension_misc::kHotwordExtensionId);
696 }
697
698 void HotwordService::DisableHotwordExtension(
699 ExtensionService* extension_service) {
700 if (extension_service) {
701 extension_service->DisableExtension(
702 extension_misc::kHotwordExtensionId,
703 extensions::Extension::DISABLE_USER_ACTION);
704 }
705 }
706
707 void HotwordService::LaunchHotwordAudioVerificationApp( 659 void HotwordService::LaunchHotwordAudioVerificationApp(
708 const LaunchMode& launch_mode) { 660 const LaunchMode& launch_mode) {
709 hotword_audio_verification_launch_mode_ = launch_mode; 661 hotword_audio_verification_launch_mode_ = launch_mode;
710 662
711 ExtensionService* extension_service = GetExtensionService(profile_); 663 ExtensionService* extension_service = GetExtensionService(profile_);
712 if (!extension_service) 664 if (!extension_service)
713 return; 665 return;
714 const extensions::Extension* extension = extension_service->GetExtensionById( 666 const extensions::Extension* extension = extension_service->GetExtensionById(
715 extension_misc::kHotwordAudioVerificationAppId, true); 667 extension_misc::kHotwordAudioVerificationAppId, true);
716 if (!extension) 668 if (!extension)
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 profile_->GetPrefs()->SetBoolean(prefs::kHotwordSearchEnabled, false); 742 profile_->GetPrefs()->SetBoolean(prefs::kHotwordSearchEnabled, false);
791 } else if (IsAlwaysOnEnabled()) { 743 } else if (IsAlwaysOnEnabled()) {
792 if (profile_->GetPrefs()->HasPrefPath( 744 if (profile_->GetPrefs()->HasPrefPath(
793 prefs::kHotwordAlwaysOnSearchEnabled)) { 745 prefs::kHotwordAlwaysOnSearchEnabled)) {
794 profile_->GetPrefs()->SetBoolean(prefs::kHotwordAlwaysOnSearchEnabled, 746 profile_->GetPrefs()->SetBoolean(prefs::kHotwordAlwaysOnSearchEnabled,
795 false); 747 false);
796 } 748 }
797 } 749 }
798 } 750 }
799 751
800 void HotwordService::OnHotwordSearchEnabledChanged(
801 const std::string& pref_name) {
802 DCHECK_EQ(pref_name, std::string(prefs::kHotwordSearchEnabled));
803
804 ExtensionService* extension_service = GetExtensionService(profile_);
805 if (profile_->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled))
806 EnableHotwordExtension(extension_service);
807 else
808 DisableHotwordExtension(extension_service);
809 }
810
811 void HotwordService::OnHotwordAlwaysOnSearchEnabledChanged( 752 void HotwordService::OnHotwordAlwaysOnSearchEnabledChanged(
812 const std::string& pref_name) { 753 const std::string& pref_name) {
813 // If the pref for always on has been changed in some way, that means that 754 // If the pref for always on has been changed in some way, that means that
814 // the user is aware of always on (either from settings or another source) 755 // the user is aware of always on (either from settings or another source)
815 // so they don't need to be shown the notification. 756 // so they don't need to be shown the notification.
816 profile_->GetPrefs()->SetBoolean(prefs::kHotwordAlwaysOnNotificationSeen, 757 profile_->GetPrefs()->SetBoolean(prefs::kHotwordAlwaysOnNotificationSeen,
817 true); 758 true);
818 pref_registrar_.Remove(prefs::kHotwordAlwaysOnSearchEnabled); 759 pref_registrar_.Remove(prefs::kHotwordAlwaysOnSearchEnabled);
819 } 760 }
820 761
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
860 std::string previous_locale = 801 std::string previous_locale =
861 profile_->GetPrefs()->GetString(prefs::kHotwordPreviousLanguage); 802 profile_->GetPrefs()->GetString(prefs::kHotwordPreviousLanguage);
862 std::string locale = GetCurrentLocale(profile_); 803 std::string locale = GetCurrentLocale(profile_);
863 804
864 // If it's a new locale, then the old extension should be uninstalled. 805 // If it's a new locale, then the old extension should be uninstalled.
865 return locale != previous_locale && 806 return locale != previous_locale &&
866 HotwordService::DoesHotwordSupportLanguage(profile_); 807 HotwordService::DoesHotwordSupportLanguage(profile_);
867 } 808 }
868 809
869 void HotwordService::ActiveUserChanged() { 810 void HotwordService::ActiveUserChanged() {
870 // Do nothing for old hotwording.
871 if (!IsExperimentalHotwordingEnabled())
872 return;
873
874 // Don't bother notifying the extension if hotwording is completely off. 811 // Don't bother notifying the extension if hotwording is completely off.
875 if (!IsSometimesOnEnabled() && !IsAlwaysOnEnabled() && !IsTraining()) 812 if (!IsSometimesOnEnabled() && !IsAlwaysOnEnabled() && !IsTraining())
876 return; 813 return;
877 814
878 HotwordPrivateEventService* event_service = 815 HotwordPrivateEventService* event_service =
879 BrowserContextKeyedAPIFactory<HotwordPrivateEventService>::Get(profile_); 816 BrowserContextKeyedAPIFactory<HotwordPrivateEventService>::Get(profile_);
880 // "enabled" isn't being changed, but piggy-back off the notification anyway. 817 // "enabled" isn't being changed, but piggy-back off the notification anyway.
881 if (event_service) 818 if (event_service)
882 event_service->OnEnabledChanged(prefs::kHotwordSearchEnabled); 819 event_service->OnEnabledChanged(prefs::kHotwordSearchEnabled);
883 } 820 }
884 821
885 bool HotwordService::UserIsActive() { 822 bool HotwordService::UserIsActive() {
886 #if defined(OS_CHROMEOS) 823 #if defined(OS_CHROMEOS)
887 // Only support multiple profiles and profile switching in ChromeOS. 824 // Only support multiple profiles and profile switching in ChromeOS.
888 if (user_manager::UserManager::IsInitialized()) { 825 if (user_manager::UserManager::IsInitialized()) {
889 user_manager::User* user = 826 user_manager::User* user =
890 user_manager::UserManager::Get()->GetActiveUser(); 827 user_manager::UserManager::Get()->GetActiveUser();
891 if (user && user->is_profile_created()) 828 if (user && user->is_profile_created())
892 return profile_ == ProfileManager::GetActiveUserProfile(); 829 return profile_ == ProfileManager::GetActiveUserProfile();
893 } 830 }
894 #endif 831 #endif
895 return true; 832 return true;
896 } 833 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698