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/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "chrome/browser/profiles/incognito_helpers.h" | |
9 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/search/hotword_service.h" | 9 #include "chrome/browser/search/hotword_service.h" |
11 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
12 #include "components/browser_context_keyed_service/browser_context_dependency_ma
nager.h" | 11 #include "components/browser_context_keyed_service/browser_context_dependency_ma
nager.h" |
13 #include "components/user_prefs/pref_registry_syncable.h" | 12 #include "components/user_prefs/pref_registry_syncable.h" |
| 13 #include "content/public/browser/browser_context.h" |
| 14 |
| 15 using content::BrowserContext; |
14 | 16 |
15 // static | 17 // static |
16 HotwordService* HotwordServiceFactory::GetForProfile(Profile* profile) { | 18 HotwordService* HotwordServiceFactory::GetForProfile(BrowserContext* context) { |
17 return static_cast<HotwordService*>( | 19 return static_cast<HotwordService*>( |
18 GetInstance()->GetServiceForBrowserContext(profile, true)); | 20 GetInstance()->GetServiceForBrowserContext(context, true)); |
19 } | 21 } |
20 | 22 |
21 // static | 23 // static |
22 HotwordServiceFactory* HotwordServiceFactory::GetInstance() { | 24 HotwordServiceFactory* HotwordServiceFactory::GetInstance() { |
23 return Singleton<HotwordServiceFactory>::get(); | 25 return Singleton<HotwordServiceFactory>::get(); |
24 } | 26 } |
25 | 27 |
26 // static | 28 // static |
27 bool HotwordServiceFactory::ShouldShowOptInPopup(Profile* profile) { | 29 bool HotwordServiceFactory::ShouldShowOptInPopup(BrowserContext* context) { |
28 HotwordService* hotword_service = GetForProfile(profile); | 30 HotwordService* hotword_service = GetForProfile(context); |
29 return hotword_service && hotword_service->ShouldShowOptInPopup(); | 31 return hotword_service && hotword_service->ShouldShowOptInPopup(); |
30 } | 32 } |
31 | 33 |
32 // static | 34 // static |
33 bool HotwordServiceFactory::IsServiceAvailable(Profile* profile) { | 35 bool HotwordServiceFactory::IsServiceAvailable(BrowserContext* context) { |
34 HotwordService* hotword_service = GetForProfile(profile); | 36 HotwordService* hotword_service = GetForProfile(context); |
35 return hotword_service && hotword_service->IsServiceAvailable(); | 37 return hotword_service && hotword_service->IsServiceAvailable(); |
36 } | 38 } |
37 | 39 |
38 // static | 40 // static |
39 bool HotwordServiceFactory::IsHotwordAllowed(Profile* profile) { | 41 bool HotwordServiceFactory::IsHotwordAllowed(BrowserContext* context) { |
40 HotwordService* hotword_service = GetForProfile(profile); | 42 HotwordService* hotword_service = GetForProfile(context); |
41 return hotword_service && hotword_service->IsHotwordAllowed(); | 43 return hotword_service && hotword_service->IsHotwordAllowed(); |
42 } | 44 } |
43 | 45 |
44 HotwordServiceFactory::HotwordServiceFactory() | 46 HotwordServiceFactory::HotwordServiceFactory() |
45 : BrowserContextKeyedServiceFactory( | 47 : BrowserContextKeyedServiceFactory( |
46 "HotwordService", | 48 "HotwordService", |
47 BrowserContextDependencyManager::GetInstance()) { | 49 BrowserContextDependencyManager::GetInstance()) { |
48 // No dependencies. | 50 // No dependencies. |
49 } | 51 } |
50 | 52 |
51 HotwordServiceFactory::~HotwordServiceFactory() { | 53 HotwordServiceFactory::~HotwordServiceFactory() { |
52 } | 54 } |
53 | 55 |
54 void HotwordServiceFactory::RegisterProfilePrefs( | 56 void HotwordServiceFactory::RegisterProfilePrefs( |
55 user_prefs::PrefRegistrySyncable* prefs) { | 57 user_prefs::PrefRegistrySyncable* prefs) { |
56 prefs->RegisterBooleanPref(prefs::kHotwordSearchEnabled, | 58 prefs->RegisterBooleanPref(prefs::kHotwordSearchEnabled, |
57 false, | 59 false, |
58 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | 60 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
59 prefs->RegisterIntegerPref(prefs::kHotwordOptInPopupTimesShown, | 61 prefs->RegisterIntegerPref(prefs::kHotwordOptInPopupTimesShown, |
60 0, | 62 0, |
61 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 63 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
62 } | 64 } |
63 | 65 |
64 BrowserContextKeyedService* HotwordServiceFactory::BuildServiceInstanceFor( | 66 BrowserContextKeyedService* HotwordServiceFactory::BuildServiceInstanceFor( |
65 content::BrowserContext* profile) const { | 67 BrowserContext* context) const { |
66 return new HotwordService(static_cast<Profile*>(profile)); | 68 return new HotwordService(Profile::FromBrowserContext(context)); |
67 } | 69 } |
OLD | NEW |