OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ios/chrome/browser/signin/account_fetcher_service_factory.h" | 5 #include "ios/chrome/browser/signin/account_fetcher_service_factory.h" |
6 | 6 |
7 #include "base/memory/singleton.h" | 7 #include "base/memory/singleton.h" |
8 #include "components/invalidation/impl/profile_invalidation_provider.h" | |
9 #include "components/invalidation/public/invalidation_service.h" | |
10 #include "components/keyed_service/ios/browser_state_dependency_manager.h" | 8 #include "components/keyed_service/ios/browser_state_dependency_manager.h" |
11 #include "components/signin/core/browser/account_fetcher_service.h" | 9 #include "components/signin/core/browser/account_fetcher_service.h" |
12 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 10 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
13 #include "ios/chrome/browser/signin/account_tracker_service_factory.h" | 11 #include "ios/chrome/browser/signin/account_tracker_service_factory.h" |
14 #include "ios/chrome/browser/signin/oauth2_token_service_factory.h" | 12 #include "ios/chrome/browser/signin/oauth2_token_service_factory.h" |
15 #include "ios/chrome/browser/signin/signin_client_factory.h" | 13 #include "ios/chrome/browser/signin/signin_client_factory.h" |
16 #include "ios/public/provider/chrome/browser/browser_state/chrome_browser_state.
h" | 14 #include "ios/public/provider/chrome/browser/browser_state/chrome_browser_state.
h" |
17 #include "ios/public/provider/chrome/browser/keyed_service_provider.h" | 15 #include "ios/public/provider/chrome/browser/keyed_service_provider.h" |
18 | 16 |
19 namespace ios { | 17 namespace ios { |
20 | 18 |
21 AccountFetcherServiceFactory::AccountFetcherServiceFactory() | 19 AccountFetcherServiceFactory::AccountFetcherServiceFactory() |
22 : BrowserStateKeyedServiceFactory( | 20 : BrowserStateKeyedServiceFactory( |
23 "AccountFetcherService", | 21 "AccountFetcherService", |
24 BrowserStateDependencyManager::GetInstance()) { | 22 BrowserStateDependencyManager::GetInstance()) { |
25 DependsOn(AccountTrackerServiceFactory::GetInstance()); | 23 DependsOn(AccountTrackerServiceFactory::GetInstance()); |
26 DependsOn(OAuth2TokenServiceFactory::GetInstance()); | 24 DependsOn(OAuth2TokenServiceFactory::GetInstance()); |
27 DependsOn(SigninClientFactory::GetInstance()); | 25 DependsOn(SigninClientFactory::GetInstance()); |
28 DependsOn(GetKeyedServiceProvider()->GetProfileInvalidationProviderFactory()); | |
29 } | 26 } |
30 | 27 |
31 AccountFetcherServiceFactory::~AccountFetcherServiceFactory() {} | 28 AccountFetcherServiceFactory::~AccountFetcherServiceFactory() {} |
32 | 29 |
33 // static | 30 // static |
34 AccountFetcherService* AccountFetcherServiceFactory::GetForBrowserState( | 31 AccountFetcherService* AccountFetcherServiceFactory::GetForBrowserState( |
35 ios::ChromeBrowserState* browser_state) { | 32 ios::ChromeBrowserState* browser_state) { |
36 return static_cast<AccountFetcherService*>( | 33 return static_cast<AccountFetcherService*>( |
37 GetInstance()->GetServiceForBrowserState(browser_state, true)); | 34 GetInstance()->GetServiceForBrowserState(browser_state, true)); |
38 } | 35 } |
39 | 36 |
40 // static | 37 // static |
41 AccountFetcherServiceFactory* AccountFetcherServiceFactory::GetInstance() { | 38 AccountFetcherServiceFactory* AccountFetcherServiceFactory::GetInstance() { |
42 return base::Singleton<AccountFetcherServiceFactory>::get(); | 39 return base::Singleton<AccountFetcherServiceFactory>::get(); |
43 } | 40 } |
44 | 41 |
45 void AccountFetcherServiceFactory::RegisterBrowserStatePrefs( | 42 void AccountFetcherServiceFactory::RegisterBrowserStatePrefs( |
46 user_prefs::PrefRegistrySyncable* registry) { | 43 user_prefs::PrefRegistrySyncable* registry) { |
47 AccountFetcherService::RegisterPrefs(registry); | 44 AccountFetcherService::RegisterPrefs(registry); |
48 } | 45 } |
49 | 46 |
50 scoped_ptr<KeyedService> AccountFetcherServiceFactory::BuildServiceInstanceFor( | 47 scoped_ptr<KeyedService> AccountFetcherServiceFactory::BuildServiceInstanceFor( |
51 web::BrowserState* context) const { | 48 web::BrowserState* context) const { |
52 ios::ChromeBrowserState* browser_state = | 49 ios::ChromeBrowserState* browser_state = |
53 ios::ChromeBrowserState::FromBrowserState(context); | 50 ios::ChromeBrowserState::FromBrowserState(context); |
54 scoped_ptr<AccountFetcherService> service(new AccountFetcherService()); | 51 scoped_ptr<AccountFetcherService> service(new AccountFetcherService()); |
55 invalidation::ProfileInvalidationProvider* invalidation_provider = | |
56 ios::GetKeyedServiceProvider() | |
57 ->GetProfileInvalidationProviderForBrowserState(browser_state); | |
58 invalidation::InvalidationService* invalidation_service = | |
59 invalidation_provider->GetInvalidationService(); | |
60 service->Initialize( | 52 service->Initialize( |
61 SigninClientFactory::GetForBrowserState(browser_state), | 53 SigninClientFactory::GetForBrowserState(browser_state), |
62 OAuth2TokenServiceFactory::GetForBrowserState(browser_state), | 54 OAuth2TokenServiceFactory::GetForBrowserState(browser_state), |
63 ios::AccountTrackerServiceFactory::GetForBrowserState(browser_state), | 55 ios::AccountTrackerServiceFactory::GetForBrowserState(browser_state)); |
64 invalidation_service); | |
65 return service.Pass(); | 56 return service.Pass(); |
66 } | 57 } |
67 | 58 |
68 } // namespace ios | 59 } // namespace ios |
OLD | NEW |