1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/signin/signin_manager_factory.h"
7 #include "base/prefs/pref_registry_simple.h"
8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/signin/account_tracker_service_factory.h"
11 #include "chrome/browser/signin/chrome_signin_client_factory.h"
12 #include "chrome/browser/signin/local_auth.h"
13 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
14 #include "chrome/common/pref_names.h"
15 #include "components/keyed_service/content/browser_context_dependency_manager.h"
16 #include "components/pref_registry/pref_registry_syncable.h"
17 #include "components/signin/core/browser/signin_manager.h"
19 SigninManagerFactory::SigninManagerFactory()
20 : BrowserContextKeyedServiceFactory(
22 BrowserContextDependencyManager::GetInstance()) {
23 DependsOn(ChromeSigninClientFactory::GetInstance());
24 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance());
25 DependsOn(AccountTrackerServiceFactory::GetInstance());
28 SigninManagerFactory::~SigninManagerFactory() {
31 #if defined(OS_CHROMEOS)
33 SigninManagerBase
* SigninManagerFactory::GetForProfileIfExists(
35 return static_cast<SigninManagerBase
*>(
36 GetInstance()->GetServiceForBrowserContext(profile
, false));
40 SigninManagerBase
* SigninManagerFactory::GetForProfile(
42 return static_cast<SigninManagerBase
*>(
43 GetInstance()->GetServiceForBrowserContext(profile
, true));
48 SigninManager
* SigninManagerFactory::GetForProfile(Profile
* profile
) {
49 return static_cast<SigninManager
*>(
50 GetInstance()->GetServiceForBrowserContext(profile
, true));
54 SigninManager
* SigninManagerFactory::GetForProfileIfExists(Profile
* profile
) {
55 return static_cast<SigninManager
*>(
56 GetInstance()->GetServiceForBrowserContext(profile
, false));
61 SigninManagerFactory
* SigninManagerFactory::GetInstance() {
62 return Singleton
<SigninManagerFactory
>::get();
65 void SigninManagerFactory::RegisterProfilePrefs(
66 user_prefs::PrefRegistrySyncable
* registry
) {
67 registry
->RegisterStringPref(
68 prefs::kGoogleServicesHostedDomain
,
70 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
71 registry
->RegisterStringPref(
72 prefs::kGoogleServicesLastUsername
,
74 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
75 registry
->RegisterStringPref(
76 prefs::kGoogleServicesUserAccountId
,
78 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
79 registry
->RegisterStringPref(
80 prefs::kGoogleServicesUsername
,
82 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
83 registry
->RegisterStringPref(
84 prefs::kGoogleServicesSigninScopedDeviceId
,
86 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
87 registry
->RegisterBooleanPref(
88 prefs::kAutologinEnabled
,
90 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
91 registry
->RegisterBooleanPref(
92 prefs::kReverseAutologinEnabled
,
94 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
95 registry
->RegisterListPref(prefs::kReverseAutologinRejectedEmailList
,
97 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
98 registry
->RegisterInt64Pref(
100 base::Time().ToInternalValue(),
101 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
102 chrome::RegisterLocalAuthPrefs(registry
);
106 void SigninManagerFactory::RegisterPrefs(PrefRegistrySimple
* registry
) {
107 registry
->RegisterStringPref(prefs::kGoogleServicesUsernamePattern
,
111 void SigninManagerFactory::AddObserver(Observer
* observer
) {
112 observer_list_
.AddObserver(observer
);
115 void SigninManagerFactory::RemoveObserver(Observer
* observer
) {
116 observer_list_
.RemoveObserver(observer
);
119 void SigninManagerFactory::NotifyObserversOfSigninManagerCreationForTesting(
120 SigninManagerBase
* manager
) {
121 FOR_EACH_OBSERVER(Observer
, observer_list_
, SigninManagerCreated(manager
));
124 KeyedService
* SigninManagerFactory::BuildServiceInstanceFor(
125 content::BrowserContext
* context
) const {
126 SigninManagerBase
* service
= NULL
;
127 Profile
* profile
= static_cast<Profile
*>(context
);
128 SigninClient
* client
=
129 ChromeSigninClientFactory::GetInstance()->GetForProfile(profile
);
130 #if defined(OS_CHROMEOS)
131 service
= new SigninManagerBase(client
);
133 service
= new SigninManager(
134 client
, ProfileOAuth2TokenServiceFactory::GetForProfile(profile
));
136 service
->Initialize(g_browser_process
->local_state());
137 FOR_EACH_OBSERVER(Observer
, observer_list_
, SigninManagerCreated(service
));
141 void SigninManagerFactory::BrowserContextShutdown(
142 content::BrowserContext
* context
) {
143 SigninManagerBase
* manager
= static_cast<SigninManagerBase
*>(
144 GetServiceForBrowserContext(context
, false));
146 FOR_EACH_OBSERVER(Observer
, observer_list_
, SigninManagerShutdown(manager
));
147 BrowserContextKeyedServiceFactory::BrowserContextShutdown(context
);