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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 #include "content/public/common/webplugininfo.h" | 42 #include "content/public/common/webplugininfo.h" |
43 #include "extensions/browser/extension_system.h" | 43 #include "extensions/browser/extension_system.h" |
44 #include "extensions/browser/uninstall_reason.h" | 44 #include "extensions/browser/uninstall_reason.h" |
45 #include "extensions/common/constants.h" | 45 #include "extensions/common/constants.h" |
46 #include "extensions/common/extension.h" | 46 #include "extensions/common/extension.h" |
47 #include "extensions/common/one_shot_event.h" | 47 #include "extensions/common/one_shot_event.h" |
48 #include "grit/theme_resources.h" | 48 #include "grit/theme_resources.h" |
49 #include "ui/base/l10n/l10n_util.h" | 49 #include "ui/base/l10n/l10n_util.h" |
50 #include "ui/base/resource/resource_bundle.h" | 50 #include "ui/base/resource/resource_bundle.h" |
51 | 51 |
| 52 #if defined(OS_CHROMEOS) |
| 53 #include "chromeos/audio/cras_audio_handler.h" |
| 54 #endif |
| 55 |
52 using extensions::BrowserContextKeyedAPIFactory; | 56 using extensions::BrowserContextKeyedAPIFactory; |
53 using extensions::HotwordPrivateEventService; | 57 using extensions::HotwordPrivateEventService; |
54 | 58 |
55 namespace { | 59 namespace { |
56 | 60 |
57 // Allowed languages for hotwording. | 61 // Allowed languages for hotwording. |
58 static const char* kSupportedLocales[] = { | 62 static const char* kSupportedLocales[] = { |
59 "en", | 63 "en", |
60 "de", | 64 "de", |
61 "fr", | 65 "fr", |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 #endif | 304 #endif |
301 | 305 |
302 HotwordService::HotwordService(Profile* profile) | 306 HotwordService::HotwordService(Profile* profile) |
303 : profile_(profile), | 307 : profile_(profile), |
304 extension_registry_observer_(this), | 308 extension_registry_observer_(this), |
305 client_(NULL), | 309 client_(NULL), |
306 error_message_(0), | 310 error_message_(0), |
307 reinstall_pending_(false), | 311 reinstall_pending_(false), |
308 training_(false), | 312 training_(false), |
309 weak_factory_(this) { | 313 weak_factory_(this) { |
| 314 #if defined(OS_CHROMEOS) |
| 315 // Tests on chromeos need to have the handler initialized. |
| 316 if (profile_->AsTestingProfile() && |
| 317 !chromeos::CrasAudioHandler::IsInitialized()) |
| 318 chromeos::CrasAudioHandler::InitializeForTesting(); |
| 319 #endif |
| 320 |
310 extension_registry_observer_.Add(extensions::ExtensionRegistry::Get(profile)); | 321 extension_registry_observer_.Add(extensions::ExtensionRegistry::Get(profile)); |
311 if (IsExperimentalHotwordingEnabled()) { | 322 if (IsExperimentalHotwordingEnabled()) { |
312 // Disable the old extension so it doesn't interfere with the new stuff. | 323 // Disable the old extension so it doesn't interfere with the new stuff. |
313 DisableHotwordExtension(GetExtensionService(profile_)); | 324 DisableHotwordExtension(GetExtensionService(profile_)); |
314 } else { | 325 } else { |
315 if (!profile_->GetPrefs()->HasPrefPath(prefs::kHotwordSearchEnabled) && | 326 if (!profile_->GetPrefs()->HasPrefPath(prefs::kHotwordSearchEnabled) && |
316 IsHotwordAllowed()) { | 327 IsHotwordAllowed()) { |
317 // If the preference has not been set the hotword extension should | 328 // If the preference has not been set the hotword extension should |
318 // not be running. However, this should only be done if auto-install | 329 // not be running. However, this should only be done if auto-install |
319 // is enabled which is gated through the IsHotwordAllowed check. | 330 // is enabled which is gated through the IsHotwordAllowed check. |
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
827 HotwordPrivateEventService* event_service = | 838 HotwordPrivateEventService* event_service = |
828 BrowserContextKeyedAPIFactory<HotwordPrivateEventService>::Get(profile_); | 839 BrowserContextKeyedAPIFactory<HotwordPrivateEventService>::Get(profile_); |
829 // "enabled" isn't being changed, but piggy-back off the notification anyway. | 840 // "enabled" isn't being changed, but piggy-back off the notification anyway. |
830 if (event_service) | 841 if (event_service) |
831 event_service->OnEnabledChanged(prefs::kHotwordSearchEnabled); | 842 event_service->OnEnabledChanged(prefs::kHotwordSearchEnabled); |
832 } | 843 } |
833 | 844 |
834 bool HotwordService::UserIsActive() { | 845 bool HotwordService::UserIsActive() { |
835 return profile_ == ProfileManager::GetActiveUserProfile(); | 846 return profile_ == ProfileManager::GetActiveUserProfile(); |
836 } | 847 } |
OLD | NEW |