- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / signin / profile_oauth2_token_service_factory.cc
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/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"
13
14 ProfileOAuth2TokenServiceFactory::ProfileOAuth2TokenServiceFactory()
15     : BrowserContextKeyedServiceFactory(
16         "ProfileOAuth2TokenService",
17         BrowserContextDependencyManager::GetInstance()) {
18   DependsOn(GlobalErrorServiceFactory::GetInstance());
19   DependsOn(SigninManagerFactory::GetInstance());
20   DependsOn(TokenServiceFactory::GetInstance());
21 }
22
23 ProfileOAuth2TokenServiceFactory::~ProfileOAuth2TokenServiceFactory() {
24 }
25
26 #if defined(OS_ANDROID)
27 // static
28 AndroidProfileOAuth2TokenService*
29     ProfileOAuth2TokenServiceFactory::GetForProfile(Profile* profile) {
30   return static_cast<AndroidProfileOAuth2TokenService*>(
31       GetInstance()->GetServiceForBrowserContext(profile, true));
32 }
33 #else
34 // static
35 ProfileOAuth2TokenService* ProfileOAuth2TokenServiceFactory::GetForProfile(
36     Profile* profile) {
37   return static_cast<ProfileOAuth2TokenService*>(
38       GetInstance()->GetServiceForBrowserContext(profile, true));
39 }
40 #endif  // defined(OS_ANDROID)
41
42 // static
43 ProfileOAuth2TokenServiceFactory*
44     ProfileOAuth2TokenServiceFactory::GetInstance() {
45   return Singleton<ProfileOAuth2TokenServiceFactory>::get();
46 }
47
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();
55 #else
56   service = new ProfileOAuth2TokenService();
57 #endif
58   service->Initialize(profile);
59   return service;
60 }