| 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 |  | 
| 22 using content::BrowserContext; | 18 using content::BrowserContext; | 
| 23 using content::BrowserThread; | 19 using content::BrowserThread; | 
| 24 | 20 | 
| 25 // static | 21 // static | 
| 26 HotwordService* HotwordServiceFactory::GetForProfile(BrowserContext* context) { | 22 HotwordService* HotwordServiceFactory::GetForProfile(BrowserContext* context) { | 
| 27   return static_cast<HotwordService*>( | 23   return static_cast<HotwordService*>( | 
| 28       GetInstance()->GetServiceForBrowserContext(context, true)); | 24       GetInstance()->GetServiceForBrowserContext(context, true)); | 
| 29 } | 25 } | 
| 30 | 26 | 
| 31 // static | 27 // static | 
| (...skipping 11 matching lines...) Expand all  Loading... | 
| 43 bool HotwordServiceFactory::IsHotwordAllowed(BrowserContext* context) { | 39 bool HotwordServiceFactory::IsHotwordAllowed(BrowserContext* context) { | 
| 44   HotwordService* hotword_service = GetForProfile(context); | 40   HotwordService* hotword_service = GetForProfile(context); | 
| 45   return hotword_service && hotword_service->IsHotwordAllowed(); | 41   return hotword_service && hotword_service->IsHotwordAllowed(); | 
| 46 } | 42 } | 
| 47 | 43 | 
| 48 // static | 44 // static | 
| 49 bool HotwordServiceFactory::IsAlwaysOnAvailable() { | 45 bool HotwordServiceFactory::IsAlwaysOnAvailable() { | 
| 50 // Temporarily disabling hotword hardware check for M42. Will be | 46 // Temporarily disabling hotword hardware check for M42. Will be | 
| 51 // re-enabled for M43. | 47 // re-enabled for M43. | 
| 52 #if 0 | 48 #if 0 | 
| 53 #if defined(OS_CHROMEOS) | 49   if (HotwordService::IsHotwordHardwareAvailable()) | 
| 54   if (chromeos::CrasAudioHandler::IsInitialized()) { | 50     return true; | 
| 55     chromeos::AudioDeviceList devices; |  | 
| 56     chromeos::CrasAudioHandler::Get()->GetAudioDevices(&devices); |  | 
| 57     for (size_t i = 0; i < devices.size(); ++i) { |  | 
| 58       if (devices[i].type == chromeos::AUDIO_TYPE_AOKR) { |  | 
| 59         DCHECK(devices[i].is_input); |  | 
| 60         return true; |  | 
| 61       } |  | 
| 62     } |  | 
| 63   } |  | 
| 64 #endif |  | 
| 65 #endif  // 0 | 51 #endif  // 0 | 
| 66   base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 52   base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 
| 67   return command_line->HasSwitch(switches::kEnableExperimentalHotwordHardware); | 53   return command_line->HasSwitch(switches::kEnableExperimentalHotwordHardware); | 
| 68 } | 54 } | 
| 69 | 55 | 
| 70 // static | 56 // static | 
| 71 int HotwordServiceFactory::GetCurrentError(BrowserContext* context) { | 57 int HotwordServiceFactory::GetCurrentError(BrowserContext* context) { | 
| 72   HotwordService* hotword_service = GetForProfile(context); | 58   HotwordService* hotword_service = GetForProfile(context); | 
| 73   if (!hotword_service) | 59   if (!hotword_service) | 
| 74     return 0; | 60     return 0; | 
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 137                              user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 123                              user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 
| 138   prefs->RegisterBooleanPref(prefs::kHotwordAlwaysOnNotificationSeen, | 124   prefs->RegisterBooleanPref(prefs::kHotwordAlwaysOnNotificationSeen, | 
| 139                              false, | 125                              false, | 
| 140                              user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 126                              user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 
| 141 } | 127 } | 
| 142 | 128 | 
| 143 KeyedService* HotwordServiceFactory::BuildServiceInstanceFor( | 129 KeyedService* HotwordServiceFactory::BuildServiceInstanceFor( | 
| 144     BrowserContext* context) const { | 130     BrowserContext* context) const { | 
| 145   return new HotwordService(Profile::FromBrowserContext(context)); | 131   return new HotwordService(Profile::FromBrowserContext(context)); | 
| 146 } | 132 } | 
| OLD | NEW | 
|---|