1c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// found in the LICENSE file.
4c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
5c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
6c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
7c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chrome/browser/profiles/profile.h"
8a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "chrome/browser/signin/chrome_signin_client_factory.h"
97dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "chrome/browser/ui/global_error/global_error_service_factory.h"
10f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "chrome/browser/webdata/web_data_service_factory.h"
11a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "components/keyed_service/content/browser_context_dependency_manager.h"
12effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "components/signin/core/browser/profile_oauth2_token_service.h"
13c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
14a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#if defined(OS_ANDROID)
15a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "chrome/browser/signin/android_profile_oauth2_token_service.h"
16a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#else
17effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "components/signin/core/browser/mutable_profile_oauth2_token_service.h"
18a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#endif
19a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
20c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)ProfileOAuth2TokenServiceFactory::ProfileOAuth2TokenServiceFactory()
2190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    : BrowserContextKeyedServiceFactory(
2290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        "ProfileOAuth2TokenService",
2390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        BrowserContextDependencyManager::GetInstance()) {
247dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  DependsOn(GlobalErrorServiceFactory::GetInstance());
25f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  DependsOn(WebDataServiceFactory::GetInstance());
26a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  DependsOn(ChromeSigninClientFactory::GetInstance());
27c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
28c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
29c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)ProfileOAuth2TokenServiceFactory::~ProfileOAuth2TokenServiceFactory() {
30c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
31c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
32a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)ProfileOAuth2TokenService*
33a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)ProfileOAuth2TokenServiceFactory::GetForProfile(Profile* profile) {
34effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  return static_cast<ProfileOAuth2TokenService*>(
35effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch      GetInstance()->GetServiceForBrowserContext(profile, true));
367dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch}
37a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
38c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// static
39a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)ProfileOAuth2TokenServiceFactory::PlatformSpecificOAuth2TokenService*
40a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)ProfileOAuth2TokenServiceFactory::GetPlatformSpecificForProfile(
41c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    Profile* profile) {
42effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  return static_cast<PlatformSpecificOAuth2TokenService*>(
43effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch      GetForProfile(profile));
44c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
45c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
46c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// static
47c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)ProfileOAuth2TokenServiceFactory*
48c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    ProfileOAuth2TokenServiceFactory::GetInstance() {
49c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  return Singleton<ProfileOAuth2TokenServiceFactory>::get();
50c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
51c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
52a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)KeyedService* ProfileOAuth2TokenServiceFactory::BuildServiceInstanceFor(
53c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    content::BrowserContext* context) const {
54c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  Profile* profile = static_cast<Profile*>(context);
55effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  PlatformSpecificOAuth2TokenService* service =
56effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch      new PlatformSpecificOAuth2TokenService();
57effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  service->Initialize(
58effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch      ChromeSigninClientFactory::GetInstance()->GetForProfile(profile));
59effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  return service;
60c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
61