| 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 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 | 218 |
| 219 // Overridden from NotificationDelegate: | 219 // Overridden from NotificationDelegate: |
| 220 void ButtonClick(int button_index) override { | 220 void ButtonClick(int button_index) override { |
| 221 DCHECK_EQ(0, button_index); | 221 DCHECK_EQ(0, button_index); |
| 222 | 222 |
| 223 // Launch the hotword audio verification app in the right mode. | 223 // Launch the hotword audio verification app in the right mode. |
| 224 HotwordService::LaunchMode launch_mode = | 224 HotwordService::LaunchMode launch_mode = |
| 225 HotwordService::HOTWORD_AND_AUDIO_HISTORY; | 225 HotwordService::HOTWORD_AND_AUDIO_HISTORY; |
| 226 if (profile_->GetPrefs()->GetBoolean( | 226 if (profile_->GetPrefs()->GetBoolean( |
| 227 prefs::kHotwordAudioLoggingEnabled)) { | 227 prefs::kHotwordAudioLoggingEnabled)) { |
| 228 // TODO(rlp): Make sure the Chrome Audio History pref is synced | |
| 229 // to the account-level Audio History setting from footprints. | |
| 230 launch_mode = HotwordService::HOTWORD_ONLY; | 228 launch_mode = HotwordService::HOTWORD_ONLY; |
| 231 } | 229 } |
| 232 | 230 |
| 233 HotwordService* hotword_service = | 231 HotwordService* hotword_service = |
| 234 HotwordServiceFactory::GetForProfile(profile_); | 232 HotwordServiceFactory::GetForProfile(profile_); |
| 235 | 233 |
| 236 if (!hotword_service) | 234 if (!hotword_service) |
| 237 return; | 235 return; |
| 238 | 236 |
| 239 hotword_service->LaunchHotwordAudioVerificationApp(launch_mode); | 237 hotword_service->LaunchHotwordAudioVerificationApp(launch_mode); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 &HotwordService::MaybeReinstallHotwordExtension), | 334 &HotwordService::MaybeReinstallHotwordExtension), |
| 337 weak_factory_.GetWeakPtr())); | 335 weak_factory_.GetWeakPtr())); |
| 338 | 336 |
| 339 // Clear the old user pref because it became unusable. | 337 // Clear the old user pref because it became unusable. |
| 340 // TODO(rlp): Remove this code per crbug.com/358789. | 338 // TODO(rlp): Remove this code per crbug.com/358789. |
| 341 if (profile_->GetPrefs()->HasPrefPath( | 339 if (profile_->GetPrefs()->HasPrefPath( |
| 342 hotword_internal::kHotwordUnusablePrefName)) { | 340 hotword_internal::kHotwordUnusablePrefName)) { |
| 343 profile_->GetPrefs()->ClearPref(hotword_internal::kHotwordUnusablePrefName); | 341 profile_->GetPrefs()->ClearPref(hotword_internal::kHotwordUnusablePrefName); |
| 344 } | 342 } |
| 345 | 343 |
| 346 audio_history_handler_.reset(new HotwordAudioHistoryHandler(profile_)); | 344 SetAudioHistoryHandler(new HotwordAudioHistoryHandler( |
| 345 profile_, base::MessageLoop::current()->task_runner())); |
| 347 | 346 |
| 348 if (HotwordServiceFactory::IsHotwordHardwareAvailable() && | 347 if (HotwordServiceFactory::IsHotwordHardwareAvailable() && |
| 349 IsHotwordAllowed() && | 348 IsHotwordAllowed() && |
| 350 IsExperimentalHotwordingEnabled()) { | 349 IsExperimentalHotwordingEnabled()) { |
| 351 // 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 |
| 352 // on, or in 30 minutes if not. We need to wait at least a few seconds | 351 // on, or in 30 minutes if not. We need to wait at least a few seconds |
| 353 // for the hotword extension to be installed. | 352 // for the hotword extension to be installed. |
| 354 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 353 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 355 if (command_line->HasSwitch(switches::kEnableExperimentalHotwordHardware)) { | 354 if (command_line->HasSwitch(switches::kEnableExperimentalHotwordHardware)) { |
| 356 base::MessageLoop::current()->PostDelayedTask( | 355 base::MessageLoop::current()->PostDelayedTask( |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 734 return training_; | 733 return training_; |
| 735 } | 734 } |
| 736 | 735 |
| 737 HotwordAudioHistoryHandler* HotwordService::GetAudioHistoryHandler() { | 736 HotwordAudioHistoryHandler* HotwordService::GetAudioHistoryHandler() { |
| 738 return audio_history_handler_.get(); | 737 return audio_history_handler_.get(); |
| 739 } | 738 } |
| 740 | 739 |
| 741 void HotwordService::SetAudioHistoryHandler( | 740 void HotwordService::SetAudioHistoryHandler( |
| 742 HotwordAudioHistoryHandler* handler) { | 741 HotwordAudioHistoryHandler* handler) { |
| 743 audio_history_handler_.reset(handler); | 742 audio_history_handler_.reset(handler); |
| 743 audio_history_handler_->UpdateAudioHistoryState(); |
| 744 } | 744 } |
| 745 | 745 |
| 746 void HotwordService::DisableHotwordPreferences() { | 746 void HotwordService::DisableHotwordPreferences() { |
| 747 if (IsSometimesOnEnabled()) { | 747 if (IsSometimesOnEnabled()) { |
| 748 if (profile_->GetPrefs()->HasPrefPath(prefs::kHotwordSearchEnabled)) | 748 if (profile_->GetPrefs()->HasPrefPath(prefs::kHotwordSearchEnabled)) |
| 749 profile_->GetPrefs()->SetBoolean(prefs::kHotwordSearchEnabled, false); | 749 profile_->GetPrefs()->SetBoolean(prefs::kHotwordSearchEnabled, false); |
| 750 } else if (IsAlwaysOnEnabled()) { | 750 } else if (IsAlwaysOnEnabled()) { |
| 751 if (profile_->GetPrefs()->HasPrefPath( | 751 if (profile_->GetPrefs()->HasPrefPath( |
| 752 prefs::kHotwordAlwaysOnSearchEnabled)) { | 752 prefs::kHotwordAlwaysOnSearchEnabled)) { |
| 753 profile_->GetPrefs()->SetBoolean(prefs::kHotwordAlwaysOnSearchEnabled, | 753 profile_->GetPrefs()->SetBoolean(prefs::kHotwordAlwaysOnSearchEnabled, |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 836 // Only support multiple profiles and profile switching in ChromeOS. | 836 // Only support multiple profiles and profile switching in ChromeOS. |
| 837 if (user_manager::UserManager::IsInitialized()) { | 837 if (user_manager::UserManager::IsInitialized()) { |
| 838 user_manager::User* user = | 838 user_manager::User* user = |
| 839 user_manager::UserManager::Get()->GetActiveUser(); | 839 user_manager::UserManager::Get()->GetActiveUser(); |
| 840 if (user && user->is_profile_created()) | 840 if (user && user->is_profile_created()) |
| 841 return profile_ == ProfileManager::GetActiveUserProfile(); | 841 return profile_ == ProfileManager::GetActiveUserProfile(); |
| 842 } | 842 } |
| 843 #endif | 843 #endif |
| 844 return true; | 844 return true; |
| 845 } | 845 } |
| OLD | NEW |