signin_manager_factory.cc revision 90dce4d38c5ff5333bea97d859d4e484e27edf0c
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/signin_manager.h" 11#include "chrome/browser/signin/token_service_factory.h" 12#include "chrome/browser/ui/global_error/global_error_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 DependsOn(GlobalErrorServiceFactory::GetInstance()); 23} 24 25SigninManagerFactory::~SigninManagerFactory() {} 26 27#if defined(OS_CHROMEOS) 28// static 29SigninManagerBase* SigninManagerFactory::GetForProfileIfExists( 30 Profile* profile) { 31 return static_cast<SigninManagerBase*>( 32 GetInstance()->GetServiceForBrowserContext(profile, false)); 33} 34 35// static 36SigninManagerBase* SigninManagerFactory::GetForProfile( 37 Profile* profile) { 38 return static_cast<SigninManagerBase*>( 39 GetInstance()->GetServiceForBrowserContext(profile, true)); 40} 41 42#else 43// static 44SigninManager* SigninManagerFactory::GetForProfile(Profile* profile) { 45 return static_cast<SigninManager*>( 46 GetInstance()->GetServiceForBrowserContext(profile, true)); 47} 48 49// static 50SigninManager* SigninManagerFactory::GetForProfileIfExists(Profile* profile) { 51 return static_cast<SigninManager*>( 52 GetInstance()->GetServiceForBrowserContext(profile, false)); 53} 54#endif 55 56// static 57SigninManagerFactory* SigninManagerFactory::GetInstance() { 58 return Singleton<SigninManagerFactory>::get(); 59} 60 61void SigninManagerFactory::RegisterUserPrefs( 62 user_prefs::PrefRegistrySyncable* registry) { 63 registry->RegisterStringPref( 64 prefs::kGoogleServicesLastUsername, 65 std::string(), 66 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 67 registry->RegisterStringPref( 68 prefs::kGoogleServicesUsername, 69 std::string(), 70 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 71 registry->RegisterBooleanPref( 72 prefs::kAutologinEnabled, 73 true, 74 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 75 registry->RegisterBooleanPref( 76 prefs::kReverseAutologinEnabled, 77 true, 78 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 79 registry->RegisterListPref(prefs::kReverseAutologinRejectedEmailList, 80 new ListValue, 81 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 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