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/profile_oauth2_token_service_factory.h" 6 7 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/signin/profile_oauth2_token_service.h" 9 #include "chrome/browser/ui/global_error/global_error_service_factory.h" 10 #include "chrome/browser/webdata/web_data_service_factory.h" 11 #include "components/browser_context_keyed_service/browser_context_dependency_manager.h" 12 13 #if defined(OS_ANDROID) 14 #include "chrome/browser/signin/android_profile_oauth2_token_service.h" 15 #else 16 #include "chrome/browser/signin/mutable_profile_oauth2_token_service.h" 17 #endif 18 ProfileOAuth2TokenServiceFactory()19ProfileOAuth2TokenServiceFactory::ProfileOAuth2TokenServiceFactory() 20 : BrowserContextKeyedServiceFactory( 21 "ProfileOAuth2TokenService", 22 BrowserContextDependencyManager::GetInstance()) { 23 DependsOn(GlobalErrorServiceFactory::GetInstance()); 24 DependsOn(WebDataServiceFactory::GetInstance()); 25 } 26 ~ProfileOAuth2TokenServiceFactory()27ProfileOAuth2TokenServiceFactory::~ProfileOAuth2TokenServiceFactory() { 28 } 29 30 ProfileOAuth2TokenService* GetForProfile(Profile * profile)31ProfileOAuth2TokenServiceFactory::GetForProfile(Profile* profile) { 32 return static_cast<ProfileOAuth2TokenService*>( 33 GetInstance()->GetServiceForBrowserContext(profile, true)); 34 } 35 36 // static 37 ProfileOAuth2TokenServiceFactory::PlatformSpecificOAuth2TokenService* GetPlatformSpecificForProfile(Profile * profile)38ProfileOAuth2TokenServiceFactory::GetPlatformSpecificForProfile( 39 Profile* profile) { 40 return static_cast<PlatformSpecificOAuth2TokenService*>( 41 GetForProfile(profile)); 42 } 43 44 // static 45 ProfileOAuth2TokenServiceFactory* GetInstance()46 ProfileOAuth2TokenServiceFactory::GetInstance() { 47 return Singleton<ProfileOAuth2TokenServiceFactory>::get(); 48 } 49 50 BrowserContextKeyedService* BuildServiceInstanceFor(content::BrowserContext * context) const51ProfileOAuth2TokenServiceFactory::BuildServiceInstanceFor( 52 content::BrowserContext* context) const { 53 Profile* profile = static_cast<Profile*>(context); 54 PlatformSpecificOAuth2TokenService* service = 55 new PlatformSpecificOAuth2TokenService(); 56 service->Initialize(profile); 57 return service; 58 } 59