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/signin/chrome_signin_manager_delegate.h"
10 #include "chrome/browser/signin/local_auth.h"
11 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
12 #include "chrome/browser/signin/signin_manager.h"
13 #include "chrome/common/pref_names.h"
14 #include "components/browser_context_keyed_service/browser_context_dependency_manager.h"
15 #include "components/user_prefs/pref_registry_syncable.h"
17 SigninManagerFactory::SigninManagerFactory()
18 : BrowserContextKeyedServiceFactory(
20 BrowserContextDependencyManager::GetInstance()) {
21 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance());
24 SigninManagerFactory::~SigninManagerFactory() {}
26 #if defined(OS_CHROMEOS)
28 SigninManagerBase
* SigninManagerFactory::GetForProfileIfExists(
30 return static_cast<SigninManagerBase
*>(
31 GetInstance()->GetServiceForBrowserContext(profile
, false));
35 SigninManagerBase
* SigninManagerFactory::GetForProfile(
37 return static_cast<SigninManagerBase
*>(
38 GetInstance()->GetServiceForBrowserContext(profile
, true));
43 SigninManager
* SigninManagerFactory::GetForProfile(Profile
* profile
) {
44 return static_cast<SigninManager
*>(
45 GetInstance()->GetServiceForBrowserContext(profile
, true));
49 SigninManager
* SigninManagerFactory::GetForProfileIfExists(Profile
* profile
) {
50 return static_cast<SigninManager
*>(
51 GetInstance()->GetServiceForBrowserContext(profile
, false));
56 SigninManagerFactory
* SigninManagerFactory::GetInstance() {
57 return Singleton
<SigninManagerFactory
>::get();
60 void SigninManagerFactory::RegisterProfilePrefs(
61 user_prefs::PrefRegistrySyncable
* registry
) {
62 registry
->RegisterStringPref(
63 prefs::kGoogleServicesLastUsername
,
65 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
66 registry
->RegisterStringPref(
67 prefs::kGoogleServicesUserAccountId
,
69 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
70 registry
->RegisterStringPref(
71 prefs::kGoogleServicesUsername
,
73 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
74 registry
->RegisterBooleanPref(
75 prefs::kAutologinEnabled
,
77 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
78 registry
->RegisterBooleanPref(
79 prefs::kReverseAutologinEnabled
,
81 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
82 registry
->RegisterListPref(prefs::kReverseAutologinRejectedEmailList
,
84 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
85 chrome::RegisterLocalAuthPrefs(registry
);
89 void SigninManagerFactory::RegisterPrefs(PrefRegistrySimple
* registry
) {
90 registry
->RegisterStringPref(prefs::kGoogleServicesUsernamePattern
,
94 BrowserContextKeyedService
* SigninManagerFactory::BuildServiceInstanceFor(
95 content::BrowserContext
* context
) const {
96 SigninManagerBase
* service
= NULL
;
97 Profile
* profile
= static_cast<Profile
*>(context
);
98 #if defined(OS_CHROMEOS)
99 service
= new SigninManagerBase();
101 service
= new SigninManager(
102 scoped_ptr
<SigninManagerDelegate
>(
103 new ChromeSigninManagerDelegate(profile
)));
105 service
->Initialize(profile
, g_browser_process
->local_state());