| OLD | NEW |
| 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 // This is used for UMA stats -- do not reorder or delete items; only add to | 121 // This is used for UMA stats -- do not reorder or delete items; only add to |
| 122 // the end. | 122 // the end. |
| 123 enum HotwordError { | 123 enum HotwordError { |
| 124 NO_HOTWORD_ERROR = 0, | 124 NO_HOTWORD_ERROR = 0, |
| 125 GENERIC_HOTWORD_ERROR, | 125 GENERIC_HOTWORD_ERROR, |
| 126 NACL_HOTWORD_ERROR, | 126 NACL_HOTWORD_ERROR, |
| 127 MICROPHONE_HOTWORD_ERROR, | 127 MICROPHONE_HOTWORD_ERROR, |
| 128 NUM_HOTWORD_ERROR_METRICS | 128 NUM_HOTWORD_ERROR_METRICS |
| 129 }; | 129 }; |
| 130 | 130 |
| 131 void RecordExtensionAvailabilityMetrics( | |
| 132 ExtensionService* service, | |
| 133 const extensions::Extension* extension) { | |
| 134 HotwordExtensionAvailability availability_state = UNAVAILABLE; | |
| 135 if (extension) { | |
| 136 availability_state = AVAILABLE; | |
| 137 } else if (service->pending_extension_manager() && | |
| 138 service->pending_extension_manager()->IsIdPending( | |
| 139 extension_misc::kHotwordExtensionId)) { | |
| 140 availability_state = PENDING_DOWNLOAD; | |
| 141 } else if (!service->IsExtensionEnabled( | |
| 142 extension_misc::kHotwordExtensionId)) { | |
| 143 availability_state = DISABLED_EXTENSION; | |
| 144 } | |
| 145 UMA_HISTOGRAM_ENUMERATION("Hotword.HotwordExtensionAvailability", | |
| 146 availability_state, | |
| 147 NUM_HOTWORD_EXTENSION_AVAILABILITY_METRICS); | |
| 148 } | |
| 149 | |
| 150 void RecordLoggingMetrics(Profile* profile) { | 131 void RecordLoggingMetrics(Profile* profile) { |
| 151 // If the user is not opted in to hotword voice search, the audio logging | 132 // If the user is not opted in to hotword voice search, the audio logging |
| 152 // metric is not valid so it is not recorded. | 133 // metric is not valid so it is not recorded. |
| 153 if (!profile->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled)) | 134 if (!profile->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled)) |
| 154 return; | 135 return; |
| 155 | 136 |
| 156 UMA_HISTOGRAM_BOOLEAN( | 137 UMA_HISTOGRAM_BOOLEAN( |
| 157 "Hotword.HotwordAudioLogging", | 138 "Hotword.HotwordAudioLogging", |
| 158 profile->GetPrefs()->GetBoolean(prefs::kHotwordAudioLoggingEnabled)); | 139 profile->GetPrefs()->GetBoolean(prefs::kHotwordAudioLoggingEnabled)); |
| 159 } | 140 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 178 error, | 159 error, |
| 179 NUM_HOTWORD_ERROR_METRICS); | 160 NUM_HOTWORD_ERROR_METRICS); |
| 180 } | 161 } |
| 181 | 162 |
| 182 void RecordHotwordEnabledMetric(HotwordService *service, Profile* profile) { | 163 void RecordHotwordEnabledMetric(HotwordService *service, Profile* profile) { |
| 183 HotwordEnabled enabled_state = DISABLED; | 164 HotwordEnabled enabled_state = DISABLED; |
| 184 auto prefs = profile->GetPrefs(); | 165 auto prefs = profile->GetPrefs(); |
| 185 if (!prefs->HasPrefPath(prefs::kHotwordSearchEnabled) && | 166 if (!prefs->HasPrefPath(prefs::kHotwordSearchEnabled) && |
| 186 !prefs->HasPrefPath(prefs::kHotwordAlwaysOnSearchEnabled)) { | 167 !prefs->HasPrefPath(prefs::kHotwordAlwaysOnSearchEnabled)) { |
| 187 enabled_state = UNSET; | 168 enabled_state = UNSET; |
| 188 } else if (service->IsExperimentalHotwordingEnabled() && | 169 } else if (service->IsAlwaysOnEnabled()) { |
| 189 service->IsAlwaysOnEnabled()) { | |
| 190 enabled_state = ALWAYS_ON_ENABLED; | 170 enabled_state = ALWAYS_ON_ENABLED; |
| 191 } else if (prefs->GetBoolean(prefs::kHotwordSearchEnabled)) { | 171 } else if (prefs->GetBoolean(prefs::kHotwordSearchEnabled)) { |
| 192 enabled_state = ENABLED; | 172 enabled_state = ENABLED; |
| 193 } | 173 } |
| 194 UMA_HISTOGRAM_ENUMERATION("Hotword.Enabled", enabled_state, | 174 UMA_HISTOGRAM_ENUMERATION("Hotword.Enabled", enabled_state, |
| 195 NUM_HOTWORD_ENABLED_METRICS); | 175 NUM_HOTWORD_ENABLED_METRICS); |
| 196 } | 176 } |
| 197 | 177 |
| 198 ExtensionService* GetExtensionService(Profile* profile) { | 178 ExtensionService* GetExtensionService(Profile* profile) { |
| 199 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 179 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 l10n_util::NormalizeLocale(GetCurrentLocale(profile)); | 266 l10n_util::NormalizeLocale(GetCurrentLocale(profile)); |
| 287 base::StringToLowerASCII(&normalized_locale); | 267 base::StringToLowerASCII(&normalized_locale); |
| 288 | 268 |
| 289 for (size_t i = 0; i < arraysize(kSupportedLocales); i++) { | 269 for (size_t i = 0; i < arraysize(kSupportedLocales); i++) { |
| 290 if (normalized_locale == kSupportedLocales[i]) | 270 if (normalized_locale == kSupportedLocales[i]) |
| 291 return true; | 271 return true; |
| 292 } | 272 } |
| 293 return false; | 273 return false; |
| 294 } | 274 } |
| 295 | 275 |
| 296 // static | |
| 297 bool HotwordService::IsExperimentalHotwordingEnabled() { | |
| 298 return true; | |
| 299 } | |
| 300 | |
| 301 #if defined(OS_CHROMEOS) | 276 #if defined(OS_CHROMEOS) |
| 302 class HotwordService::HotwordUserSessionStateObserver | 277 class HotwordService::HotwordUserSessionStateObserver |
| 303 : public user_manager::UserManager::UserSessionStateObserver { | 278 : public user_manager::UserManager::UserSessionStateObserver { |
| 304 public: | 279 public: |
| 305 explicit HotwordUserSessionStateObserver(HotwordService* service) | 280 explicit HotwordUserSessionStateObserver(HotwordService* service) |
| 306 : service_(service) {} | 281 : service_(service) {} |
| 307 | 282 |
| 308 // Overridden from UserSessionStateObserver: | 283 // Overridden from UserSessionStateObserver: |
| 309 void ActiveUserChanged(const user_manager::User* active_user) override { | 284 void ActiveUserChanged(const user_manager::User* active_user) override { |
| 310 service_->ActiveUserChanged(); | 285 service_->ActiveUserChanged(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 325 | 300 |
| 326 HotwordService::HotwordService(Profile* profile) | 301 HotwordService::HotwordService(Profile* profile) |
| 327 : profile_(profile), | 302 : profile_(profile), |
| 328 extension_registry_observer_(this), | 303 extension_registry_observer_(this), |
| 329 client_(NULL), | 304 client_(NULL), |
| 330 error_message_(0), | 305 error_message_(0), |
| 331 reinstall_pending_(false), | 306 reinstall_pending_(false), |
| 332 training_(false), | 307 training_(false), |
| 333 weak_factory_(this) { | 308 weak_factory_(this) { |
| 334 extension_registry_observer_.Add(extensions::ExtensionRegistry::Get(profile)); | 309 extension_registry_observer_.Add(extensions::ExtensionRegistry::Get(profile)); |
| 335 if (IsExperimentalHotwordingEnabled()) { | 310 |
| 336 // Disable the old extension so it doesn't interfere with the new stuff. | 311 // Disable the old extension so it doesn't interfere with the new stuff. |
| 337 DisableHotwordExtension(GetExtensionService(profile_)); | 312 ExtensionService* extension_service = GetExtensionService(profile_); |
| 338 } else { | 313 if (extension_service) { |
| 339 if (!profile_->GetPrefs()->HasPrefPath(prefs::kHotwordSearchEnabled) && | 314 extension_service->DisableExtension( |
| 340 IsHotwordAllowed()) { | 315 extension_misc::kHotwordOldExtensionId, |
| 341 // If the preference has not been set the hotword extension should | 316 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 } | 317 } |
| 318 |
| 347 // This will be called during profile initialization which is a good time | 319 // This will be called during profile initialization which is a good time |
| 348 // to check the user's hotword state. | 320 // to check the user's hotword state. |
| 349 RecordHotwordEnabledMetric(this, profile_); | 321 RecordHotwordEnabledMetric(this, profile_); |
| 350 | 322 |
| 351 pref_registrar_.Init(profile_->GetPrefs()); | 323 pref_registrar_.Init(profile_->GetPrefs()); |
| 352 pref_registrar_.Add( | 324 pref_registrar_.Add( |
| 353 prefs::kHotwordSearchEnabled, | |
| 354 base::Bind(&HotwordService::OnHotwordSearchEnabledChanged, | |
| 355 base::Unretained(this))); | |
| 356 pref_registrar_.Add( | |
| 357 prefs::kHotwordAlwaysOnSearchEnabled, | 325 prefs::kHotwordAlwaysOnSearchEnabled, |
| 358 base::Bind(&HotwordService::OnHotwordAlwaysOnSearchEnabledChanged, | 326 base::Bind(&HotwordService::OnHotwordAlwaysOnSearchEnabledChanged, |
| 359 base::Unretained(this))); | 327 base::Unretained(this))); |
| 360 | 328 |
| 361 extensions::ExtensionSystem::Get(profile_)->ready().Post( | 329 extensions::ExtensionSystem::Get(profile_)->ready().Post( |
| 362 FROM_HERE, | 330 FROM_HERE, |
| 363 base::Bind(base::IgnoreResult( | 331 base::Bind(base::IgnoreResult( |
| 364 &HotwordService::MaybeReinstallHotwordExtension), | 332 &HotwordService::MaybeReinstallHotwordExtension), |
| 365 weak_factory_.GetWeakPtr())); | 333 weak_factory_.GetWeakPtr())); |
| 366 | 334 |
| 367 // Clear the old user pref because it became unusable. | 335 // Clear the old user pref because it became unusable. |
| 368 // TODO(rlp): Remove this code per crbug.com/358789. | 336 // TODO(rlp): Remove this code per crbug.com/358789. |
| 369 if (profile_->GetPrefs()->HasPrefPath( | 337 if (profile_->GetPrefs()->HasPrefPath( |
| 370 hotword_internal::kHotwordUnusablePrefName)) { | 338 hotword_internal::kHotwordUnusablePrefName)) { |
| 371 profile_->GetPrefs()->ClearPref(hotword_internal::kHotwordUnusablePrefName); | 339 profile_->GetPrefs()->ClearPref(hotword_internal::kHotwordUnusablePrefName); |
| 372 } | 340 } |
| 373 | 341 |
| 374 SetAudioHistoryHandler(new HotwordAudioHistoryHandler( | 342 SetAudioHistoryHandler(new HotwordAudioHistoryHandler( |
| 375 profile_, base::MessageLoop::current()->task_runner())); | 343 profile_, base::MessageLoop::current()->task_runner())); |
| 376 | 344 |
| 377 if (HotwordServiceFactory::IsAlwaysOnAvailable() && | 345 if (HotwordServiceFactory::IsAlwaysOnAvailable() && |
| 378 IsHotwordAllowed() && | 346 IsHotwordAllowed()) { |
| 379 IsExperimentalHotwordingEnabled()) { | |
| 380 // Show the hotword notification in 5 seconds if the experimental flag is | 347 // Show the hotword notification in 5 seconds if the experimental flag is |
| 381 // on, or in 10 minutes if not. We need to wait at least a few seconds | 348 // on, or in 10 minutes if not. We need to wait at least a few seconds |
| 382 // for the hotword extension to be installed. | 349 // for the hotword extension to be installed. |
| 383 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 350 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 384 if (command_line->HasSwitch(switches::kEnableExperimentalHotwordHardware)) { | 351 if (command_line->HasSwitch(switches::kEnableExperimentalHotwordHardware)) { |
| 385 base::MessageLoop::current()->PostDelayedTask( | 352 base::MessageLoop::current()->PostDelayedTask( |
| 386 FROM_HERE, | 353 FROM_HERE, |
| 387 base::Bind(&HotwordService::ShowHotwordNotification, | 354 base::Bind(&HotwordService::ShowHotwordNotification, |
| 388 weak_factory_.GetWeakPtr()), | 355 weak_factory_.GetWeakPtr()), |
| 389 base::TimeDelta::FromSeconds(5)); | 356 base::TimeDelta::FromSeconds(5)); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 profile_->GetPrefs()->SetBoolean( | 416 profile_->GetPrefs()->SetBoolean( |
| 450 prefs::kHotwordAlwaysOnNotificationSeen, true); | 417 prefs::kHotwordAlwaysOnNotificationSeen, true); |
| 451 } | 418 } |
| 452 | 419 |
| 453 void HotwordService::OnExtensionUninstalled( | 420 void HotwordService::OnExtensionUninstalled( |
| 454 content::BrowserContext* browser_context, | 421 content::BrowserContext* browser_context, |
| 455 const extensions::Extension* extension, | 422 const extensions::Extension* extension, |
| 456 extensions::UninstallReason reason) { | 423 extensions::UninstallReason reason) { |
| 457 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 424 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 458 | 425 |
| 459 if ((extension->id() != extension_misc::kHotwordExtensionId && | 426 if (extension->id() != extension_misc::kHotwordSharedModuleId || |
| 460 extension->id() != extension_misc::kHotwordSharedModuleId) || | 427 profile_ != Profile::FromBrowserContext(browser_context) || |
| 461 profile_ != Profile::FromBrowserContext(browser_context) || | |
| 462 !GetExtensionService(profile_)) | 428 !GetExtensionService(profile_)) |
| 463 return; | 429 return; |
| 464 | 430 |
| 465 // If the extension wasn't uninstalled due to language change, don't try to | 431 // If the extension wasn't uninstalled due to language change, don't try to |
| 466 // reinstall it. | 432 // reinstall it. |
| 467 if (!reinstall_pending_) | 433 if (!reinstall_pending_) |
| 468 return; | 434 return; |
| 469 | 435 |
| 470 InstallHotwordExtensionFromWebstore(kMaxInstallRetries); | 436 InstallHotwordExtensionFromWebstore(kMaxInstallRetries); |
| 471 SetPreviousLanguagePref(); | 437 SetPreviousLanguagePref(); |
| 472 } | 438 } |
| 473 | 439 |
| 474 std::string HotwordService::ReinstalledExtensionId() { | 440 std::string HotwordService::ReinstalledExtensionId() { |
| 475 if (IsExperimentalHotwordingEnabled()) | 441 return extension_misc::kHotwordSharedModuleId; |
| 476 return extension_misc::kHotwordSharedModuleId; | |
| 477 | |
| 478 return extension_misc::kHotwordExtensionId; | |
| 479 } | 442 } |
| 480 | 443 |
| 481 void HotwordService::InstalledFromWebstoreCallback( | 444 void HotwordService::InstalledFromWebstoreCallback( |
| 482 int num_tries, | 445 int num_tries, |
| 483 bool success, | 446 bool success, |
| 484 const std::string& error, | 447 const std::string& error, |
| 485 extensions::webstore_install::Result result) { | 448 extensions::webstore_install::Result result) { |
| 486 if (result != extensions::webstore_install::SUCCESS && num_tries) { | 449 if (result != extensions::webstore_install::SUCCESS && num_tries) { |
| 487 // Try again on failure. | 450 // Try again on failure. |
| 488 content::BrowserThread::PostDelayedTask( | 451 content::BrowserThread::PostDelayedTask( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 503 weak_factory_.GetWeakPtr(), | 466 weak_factory_.GetWeakPtr(), |
| 504 num_tries - 1)); | 467 num_tries - 1)); |
| 505 installer_->BeginInstall(); | 468 installer_->BeginInstall(); |
| 506 } | 469 } |
| 507 | 470 |
| 508 void HotwordService::OnExtensionInstalled( | 471 void HotwordService::OnExtensionInstalled( |
| 509 content::BrowserContext* browser_context, | 472 content::BrowserContext* browser_context, |
| 510 const extensions::Extension* extension, | 473 const extensions::Extension* extension, |
| 511 bool is_update) { | 474 bool is_update) { |
| 512 | 475 |
| 513 if ((extension->id() != extension_misc::kHotwordExtensionId && | 476 if (extension->id() != extension_misc::kHotwordSharedModuleId || |
| 514 extension->id() != extension_misc::kHotwordSharedModuleId) || | 477 profile_ != Profile::FromBrowserContext(browser_context)) |
| 515 profile_ != Profile::FromBrowserContext(browser_context)) | |
| 516 return; | 478 return; |
| 517 | 479 |
| 518 // If the previous locale pref has never been set, set it now since | 480 // If the previous locale pref has never been set, set it now since |
| 519 // the extension has been installed. | 481 // the extension has been installed. |
| 520 if (!profile_->GetPrefs()->HasPrefPath(prefs::kHotwordPreviousLanguage)) | 482 if (!profile_->GetPrefs()->HasPrefPath(prefs::kHotwordPreviousLanguage)) |
| 521 SetPreviousLanguagePref(); | 483 SetPreviousLanguagePref(); |
| 522 | 484 |
| 523 // If MaybeReinstallHotwordExtension already triggered an uninstall, we | 485 // If MaybeReinstallHotwordExtension already triggered an uninstall, we |
| 524 // don't want to loop and trigger another uninstall-install cycle. | 486 // don't want to loop and trigger another uninstall-install cycle. |
| 525 // However, if we arrived here via an uninstall-triggered-install (and in | 487 // However, if we arrived here via an uninstall-triggered-install (and in |
| 526 // that case |reinstall_pending_| will be true) then we know install | 488 // that case |reinstall_pending_| will be true) then we know install |
| 527 // has completed and we can reset |reinstall_pending_|. | 489 // has completed and we can reset |reinstall_pending_|. |
| 528 if (!reinstall_pending_) | 490 if (!reinstall_pending_) |
| 529 MaybeReinstallHotwordExtension(); | 491 MaybeReinstallHotwordExtension(); |
| 530 else | 492 else |
| 531 reinstall_pending_ = false; | 493 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 } | 494 } |
| 544 | 495 |
| 545 bool HotwordService::MaybeReinstallHotwordExtension() { | 496 bool HotwordService::MaybeReinstallHotwordExtension() { |
| 546 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 497 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 547 | 498 |
| 548 ExtensionService* extension_service = GetExtensionService(profile_); | 499 ExtensionService* extension_service = GetExtensionService(profile_); |
| 549 if (!extension_service) | 500 if (!extension_service) |
| 550 return false; | 501 return false; |
| 551 | 502 |
| 552 const extensions::Extension* extension = extension_service->GetExtensionById( | 503 const extensions::Extension* extension = extension_service->GetExtensionById( |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 extensions::ExtensionSystem* system = | 566 extensions::ExtensionSystem* system = |
| 616 extensions::ExtensionSystem::Get(profile_); | 567 extensions::ExtensionSystem::Get(profile_); |
| 617 ExtensionService* service = system->extension_service(); | 568 ExtensionService* service = system->extension_service(); |
| 618 // Include disabled extensions (true parameter) since it may not be enabled | 569 // Include disabled extensions (true parameter) since it may not be enabled |
| 619 // if the user opted out. | 570 // if the user opted out. |
| 620 const extensions::Extension* extension = | 571 const extensions::Extension* extension = |
| 621 service->GetExtensionById(ReinstalledExtensionId(), true); | 572 service->GetExtensionById(ReinstalledExtensionId(), true); |
| 622 if (!extension) | 573 if (!extension) |
| 623 error_message_ = IDS_HOTWORD_GENERIC_ERROR_MESSAGE; | 574 error_message_ = IDS_HOTWORD_GENERIC_ERROR_MESSAGE; |
| 624 | 575 |
| 625 RecordExtensionAvailabilityMetrics(service, extension); | 576 // TODO(amistry): Record availability of shared module in UMA. |
| 626 RecordLoggingMetrics(profile_); | 577 RecordLoggingMetrics(profile_); |
| 627 | 578 |
| 628 // Determine if NaCl is available. | 579 // Determine if NaCl is available. |
| 629 bool nacl_enabled = false; | 580 bool nacl_enabled = false; |
| 630 base::FilePath path; | 581 base::FilePath path; |
| 631 if (PathService::Get(chrome::FILE_NACL_PLUGIN, &path)) { | 582 if (PathService::Get(chrome::FILE_NACL_PLUGIN, &path)) { |
| 632 content::WebPluginInfo info; | 583 content::WebPluginInfo info; |
| 633 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile_).get(); | 584 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile_).get(); |
| 634 if (content::PluginService::GetInstance()->GetPluginInfoByPath(path, &info)) | 585 if (content::PluginService::GetInstance()->GetPluginInfoByPath(path, &info)) |
| 635 nacl_enabled = plugin_prefs->IsPluginEnabled(info); | 586 nacl_enabled = plugin_prefs->IsPluginEnabled(info); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 profile_->GetPrefs()->GetBoolean(prefs::kHotwordAlwaysOnSearchEnabled) && | 633 profile_->GetPrefs()->GetBoolean(prefs::kHotwordAlwaysOnSearchEnabled) && |
| 683 HotwordServiceFactory::IsAlwaysOnAvailable(); | 634 HotwordServiceFactory::IsAlwaysOnAvailable(); |
| 684 } | 635 } |
| 685 | 636 |
| 686 bool HotwordService::IsSometimesOnEnabled() { | 637 bool HotwordService::IsSometimesOnEnabled() { |
| 687 return profile_->GetPrefs()->HasPrefPath(prefs::kHotwordSearchEnabled) && | 638 return profile_->GetPrefs()->HasPrefPath(prefs::kHotwordSearchEnabled) && |
| 688 profile_->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled) && | 639 profile_->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled) && |
| 689 !HotwordServiceFactory::IsAlwaysOnAvailable(); | 640 !HotwordServiceFactory::IsAlwaysOnAvailable(); |
| 690 } | 641 } |
| 691 | 642 |
| 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( | 643 void HotwordService::LaunchHotwordAudioVerificationApp( |
| 708 const LaunchMode& launch_mode) { | 644 const LaunchMode& launch_mode) { |
| 709 hotword_audio_verification_launch_mode_ = launch_mode; | 645 hotword_audio_verification_launch_mode_ = launch_mode; |
| 710 | 646 |
| 711 ExtensionService* extension_service = GetExtensionService(profile_); | 647 ExtensionService* extension_service = GetExtensionService(profile_); |
| 712 if (!extension_service) | 648 if (!extension_service) |
| 713 return; | 649 return; |
| 714 const extensions::Extension* extension = extension_service->GetExtensionById( | 650 const extensions::Extension* extension = extension_service->GetExtensionById( |
| 715 extension_misc::kHotwordAudioVerificationAppId, true); | 651 extension_misc::kHotwordAudioVerificationAppId, true); |
| 716 if (!extension) | 652 if (!extension) |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 787 void HotwordService::DisableHotwordPreferences() { | 723 void HotwordService::DisableHotwordPreferences() { |
| 788 if (IsSometimesOnEnabled()) { | 724 if (IsSometimesOnEnabled()) { |
| 789 profile_->GetPrefs()->SetBoolean(prefs::kHotwordSearchEnabled, false); | 725 profile_->GetPrefs()->SetBoolean(prefs::kHotwordSearchEnabled, false); |
| 790 } | 726 } |
| 791 if (IsAlwaysOnEnabled()) { | 727 if (IsAlwaysOnEnabled()) { |
| 792 profile_->GetPrefs()->SetBoolean(prefs::kHotwordAlwaysOnSearchEnabled, | 728 profile_->GetPrefs()->SetBoolean(prefs::kHotwordAlwaysOnSearchEnabled, |
| 793 false); | 729 false); |
| 794 } | 730 } |
| 795 } | 731 } |
| 796 | 732 |
| 797 void HotwordService::OnHotwordSearchEnabledChanged( | |
| 798 const std::string& pref_name) { | |
| 799 DCHECK_EQ(pref_name, std::string(prefs::kHotwordSearchEnabled)); | |
| 800 | |
| 801 ExtensionService* extension_service = GetExtensionService(profile_); | |
| 802 if (profile_->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled)) | |
| 803 EnableHotwordExtension(extension_service); | |
| 804 else | |
| 805 DisableHotwordExtension(extension_service); | |
| 806 } | |
| 807 | |
| 808 void HotwordService::OnHotwordAlwaysOnSearchEnabledChanged( | 733 void HotwordService::OnHotwordAlwaysOnSearchEnabledChanged( |
| 809 const std::string& pref_name) { | 734 const std::string& pref_name) { |
| 810 // If the pref for always on has been changed in some way, that means that | 735 // If the pref for always on has been changed in some way, that means that |
| 811 // the user is aware of always on (either from settings or another source) | 736 // the user is aware of always on (either from settings or another source) |
| 812 // so they don't need to be shown the notification. | 737 // so they don't need to be shown the notification. |
| 813 profile_->GetPrefs()->SetBoolean(prefs::kHotwordAlwaysOnNotificationSeen, | 738 profile_->GetPrefs()->SetBoolean(prefs::kHotwordAlwaysOnNotificationSeen, |
| 814 true); | 739 true); |
| 815 pref_registrar_.Remove(prefs::kHotwordAlwaysOnSearchEnabled); | 740 pref_registrar_.Remove(prefs::kHotwordAlwaysOnSearchEnabled); |
| 816 } | 741 } |
| 817 | 742 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 857 std::string previous_locale = | 782 std::string previous_locale = |
| 858 profile_->GetPrefs()->GetString(prefs::kHotwordPreviousLanguage); | 783 profile_->GetPrefs()->GetString(prefs::kHotwordPreviousLanguage); |
| 859 std::string locale = GetCurrentLocale(profile_); | 784 std::string locale = GetCurrentLocale(profile_); |
| 860 | 785 |
| 861 // If it's a new locale, then the old extension should be uninstalled. | 786 // If it's a new locale, then the old extension should be uninstalled. |
| 862 return locale != previous_locale && | 787 return locale != previous_locale && |
| 863 HotwordService::DoesHotwordSupportLanguage(profile_); | 788 HotwordService::DoesHotwordSupportLanguage(profile_); |
| 864 } | 789 } |
| 865 | 790 |
| 866 void HotwordService::ActiveUserChanged() { | 791 void HotwordService::ActiveUserChanged() { |
| 867 // Do nothing for old hotwording. | |
| 868 if (!IsExperimentalHotwordingEnabled()) | |
| 869 return; | |
| 870 | |
| 871 // Don't bother notifying the extension if hotwording is completely off. | 792 // Don't bother notifying the extension if hotwording is completely off. |
| 872 if (!IsSometimesOnEnabled() && !IsAlwaysOnEnabled() && !IsTraining()) | 793 if (!IsSometimesOnEnabled() && !IsAlwaysOnEnabled() && !IsTraining()) |
| 873 return; | 794 return; |
| 874 | 795 |
| 875 HotwordPrivateEventService* event_service = | 796 HotwordPrivateEventService* event_service = |
| 876 BrowserContextKeyedAPIFactory<HotwordPrivateEventService>::Get(profile_); | 797 BrowserContextKeyedAPIFactory<HotwordPrivateEventService>::Get(profile_); |
| 877 // "enabled" isn't being changed, but piggy-back off the notification anyway. | 798 // "enabled" isn't being changed, but piggy-back off the notification anyway. |
| 878 if (event_service) | 799 if (event_service) |
| 879 event_service->OnEnabledChanged(prefs::kHotwordSearchEnabled); | 800 event_service->OnEnabledChanged(prefs::kHotwordSearchEnabled); |
| 880 } | 801 } |
| 881 | 802 |
| 882 bool HotwordService::UserIsActive() { | 803 bool HotwordService::UserIsActive() { |
| 883 #if defined(OS_CHROMEOS) | 804 #if defined(OS_CHROMEOS) |
| 884 // Only support multiple profiles and profile switching in ChromeOS. | 805 // Only support multiple profiles and profile switching in ChromeOS. |
| 885 if (user_manager::UserManager::IsInitialized()) { | 806 if (user_manager::UserManager::IsInitialized()) { |
| 886 user_manager::User* user = | 807 user_manager::User* user = |
| 887 user_manager::UserManager::Get()->GetActiveUser(); | 808 user_manager::UserManager::Get()->GetActiveUser(); |
| 888 if (user && user->is_profile_created()) | 809 if (user && user->is_profile_created()) |
| 889 return profile_ == ProfileManager::GetActiveUserProfile(); | 810 return profile_ == ProfileManager::GetActiveUserProfile(); |
| 890 } | 811 } |
| 891 #endif | 812 #endif |
| 892 return true; | 813 return true; |
| 893 } | 814 } |
| OLD | NEW |