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/profile_oauth2_token_service.h"
9 #include "chrome/browser/signin/signin_manager_factory.h"
10 #include "chrome/browser/signin/token_service_factory.h"
11 #include "chrome/browser/ui/global_error/global_error_service_factory.h"
12 #include "components/browser_context_keyed_service/browser_context_dependency_manager.h"
14 ProfileOAuth2TokenServiceFactory::ProfileOAuth2TokenServiceFactory()
15 : BrowserContextKeyedServiceFactory(
16 "ProfileOAuth2TokenService",
17 BrowserContextDependencyManager::GetInstance()) {
18 DependsOn(GlobalErrorServiceFactory::GetInstance());
19 DependsOn(SigninManagerFactory::GetInstance());
20 DependsOn(TokenServiceFactory::GetInstance());
23 ProfileOAuth2TokenServiceFactory::~ProfileOAuth2TokenServiceFactory() {
26 #if defined(OS_ANDROID)
28 AndroidProfileOAuth2TokenService*
29 ProfileOAuth2TokenServiceFactory::GetForProfile(Profile* profile) {
30 return static_cast<AndroidProfileOAuth2TokenService*>(
31 GetInstance()->GetServiceForBrowserContext(profile, true));
35 ProfileOAuth2TokenService* ProfileOAuth2TokenServiceFactory::GetForProfile(
37 return static_cast<ProfileOAuth2TokenService*>(
38 GetInstance()->GetServiceForBrowserContext(profile, true));
40 #endif // defined(OS_ANDROID)
43 ProfileOAuth2TokenServiceFactory*
44 ProfileOAuth2TokenServiceFactory::GetInstance() {
45 return Singleton<ProfileOAuth2TokenServiceFactory>::get();
48 BrowserContextKeyedService*
49 ProfileOAuth2TokenServiceFactory::BuildServiceInstanceFor(
50 content::BrowserContext* context) const {
51 Profile* profile = static_cast<Profile*>(context);
52 ProfileOAuth2TokenService* service;
53 #if defined(OS_ANDROID)
54 service = new AndroidProfileOAuth2TokenService();
56 service = new ProfileOAuth2TokenService();
58 service->Initialize(profile);