[Android] Allow multiple --install in bb_device_steps.py.
[chromium-blink-merge.git] / chrome / browser / signin / signin_manager_factory.cc
blob499fbc4a4b1ea13d4bf8555d36a02caac44db8f1
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(
21 "SigninManager",
22 BrowserContextDependencyManager::GetInstance()) {
23 DependsOn(ChromeSigninClientFactory::GetInstance());
24 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance());
25 DependsOn(AccountTrackerServiceFactory::GetInstance());
28 SigninManagerFactory::~SigninManagerFactory() {
31 #if defined(OS_CHROMEOS)
32 // static
33 SigninManagerBase* SigninManagerFactory::GetForProfileIfExists(
34 Profile* profile) {
35 return static_cast<SigninManagerBase*>(
36 GetInstance()->GetServiceForBrowserContext(profile, false));
39 // static
40 SigninManagerBase* SigninManagerFactory::GetForProfile(
41 Profile* profile) {
42 return static_cast<SigninManagerBase*>(
43 GetInstance()->GetServiceForBrowserContext(profile, true));
46 #else
47 // static
48 SigninManager* SigninManagerFactory::GetForProfile(Profile* profile) {
49 return static_cast<SigninManager*>(
50 GetInstance()->GetServiceForBrowserContext(profile, true));
53 // static
54 SigninManager* SigninManagerFactory::GetForProfileIfExists(Profile* profile) {
55 return static_cast<SigninManager*>(
56 GetInstance()->GetServiceForBrowserContext(profile, false));
58 #endif
60 // static
61 SigninManagerFactory* SigninManagerFactory::GetInstance() {
62 return Singleton<SigninManagerFactory>::get();
65 void SigninManagerFactory::RegisterProfilePrefs(
66 user_prefs::PrefRegistrySyncable* registry) {
67 registry->RegisterStringPref(
68 prefs::kGoogleServicesHostedDomain,
69 std::string(),
70 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
71 registry->RegisterStringPref(
72 prefs::kGoogleServicesLastUsername,
73 std::string(),
74 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
75 registry->RegisterStringPref(
76 prefs::kGoogleServicesUserAccountId,
77 std::string(),
78 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
79 registry->RegisterStringPref(
80 prefs::kGoogleServicesUsername,
81 std::string(),
82 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
83 registry->RegisterStringPref(
84 prefs::kGoogleServicesSigninScopedDeviceId,
85 std::string(),
86 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
87 registry->RegisterBooleanPref(
88 prefs::kAutologinEnabled,
89 true,
90 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
91 registry->RegisterBooleanPref(
92 prefs::kReverseAutologinEnabled,
93 true,
94 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
95 registry->RegisterListPref(prefs::kReverseAutologinRejectedEmailList,
96 new base::ListValue,
97 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
98 registry->RegisterInt64Pref(
99 prefs::kSignedInTime,
100 base::Time().ToInternalValue(),
101 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
102 chrome::RegisterLocalAuthPrefs(registry);
105 // static
106 void SigninManagerFactory::RegisterPrefs(PrefRegistrySimple* registry) {
107 registry->RegisterStringPref(prefs::kGoogleServicesUsernamePattern,
108 std::string());
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);
132 #else
133 service = new SigninManager(
134 client, ProfileOAuth2TokenServiceFactory::GetForProfile(profile));
135 #endif
136 service->Initialize(g_browser_process->local_state());
137 FOR_EACH_OBSERVER(Observer, observer_list_, SigninManagerCreated(service));
138 return service;
141 void SigninManagerFactory::BrowserContextShutdown(
142 content::BrowserContext* context) {
143 SigninManagerBase* manager = static_cast<SigninManagerBase*>(
144 GetServiceForBrowserContext(context, false));
145 if (manager)
146 FOR_EACH_OBSERVER(Observer, observer_list_, SigninManagerShutdown(manager));
147 BrowserContextKeyedServiceFactory::BrowserContextShutdown(context);