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 "chrome/browser/signin/account_fetcher_service_factory.h"
7 #include "chrome/browser/invalidation/profile_invalidation_provider_factory.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/signin/account_tracker_service_factory.h"
10 #include "chrome/browser/signin/chrome_signin_client_factory.h"
11 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
12 #include "components/invalidation/impl/profile_invalidation_provider.h"
13 #include "components/invalidation/public/invalidation_service.h"
14 #include "components/keyed_service/content/browser_context_dependency_manager.h"
15 #include "components/signin/core/browser/account_fetcher_service.h"
16 #include "components/signin/core/browser/profile_oauth2_token_service.h"
18 AccountFetcherServiceFactory::AccountFetcherServiceFactory()
19 : BrowserContextKeyedServiceFactory(
20 "AccountFetcherServiceFactory",
21 BrowserContextDependencyManager::GetInstance()) {
22 DependsOn(AccountTrackerServiceFactory::GetInstance());
23 DependsOn(ChromeSigninClientFactory::GetInstance());
24 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance());
25 DependsOn(invalidation::ProfileInvalidationProviderFactory::GetInstance());
28 AccountFetcherServiceFactory::~AccountFetcherServiceFactory() {}
31 AccountFetcherService
* AccountFetcherServiceFactory::GetForProfile(
33 return static_cast<AccountFetcherService
*>(
34 GetInstance()->GetServiceForBrowserContext(profile
, true));
38 AccountFetcherServiceFactory
* AccountFetcherServiceFactory::GetInstance() {
39 return Singleton
<AccountFetcherServiceFactory
>::get();
42 void AccountFetcherServiceFactory::RegisterProfilePrefs(
43 user_prefs::PrefRegistrySyncable
* registry
) {
44 AccountFetcherService::RegisterPrefs(registry
);
47 KeyedService
* AccountFetcherServiceFactory::BuildServiceInstanceFor(
48 content::BrowserContext
* context
) const {
49 Profile
* profile
= Profile::FromBrowserContext(context
);
50 AccountFetcherService
* service
= new AccountFetcherService();
51 invalidation::ProfileInvalidationProvider
* invalidation_provider
=
52 invalidation::ProfileInvalidationProviderFactory::GetForProfile(profile
);
53 // Chrome OS login and guest profiles do not support invalidation. This is
54 // fine as they do not have GAIA credentials anyway. http://crbug.com/358169
55 invalidation::InvalidationService
* invalidation_service
=
56 invalidation_provider
? invalidation_provider
->GetInvalidationService()
58 service
->Initialize(ChromeSigninClientFactory::GetForProfile(profile
),
59 ProfileOAuth2TokenServiceFactory::GetForProfile(profile
),
60 AccountTrackerServiceFactory::GetForProfile(profile
),
61 invalidation_service
);