Upstreaming browser/ui/uikit_ui_util from iOS.
[chromium-blink-merge.git] / ios / chrome / browser / signin / account_fetcher_service_factory.cc
blobc74f031216fe9ae89b12a2b669ab128b1c6f1158
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
3 // found in the LICENSE file.
5 #include "ios/chrome/browser/signin/account_fetcher_service_factory.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"
11 #include "components/signin/core/browser/account_fetcher_service.h"
12 #include "components/signin/core/browser/profile_oauth2_token_service.h"
13 #include "ios/chrome/browser/signin/account_tracker_service_factory.h"
14 #include "ios/chrome/browser/signin/oauth2_token_service_factory.h"
15 #include "ios/chrome/browser/signin/signin_client_factory.h"
16 #include "ios/public/provider/chrome/browser/browser_state/chrome_browser_state.h"
17 #include "ios/public/provider/chrome/browser/keyed_service_provider.h"
19 namespace ios {
21 AccountFetcherServiceFactory::AccountFetcherServiceFactory()
22 : BrowserStateKeyedServiceFactory(
23 "AccountFetcherService",
24 BrowserStateDependencyManager::GetInstance()) {
25 DependsOn(AccountTrackerServiceFactory::GetInstance());
26 DependsOn(OAuth2TokenServiceFactory::GetInstance());
27 DependsOn(SigninClientFactory::GetInstance());
28 DependsOn(GetKeyedServiceProvider()->GetProfileInvalidationProviderFactory());
31 AccountFetcherServiceFactory::~AccountFetcherServiceFactory() {}
33 // static
34 AccountFetcherService* AccountFetcherServiceFactory::GetForBrowserState(
35 ios::ChromeBrowserState* browser_state) {
36 return static_cast<AccountFetcherService*>(
37 GetInstance()->GetServiceForBrowserState(browser_state, true));
40 // static
41 AccountFetcherServiceFactory* AccountFetcherServiceFactory::GetInstance() {
42 return Singleton<AccountFetcherServiceFactory>::get();
45 void AccountFetcherServiceFactory::RegisterBrowserStatePrefs(
46 user_prefs::PrefRegistrySyncable* registry) {
47 AccountFetcherService::RegisterPrefs(registry);
50 scoped_ptr<KeyedService> AccountFetcherServiceFactory::BuildServiceInstanceFor(
51 web::BrowserState* context) const {
52 ios::ChromeBrowserState* browser_state =
53 ios::ChromeBrowserState::FromBrowserState(context);
54 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(
61 SigninClientFactory::GetForBrowserState(browser_state),
62 OAuth2TokenServiceFactory::GetForBrowserState(browser_state),
63 ios::AccountTrackerServiceFactory::GetForBrowserState(browser_state),
64 invalidation_service);
65 return service.Pass();
68 } // namespace ios