Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / signin / signin_manager_factory.cc
blob00e9a9bc6aec098353fd80c3bb18166c9af59d5e
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 "components/keyed_service/content/browser_context_dependency_manager.h"
16 #include "components/signin/core/browser/signin_manager.h"
18 SigninManagerFactory::SigninManagerFactory()
19 : BrowserContextKeyedServiceFactory(
20 "SigninManager",
21 BrowserContextDependencyManager::GetInstance()) {
22 DependsOn(ChromeSigninClientFactory::GetInstance());
23 DependsOn(GaiaCookieManagerServiceFactory::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 const SigninManagerBase* SigninManagerFactory::GetForProfileIfExists(
40 const Profile* profile) {
41 return static_cast<const SigninManagerBase*>(
42 GetInstance()->GetServiceForBrowserContext(
43 const_cast<Profile*>(profile), false));
46 // static
47 SigninManagerBase* SigninManagerFactory::GetForProfile(
48 Profile* profile) {
49 return static_cast<SigninManagerBase*>(
50 GetInstance()->GetServiceForBrowserContext(profile, true));
53 #else
54 // static
55 SigninManager* SigninManagerFactory::GetForProfile(Profile* profile) {
56 return static_cast<SigninManager*>(
57 GetInstance()->GetServiceForBrowserContext(profile, true));
60 // static
61 SigninManager* SigninManagerFactory::GetForProfileIfExists(Profile* profile) {
62 return static_cast<SigninManager*>(
63 GetInstance()->GetServiceForBrowserContext(profile, false));
66 // static
67 const SigninManager* SigninManagerFactory::GetForProfileIfExists(
68 const Profile* profile) {
69 return static_cast<const SigninManager*>(
70 GetInstance()->GetServiceForBrowserContext(
71 const_cast<Profile*>(profile), false));
73 #endif
75 // static
76 SigninManagerFactory* SigninManagerFactory::GetInstance() {
77 return Singleton<SigninManagerFactory>::get();
80 void SigninManagerFactory::RegisterProfilePrefs(
81 user_prefs::PrefRegistrySyncable* registry) {
82 SigninManagerBase::RegisterProfilePrefs(registry);
83 LocalAuth::RegisterLocalAuthPrefs(registry);
86 // static
87 void SigninManagerFactory::RegisterPrefs(PrefRegistrySimple* registry) {
88 SigninManagerBase::RegisterPrefs(registry);
91 void SigninManagerFactory::AddObserver(Observer* observer) {
92 observer_list_.AddObserver(observer);
95 void SigninManagerFactory::RemoveObserver(Observer* observer) {
96 observer_list_.RemoveObserver(observer);
99 void SigninManagerFactory::NotifyObserversOfSigninManagerCreationForTesting(
100 SigninManagerBase* manager) {
101 FOR_EACH_OBSERVER(Observer, observer_list_, SigninManagerCreated(manager));
104 KeyedService* SigninManagerFactory::BuildServiceInstanceFor(
105 content::BrowserContext* context) const {
106 SigninManagerBase* service = NULL;
107 Profile* profile = static_cast<Profile*>(context);
108 SigninClient* client =
109 ChromeSigninClientFactory::GetInstance()->GetForProfile(profile);
110 #if defined(OS_CHROMEOS)
111 service = new SigninManagerBase(
112 client,
113 AccountTrackerServiceFactory::GetForProfile(profile));
114 #else
115 service = new SigninManager(
116 client,
117 ProfileOAuth2TokenServiceFactory::GetForProfile(profile),
118 AccountTrackerServiceFactory::GetForProfile(profile),
119 GaiaCookieManagerServiceFactory::GetForProfile(profile));
120 #endif
121 service->Initialize(g_browser_process->local_state());
122 FOR_EACH_OBSERVER(Observer, observer_list_, SigninManagerCreated(service));
123 return service;
126 void SigninManagerFactory::BrowserContextShutdown(
127 content::BrowserContext* context) {
128 SigninManagerBase* manager = static_cast<SigninManagerBase*>(
129 GetServiceForBrowserContext(context, false));
130 if (manager)
131 FOR_EACH_OBSERVER(Observer, observer_list_, SigninManagerShutdown(manager));
132 BrowserContextKeyedServiceFactory::BrowserContextShutdown(context);