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.
5 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
7 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/signin/account_tracker_service_factory.h"
9 #include "chrome/browser/signin/chrome_signin_client_factory.h"
10 #include "chrome/browser/signin/signin_error_controller_factory.h"
11 #include "chrome/browser/web_data_service_factory.h"
12 #include "components/keyed_service/content/browser_context_dependency_manager.h"
13 #include "components/signin/core/browser/profile_oauth2_token_service.h"
15 #if defined(OS_ANDROID)
16 #include "chrome/browser/signin/oauth2_token_service_delegate_android.h"
18 #include "chrome/browser/signin/mutable_profile_oauth2_token_service_delegate.h"
19 #include "chrome/browser/ui/global_error/global_error_service_factory.h"
22 ProfileOAuth2TokenServiceFactory::ProfileOAuth2TokenServiceFactory()
23 : BrowserContextKeyedServiceFactory(
24 "ProfileOAuth2TokenService",
25 BrowserContextDependencyManager::GetInstance()) {
26 #if !defined(OS_ANDROID)
27 DependsOn(GlobalErrorServiceFactory::GetInstance());
29 DependsOn(WebDataServiceFactory::GetInstance());
30 DependsOn(ChromeSigninClientFactory::GetInstance());
31 DependsOn(SigninErrorControllerFactory::GetInstance());
32 DependsOn(AccountTrackerServiceFactory::GetInstance());
35 ProfileOAuth2TokenServiceFactory::~ProfileOAuth2TokenServiceFactory() {
38 ProfileOAuth2TokenService
*
39 ProfileOAuth2TokenServiceFactory::GetForProfile(Profile
* profile
) {
40 return static_cast<ProfileOAuth2TokenService
*>(
41 GetInstance()->GetServiceForBrowserContext(profile
, true));
45 ProfileOAuth2TokenServiceFactory
*
46 ProfileOAuth2TokenServiceFactory::GetInstance() {
47 return base::Singleton
<ProfileOAuth2TokenServiceFactory
>::get();
50 KeyedService
* ProfileOAuth2TokenServiceFactory::BuildServiceInstanceFor(
51 content::BrowserContext
* context
) const {
52 Profile
* profile
= static_cast<Profile
*>(context
);
53 #if defined(OS_ANDROID)
54 OAuth2TokenServiceDelegateAndroid
* delegate
=
55 new OAuth2TokenServiceDelegateAndroid(
56 AccountTrackerServiceFactory::GetInstance()->GetForProfile(profile
));
58 MutableProfileOAuth2TokenServiceDelegate
* delegate
=
59 new MutableProfileOAuth2TokenServiceDelegate(
60 ChromeSigninClientFactory::GetInstance()->GetForProfile(profile
),
61 SigninErrorControllerFactory::GetInstance()->GetForProfile(profile
),
62 AccountTrackerServiceFactory::GetInstance()->GetForProfile(profile
));
64 ProfileOAuth2TokenService
* service
= new ProfileOAuth2TokenService(delegate
);