OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 "ios/chrome/browser/signin/oauth2_token_service_factory.h" |
| 6 |
| 7 #include "base/memory/singleton.h" |
| 8 #include "components/keyed_service/ios/browser_state_dependency_manager.h" |
| 9 #include "components/pref_registry/pref_registry_syncable.h" |
| 10 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 11 #include "components/signin/core/common/signin_pref_names.h" |
| 12 #include "components/signin/ios/browser/profile_oauth2_token_service_ios_delegat
e.h" |
| 13 #include "ios/chrome/browser/signin/signin_client_factory.h" |
| 14 #include "ios/chrome/browser/signin/signin_error_controller_factory.h" |
| 15 #include "ios/public/provider/chrome/browser/browser_state/chrome_browser_state.
h" |
| 16 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" |
| 17 |
| 18 OAuth2TokenServiceFactory::OAuth2TokenServiceFactory() |
| 19 : BrowserStateKeyedServiceFactory( |
| 20 "ProfileOAuth2TokenService", |
| 21 BrowserStateDependencyManager::GetInstance()) { |
| 22 DependsOn(SigninClientFactory::GetInstance()); |
| 23 DependsOn(ios::SigninErrorControllerFactory::GetInstance()); |
| 24 } |
| 25 |
| 26 OAuth2TokenServiceFactory::~OAuth2TokenServiceFactory() {} |
| 27 |
| 28 ProfileOAuth2TokenService* OAuth2TokenServiceFactory::GetForBrowserState( |
| 29 ios::ChromeBrowserState* browser_state) { |
| 30 return static_cast<ProfileOAuth2TokenService*>( |
| 31 GetInstance()->GetServiceForBrowserState(browser_state, true)); |
| 32 } |
| 33 |
| 34 // static |
| 35 OAuth2TokenServiceFactory* OAuth2TokenServiceFactory::GetInstance() { |
| 36 return Singleton<OAuth2TokenServiceFactory>::get(); |
| 37 } |
| 38 |
| 39 void OAuth2TokenServiceFactory::RegisterBrowserStatePrefs( |
| 40 user_prefs::PrefRegistrySyncable* registry) { |
| 41 registry->RegisterBooleanPref(prefs::kTokenServiceExcludeAllSecondaryAccounts, |
| 42 false); |
| 43 registry->RegisterListPref(prefs::kTokenServiceExcludedSecondaryAccounts); |
| 44 } |
| 45 |
| 46 scoped_ptr<KeyedService> OAuth2TokenServiceFactory::BuildServiceInstanceFor( |
| 47 web::BrowserState* context) const { |
| 48 ios::ChromeBrowserState* chrome_browser_state = |
| 49 ios::ChromeBrowserState::FromBrowserState(context); |
| 50 ProfileOAuth2TokenServiceIOSDelegate* delegate = |
| 51 new ProfileOAuth2TokenServiceIOSDelegate( |
| 52 SigninClientFactory::GetForBrowserState(chrome_browser_state), |
| 53 ios::GetChromeBrowserProvider() |
| 54 ->GetProfileOAuth2TokenServiceIOSProvider(), |
| 55 ios::SigninErrorControllerFactory::GetForBrowserState( |
| 56 chrome_browser_state)); |
| 57 return make_scoped_ptr(new ProfileOAuth2TokenService(delegate)); |
| 58 } |
OLD | NEW |