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