[Media Router] Add integration tests and e2e tests for media router and presentation...
[chromium-blink-merge.git] / chrome / browser / signin / signin_manager_factory.cc
blob9b5406fefd9c712e359a081405dd66f693c7a47b
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/gaia_cookie_manager_service_factory.h"
13 #include "chrome/browser/signin/local_auth.h"
14 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
15 #include "chrome/common/pref_names.h"
16 #include "components/keyed_service/content/browser_context_dependency_manager.h"
17 #include "components/pref_registry/pref_registry_syncable.h"
18 #include "components/signin/core/browser/signin_manager.h"
20 SigninManagerFactory::SigninManagerFactory()
21 : BrowserContextKeyedServiceFactory(
22 "SigninManager",
23 BrowserContextDependencyManager::GetInstance()) {
24 DependsOn(ChromeSigninClientFactory::GetInstance());
25 DependsOn(GaiaCookieManagerServiceFactory::GetInstance());
26 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance());
27 DependsOn(AccountTrackerServiceFactory::GetInstance());
30 SigninManagerFactory::~SigninManagerFactory() {
33 #if defined(OS_CHROMEOS)
34 // static
35 SigninManagerBase* SigninManagerFactory::GetForProfileIfExists(
36 Profile* profile) {
37 return static_cast<SigninManagerBase*>(
38 GetInstance()->GetServiceForBrowserContext(profile, false));
41 const SigninManagerBase* SigninManagerFactory::GetForProfileIfExists(
42 const Profile* profile) {
43 return static_cast<const SigninManagerBase*>(
44 GetInstance()->GetServiceForBrowserContext(
45 const_cast<Profile*>(profile), false));
48 // static
49 SigninManagerBase* SigninManagerFactory::GetForProfile(
50 Profile* profile) {
51 return static_cast<SigninManagerBase*>(
52 GetInstance()->GetServiceForBrowserContext(profile, true));
55 #else
56 // static
57 SigninManager* SigninManagerFactory::GetForProfile(Profile* profile) {
58 return static_cast<SigninManager*>(
59 GetInstance()->GetServiceForBrowserContext(profile, true));
62 // static
63 SigninManager* SigninManagerFactory::GetForProfileIfExists(Profile* profile) {
64 return static_cast<SigninManager*>(
65 GetInstance()->GetServiceForBrowserContext(profile, false));
68 // static
69 const SigninManager* SigninManagerFactory::GetForProfileIfExists(
70 const Profile* profile) {
71 return static_cast<const SigninManager*>(
72 GetInstance()->GetServiceForBrowserContext(
73 const_cast<Profile*>(profile), false));
75 #endif
77 // static
78 SigninManagerFactory* SigninManagerFactory::GetInstance() {
79 return Singleton<SigninManagerFactory>::get();
82 void SigninManagerFactory::RegisterProfilePrefs(
83 user_prefs::PrefRegistrySyncable* registry) {
84 registry->RegisterStringPref(prefs::kGoogleServicesHostedDomain,
85 std::string());
86 registry->RegisterStringPref(prefs::kGoogleServicesLastUsername,
87 std::string());
88 registry->RegisterInt64Pref(
89 prefs::kGoogleServicesRefreshTokenAnnotateScheduledTime,
90 base::Time().ToInternalValue());
91 registry->RegisterStringPref(prefs::kGoogleServicesSigninScopedDeviceId,
92 std::string());
93 registry->RegisterStringPref(prefs::kGoogleServicesAccountId, std::string());
94 registry->RegisterStringPref(prefs::kGoogleServicesUserAccountId,
95 std::string());
96 registry->RegisterBooleanPref(prefs::kAutologinEnabled, true);
97 registry->RegisterBooleanPref(prefs::kReverseAutologinEnabled, true);
98 registry->RegisterListPref(prefs::kReverseAutologinRejectedEmailList,
99 new base::ListValue);
100 registry->RegisterInt64Pref(prefs::kSignedInTime,
101 base::Time().ToInternalValue());
103 LocalAuth::RegisterLocalAuthPrefs(registry);
105 // Deprecated prefs: will be removed in a future release.
106 registry->RegisterStringPref(prefs::kGoogleServicesUsername, std::string());
109 // static
110 void SigninManagerFactory::RegisterPrefs(PrefRegistrySimple* registry) {
111 registry->RegisterStringPref(prefs::kGoogleServicesUsernamePattern,
112 std::string());
115 void SigninManagerFactory::AddObserver(Observer* observer) {
116 observer_list_.AddObserver(observer);
119 void SigninManagerFactory::RemoveObserver(Observer* observer) {
120 observer_list_.RemoveObserver(observer);
123 void SigninManagerFactory::NotifyObserversOfSigninManagerCreationForTesting(
124 SigninManagerBase* manager) {
125 FOR_EACH_OBSERVER(Observer, observer_list_, SigninManagerCreated(manager));
128 KeyedService* SigninManagerFactory::BuildServiceInstanceFor(
129 content::BrowserContext* context) const {
130 SigninManagerBase* service = NULL;
131 Profile* profile = static_cast<Profile*>(context);
132 SigninClient* client =
133 ChromeSigninClientFactory::GetInstance()->GetForProfile(profile);
134 #if defined(OS_CHROMEOS)
135 service = new SigninManagerBase(
136 client,
137 AccountTrackerServiceFactory::GetForProfile(profile));
138 #else
139 service = new SigninManager(
140 client,
141 ProfileOAuth2TokenServiceFactory::GetForProfile(profile),
142 AccountTrackerServiceFactory::GetForProfile(profile),
143 GaiaCookieManagerServiceFactory::GetForProfile(profile));
144 #endif
145 service->Initialize(g_browser_process->local_state());
146 FOR_EACH_OBSERVER(Observer, observer_list_, SigninManagerCreated(service));
147 return service;
150 void SigninManagerFactory::BrowserContextShutdown(
151 content::BrowserContext* context) {
152 SigninManagerBase* manager = static_cast<SigninManagerBase*>(
153 GetServiceForBrowserContext(context, false));
154 if (manager)
155 FOR_EACH_OBSERVER(Observer, observer_list_, SigninManagerShutdown(manager));
156 BrowserContextKeyedServiceFactory::BrowserContextShutdown(context);