| 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 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 // Clear the old user pref because it became unusable. | 376 // Clear the old user pref because it became unusable. |
| 377 // TODO(rlp): Remove this code per crbug.com/358789. | 377 // TODO(rlp): Remove this code per crbug.com/358789. |
| 378 if (profile_->GetPrefs()->HasPrefPath( | 378 if (profile_->GetPrefs()->HasPrefPath( |
| 379 hotword_internal::kHotwordUnusablePrefName)) { | 379 hotword_internal::kHotwordUnusablePrefName)) { |
| 380 profile_->GetPrefs()->ClearPref(hotword_internal::kHotwordUnusablePrefName); | 380 profile_->GetPrefs()->ClearPref(hotword_internal::kHotwordUnusablePrefName); |
| 381 } | 381 } |
| 382 | 382 |
| 383 SetAudioHistoryHandler(new HotwordAudioHistoryHandler( | 383 SetAudioHistoryHandler(new HotwordAudioHistoryHandler( |
| 384 profile_, base::MessageLoop::current()->task_runner())); | 384 profile_, base::MessageLoop::current()->task_runner())); |
| 385 | 385 |
| 386 if (HotwordServiceFactory::IsHotwordHardwareAvailable() && | 386 if (HotwordServiceFactory::IsAlwaysOnAvailable() && |
| 387 IsHotwordAllowed() && | 387 IsHotwordAllowed() && |
| 388 IsExperimentalHotwordingEnabled()) { | 388 IsExperimentalHotwordingEnabled()) { |
| 389 // Show the hotword notification in 5 seconds if the experimental flag is | 389 // Show the hotword notification in 5 seconds if the experimental flag is |
| 390 // on, or in 30 minutes if not. We need to wait at least a few seconds | 390 // on, or in 30 minutes if not. We need to wait at least a few seconds |
| 391 // for the hotword extension to be installed. | 391 // for the hotword extension to be installed. |
| 392 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 392 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 393 if (command_line->HasSwitch(switches::kEnableExperimentalHotwordHardware)) { | 393 if (command_line->HasSwitch(switches::kEnableExperimentalHotwordHardware)) { |
| 394 base::MessageLoop::current()->PostDelayedTask( | 394 base::MessageLoop::current()->PostDelayedTask( |
| 395 FROM_HERE, | 395 FROM_HERE, |
| 396 base::Bind(&HotwordService::ShowHotwordNotification, | 396 base::Bind(&HotwordService::ShowHotwordNotification, |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 // Do not opt the user in if the preference has not been set. | 679 // Do not opt the user in if the preference has not been set. |
| 680 return | 680 return |
| 681 profile_->GetPrefs()->HasPrefPath(prefs::kHotwordAudioLoggingEnabled) && | 681 profile_->GetPrefs()->HasPrefPath(prefs::kHotwordAudioLoggingEnabled) && |
| 682 profile_->GetPrefs()->GetBoolean(prefs::kHotwordAudioLoggingEnabled); | 682 profile_->GetPrefs()->GetBoolean(prefs::kHotwordAudioLoggingEnabled); |
| 683 } | 683 } |
| 684 | 684 |
| 685 bool HotwordService::IsAlwaysOnEnabled() { | 685 bool HotwordService::IsAlwaysOnEnabled() { |
| 686 return | 686 return |
| 687 profile_->GetPrefs()->HasPrefPath(prefs::kHotwordAlwaysOnSearchEnabled) && | 687 profile_->GetPrefs()->HasPrefPath(prefs::kHotwordAlwaysOnSearchEnabled) && |
| 688 profile_->GetPrefs()->GetBoolean(prefs::kHotwordAlwaysOnSearchEnabled) && | 688 profile_->GetPrefs()->GetBoolean(prefs::kHotwordAlwaysOnSearchEnabled) && |
| 689 HotwordServiceFactory::IsHotwordHardwareAvailable(); | 689 HotwordServiceFactory::IsAlwaysOnAvailable(); |
| 690 } | 690 } |
| 691 | 691 |
| 692 bool HotwordService::IsSometimesOnEnabled() { | 692 bool HotwordService::IsSometimesOnEnabled() { |
| 693 return profile_->GetPrefs()->HasPrefPath(prefs::kHotwordSearchEnabled) && | 693 return profile_->GetPrefs()->HasPrefPath(prefs::kHotwordSearchEnabled) && |
| 694 profile_->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled) && | 694 profile_->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled) && |
| 695 !HotwordServiceFactory::IsHotwordHardwareAvailable(); | 695 !HotwordServiceFactory::IsAlwaysOnAvailable(); |
| 696 } | 696 } |
| 697 | 697 |
| 698 void HotwordService::EnableHotwordExtension( | 698 void HotwordService::EnableHotwordExtension( |
| 699 ExtensionService* extension_service) { | 699 ExtensionService* extension_service) { |
| 700 if (extension_service && !IsExperimentalHotwordingEnabled()) | 700 if (extension_service && !IsExperimentalHotwordingEnabled()) |
| 701 extension_service->EnableExtension(extension_misc::kHotwordExtensionId); | 701 extension_service->EnableExtension(extension_misc::kHotwordExtensionId); |
| 702 } | 702 } |
| 703 | 703 |
| 704 void HotwordService::DisableHotwordExtension( | 704 void HotwordService::DisableHotwordExtension( |
| 705 ExtensionService* extension_service) { | 705 ExtensionService* extension_service) { |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 893 // Only support multiple profiles and profile switching in ChromeOS. | 893 // Only support multiple profiles and profile switching in ChromeOS. |
| 894 if (user_manager::UserManager::IsInitialized()) { | 894 if (user_manager::UserManager::IsInitialized()) { |
| 895 user_manager::User* user = | 895 user_manager::User* user = |
| 896 user_manager::UserManager::Get()->GetActiveUser(); | 896 user_manager::UserManager::Get()->GetActiveUser(); |
| 897 if (user && user->is_profile_created()) | 897 if (user && user->is_profile_created()) |
| 898 return profile_ == ProfileManager::GetActiveUserProfile(); | 898 return profile_ == ProfileManager::GetActiveUserProfile(); |
| 899 } | 899 } |
| 900 #endif | 900 #endif |
| 901 return true; | 901 return true; |
| 902 } | 902 } |
| OLD | NEW |