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