signin_manager_factory.cc revision 1e9bf3e0803691d0a228da41fc608347b6db4340
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.
4
5#include "chrome/browser/signin/signin_manager_factory.h"
6
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/signin_manager.h"
12#include "chrome/browser/signin/token_service_factory.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"
16
17SigninManagerFactory::SigninManagerFactory()
18    : BrowserContextKeyedServiceFactory(
19        "SigninManager",
20        BrowserContextDependencyManager::GetInstance()) {
21  DependsOn(TokenServiceFactory::GetInstance());
22}
23
24SigninManagerFactory::~SigninManagerFactory() {}
25
26#if defined(OS_CHROMEOS)
27// static
28SigninManagerBase* SigninManagerFactory::GetForProfileIfExists(
29    Profile* profile) {
30  return static_cast<SigninManagerBase*>(
31      GetInstance()->GetServiceForBrowserContext(profile, false));
32}
33
34// static
35SigninManagerBase* SigninManagerFactory::GetForProfile(
36    Profile* profile) {
37  return static_cast<SigninManagerBase*>(
38      GetInstance()->GetServiceForBrowserContext(profile, true));
39}
40
41#else
42// static
43SigninManager* SigninManagerFactory::GetForProfile(Profile* profile) {
44  return static_cast<SigninManager*>(
45      GetInstance()->GetServiceForBrowserContext(profile, true));
46}
47
48// static
49SigninManager* SigninManagerFactory::GetForProfileIfExists(Profile* profile) {
50  return static_cast<SigninManager*>(
51      GetInstance()->GetServiceForBrowserContext(profile, false));
52}
53#endif
54
55// static
56SigninManagerFactory* SigninManagerFactory::GetInstance() {
57  return Singleton<SigninManagerFactory>::get();
58}
59
60void SigninManagerFactory::RegisterProfilePrefs(
61    user_prefs::PrefRegistrySyncable* registry) {
62  registry->RegisterStringPref(
63      prefs::kGoogleServicesLastUsername,
64      std::string(),
65      user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
66  registry->RegisterStringPref(
67      prefs::kGoogleServicesUsername,
68      std::string(),
69      user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
70  registry->RegisterBooleanPref(
71      prefs::kAutologinEnabled,
72      true,
73      user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
74  registry->RegisterBooleanPref(
75      prefs::kReverseAutologinEnabled,
76      true,
77      user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
78  registry->RegisterListPref(prefs::kReverseAutologinRejectedEmailList,
79                             new ListValue,
80                             user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
81  chrome::RegisterLocalAuthPrefs(registry);
82}
83
84// static
85void SigninManagerFactory::RegisterPrefs(PrefRegistrySimple* registry) {
86  registry->RegisterStringPref(prefs::kGoogleServicesUsernamePattern,
87                               std::string());
88}
89
90BrowserContextKeyedService* SigninManagerFactory::BuildServiceInstanceFor(
91    content::BrowserContext* context) const {
92  SigninManagerBase* service = NULL;
93  Profile* profile = static_cast<Profile*>(context);
94#if defined(OS_CHROMEOS)
95  service = new SigninManagerBase();
96#else
97  service = new SigninManager(
98      scoped_ptr<SigninManagerDelegate>(
99          new ChromeSigninManagerDelegate(profile)));
100#endif
101  service->Initialize(profile, g_browser_process->local_state());
102  return service;
103}
104