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_factory.h" | 5 #include "chrome/browser/search/hotword_service_factory.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/search/hotword_service.h" | 10 #include "chrome/browser/search/hotword_service.h" |
11 #include "chrome/common/chrome_switches.h" | 11 #include "chrome/common/chrome_switches.h" |
12 #include "chrome/common/pref_names.h" | 12 #include "chrome/common/pref_names.h" |
13 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 13 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
14 #include "components/pref_registry/pref_registry_syncable.h" | 14 #include "components/pref_registry/pref_registry_syncable.h" |
15 #include "content/public/browser/browser_context.h" | 15 #include "content/public/browser/browser_context.h" |
16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
17 | 17 |
| 18 #if defined(OS_CHROMEOS) |
| 19 #include "chromeos/audio/cras_audio_handler.h" |
| 20 #endif |
| 21 |
18 using content::BrowserContext; | 22 using content::BrowserContext; |
19 using content::BrowserThread; | 23 using content::BrowserThread; |
20 | 24 |
21 // static | 25 // static |
22 HotwordService* HotwordServiceFactory::GetForProfile(BrowserContext* context) { | 26 HotwordService* HotwordServiceFactory::GetForProfile(BrowserContext* context) { |
23 return static_cast<HotwordService*>( | 27 return static_cast<HotwordService*>( |
24 GetInstance()->GetServiceForBrowserContext(context, true)); | 28 GetInstance()->GetServiceForBrowserContext(context, true)); |
25 } | 29 } |
26 | 30 |
27 // static | 31 // static |
28 HotwordServiceFactory* HotwordServiceFactory::GetInstance() { | 32 HotwordServiceFactory* HotwordServiceFactory::GetInstance() { |
29 return Singleton<HotwordServiceFactory>::get(); | 33 return Singleton<HotwordServiceFactory>::get(); |
30 } | 34 } |
31 | 35 |
32 // static | 36 // static |
33 bool HotwordServiceFactory::IsServiceAvailable(BrowserContext* context) { | 37 bool HotwordServiceFactory::IsServiceAvailable(BrowserContext* context) { |
34 HotwordService* hotword_service = GetForProfile(context); | 38 HotwordService* hotword_service = GetForProfile(context); |
35 return hotword_service && hotword_service->IsServiceAvailable(); | 39 return hotword_service && hotword_service->IsServiceAvailable(); |
36 } | 40 } |
37 | 41 |
38 // static | 42 // static |
39 bool HotwordServiceFactory::IsHotwordAllowed(BrowserContext* context) { | 43 bool HotwordServiceFactory::IsHotwordAllowed(BrowserContext* context) { |
40 HotwordService* hotword_service = GetForProfile(context); | 44 HotwordService* hotword_service = GetForProfile(context); |
41 return hotword_service && hotword_service->IsHotwordAllowed(); | 45 return hotword_service && hotword_service->IsHotwordAllowed(); |
42 } | 46 } |
43 | 47 |
44 // static | 48 // static |
45 bool HotwordServiceFactory::IsHotwordHardwareAvailable() { | 49 bool HotwordServiceFactory::IsHotwordHardwareAvailable() { |
46 // TODO(rlp, dgreid): return has_hotword_hardware() | 50 #if defined(OS_CHROMEOS) |
47 // Fill in once the hardware has the correct interface implemented. | 51 chromeos::AudioDeviceList devices; |
48 // In the meantime, this function can be used to get other parts moving | 52 chromeos::CrasAudioHandler::Get()->GetAudioDevices(&devices); |
49 // based on a flag. | 53 for (size_t i = 0; i < devices.size(); ++i) { |
| 54 if (devices[i].type == chromeos::AUDIO_TYPE_AOKR) { |
| 55 DCHECK(devices[i].is_input); |
| 56 return true; |
| 57 } |
| 58 } |
| 59 #endif |
50 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 60 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
51 return command_line->HasSwitch(switches::kEnableExperimentalHotwordHardware); | 61 return command_line->HasSwitch(switches::kEnableExperimentalHotwordHardware); |
52 } | 62 } |
53 | 63 |
54 // static | 64 // static |
55 int HotwordServiceFactory::GetCurrentError(BrowserContext* context) { | 65 int HotwordServiceFactory::GetCurrentError(BrowserContext* context) { |
56 HotwordService* hotword_service = GetForProfile(context); | 66 HotwordService* hotword_service = GetForProfile(context); |
57 if (!hotword_service) | 67 if (!hotword_service) |
58 return 0; | 68 return 0; |
59 return hotword_service->error_message(); | 69 return hotword_service->error_message(); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 137 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
128 prefs->RegisterBooleanPref(prefs::kHotwordAlwaysOnNotificationSeen, | 138 prefs->RegisterBooleanPref(prefs::kHotwordAlwaysOnNotificationSeen, |
129 false, | 139 false, |
130 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 140 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
131 } | 141 } |
132 | 142 |
133 KeyedService* HotwordServiceFactory::BuildServiceInstanceFor( | 143 KeyedService* HotwordServiceFactory::BuildServiceInstanceFor( |
134 BrowserContext* context) const { | 144 BrowserContext* context) const { |
135 return new HotwordService(Profile::FromBrowserContext(context)); | 145 return new HotwordService(Profile::FromBrowserContext(context)); |
136 } | 146 } |
OLD | NEW |