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.
5 #include "ios/chrome/browser/signin/oauth2_token_service_factory.h"
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_delegate.h"
13 #include "ios/chrome/browser/signin/account_tracker_service_factory.h"
14 #include "ios/chrome/browser/signin/signin_client_factory.h"
15 #include "ios/chrome/browser/signin/signin_error_controller_factory.h"
16 #include "ios/public/provider/chrome/browser/browser_state/chrome_browser_state.h"
17 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
19 OAuth2TokenServiceFactory::OAuth2TokenServiceFactory()
20 : BrowserStateKeyedServiceFactory(
21 "ProfileOAuth2TokenService",
22 BrowserStateDependencyManager::GetInstance()) {
23 DependsOn(ios::AccountTrackerServiceFactory::GetInstance());
24 DependsOn(SigninClientFactory::GetInstance());
25 DependsOn(ios::SigninErrorControllerFactory::GetInstance());
28 OAuth2TokenServiceFactory::~OAuth2TokenServiceFactory() {}
30 ProfileOAuth2TokenService
* OAuth2TokenServiceFactory::GetForBrowserState(
31 ios::ChromeBrowserState
* browser_state
) {
32 return static_cast<ProfileOAuth2TokenService
*>(
33 GetInstance()->GetServiceForBrowserState(browser_state
, true));
37 OAuth2TokenServiceFactory
* OAuth2TokenServiceFactory::GetInstance() {
38 return base::Singleton
<OAuth2TokenServiceFactory
>::get();
41 void OAuth2TokenServiceFactory::RegisterBrowserStatePrefs(
42 user_prefs::PrefRegistrySyncable
* registry
) {
43 registry
->RegisterBooleanPref(prefs::kTokenServiceExcludeAllSecondaryAccounts
,
45 registry
->RegisterListPref(prefs::kTokenServiceExcludedSecondaryAccounts
);
48 scoped_ptr
<KeyedService
> OAuth2TokenServiceFactory::BuildServiceInstanceFor(
49 web::BrowserState
* context
) const {
50 ios::ChromeBrowserState
* chrome_browser_state
=
51 ios::ChromeBrowserState::FromBrowserState(context
);
52 ProfileOAuth2TokenServiceIOSDelegate
* delegate
=
53 new ProfileOAuth2TokenServiceIOSDelegate(
54 SigninClientFactory::GetForBrowserState(chrome_browser_state
),
55 ios::GetChromeBrowserProvider()
56 ->GetProfileOAuth2TokenServiceIOSProvider(),
57 ios::AccountTrackerServiceFactory::GetForBrowserState(
58 chrome_browser_state
),
59 ios::SigninErrorControllerFactory::GetForBrowserState(
60 chrome_browser_state
));
61 return make_scoped_ptr(new ProfileOAuth2TokenService(delegate
));