Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / signin / signin_manager_factory.cc
blobaa5286754b05d0f0c638636206a0764ea27c64b3
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/chrome_signin_client_factory.h"
11 #include "chrome/browser/signin/local_auth.h"
12 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
13 #include "chrome/common/pref_names.h"
14 #include "components/keyed_service/content/browser_context_dependency_manager.h"
15 #include "components/signin/core/browser/signin_manager.h"
16 #include "components/user_prefs/pref_registry_syncable.h"
18 SigninManagerFactory::SigninManagerFactory()
19 : BrowserContextKeyedServiceFactory(
20 "SigninManager",
21 BrowserContextDependencyManager::GetInstance()) {
22 DependsOn(ChromeSigninClientFactory::GetInstance());
23 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance());
26 SigninManagerFactory::~SigninManagerFactory() {
27 #if defined(OS_MACOSX)
28 // Check that the number of remaining observers is as expected. Mac has a
29 // known issue wherein there might be a remaining observer
30 // (UIAppListViewDelegate).
31 int num_observers = 0;
32 if (observer_list_.might_have_observers()) {
33 ObserverListBase<SigninManagerFactory::Observer>::Iterator it(
34 observer_list_);
35 while (it.GetNext()) {
36 num_observers++;
39 DCHECK_LE(num_observers, 1);
40 #endif // defined(OS_MACOSX)
43 #if defined(OS_CHROMEOS)
44 // static
45 SigninManagerBase* SigninManagerFactory::GetForProfileIfExists(
46 Profile* profile) {
47 return static_cast<SigninManagerBase*>(
48 GetInstance()->GetServiceForBrowserContext(profile, false));
51 // static
52 SigninManagerBase* SigninManagerFactory::GetForProfile(
53 Profile* profile) {
54 return static_cast<SigninManagerBase*>(
55 GetInstance()->GetServiceForBrowserContext(profile, true));
58 #else
59 // static
60 SigninManager* SigninManagerFactory::GetForProfile(Profile* profile) {
61 return static_cast<SigninManager*>(
62 GetInstance()->GetServiceForBrowserContext(profile, true));
65 // static
66 SigninManager* SigninManagerFactory::GetForProfileIfExists(Profile* profile) {
67 return static_cast<SigninManager*>(
68 GetInstance()->GetServiceForBrowserContext(profile, false));
70 #endif
72 // static
73 SigninManagerFactory* SigninManagerFactory::GetInstance() {
74 return Singleton<SigninManagerFactory>::get();
77 void SigninManagerFactory::RegisterProfilePrefs(
78 user_prefs::PrefRegistrySyncable* registry) {
79 registry->RegisterStringPref(
80 prefs::kGoogleServicesLastUsername,
81 std::string(),
82 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
83 registry->RegisterStringPref(
84 prefs::kGoogleServicesUserAccountId,
85 std::string(),
86 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
87 registry->RegisterStringPref(
88 prefs::kGoogleServicesUsername,
89 std::string(),
90 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
91 registry->RegisterBooleanPref(
92 prefs::kAutologinEnabled,
93 true,
94 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
95 registry->RegisterBooleanPref(
96 prefs::kReverseAutologinEnabled,
97 true,
98 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
99 registry->RegisterListPref(prefs::kReverseAutologinRejectedEmailList,
100 new base::ListValue,
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);