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