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/pref_registry/pref_registry_syncable.h"
16 #include "components/signin/core/browser/account_fetcher_service.h"
17 #include "components/signin/core/browser/profile_oauth2_token_service.h"
19 AccountFetcherServiceFactory::AccountFetcherServiceFactory()
20 : BrowserContextKeyedServiceFactory(
21 "AccountFetcherServiceFactory",
22 BrowserContextDependencyManager::GetInstance()) {
23 DependsOn(AccountTrackerServiceFactory::GetInstance());
24 DependsOn(ChromeSigninClientFactory::GetInstance());
25 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance());
26 DependsOn(invalidation::ProfileInvalidationProviderFactory::GetInstance());
29 AccountFetcherServiceFactory::~AccountFetcherServiceFactory() {}
32 AccountFetcherService
* AccountFetcherServiceFactory::GetForProfile(
34 return static_cast<AccountFetcherService
*>(
35 GetInstance()->GetServiceForBrowserContext(profile
, true));
39 AccountFetcherServiceFactory
* AccountFetcherServiceFactory::GetInstance() {
40 return Singleton
<AccountFetcherServiceFactory
>::get();
43 void AccountFetcherServiceFactory::RegisterProfilePrefs(
44 user_prefs::PrefRegistrySyncable
* registry
) {
45 registry
->RegisterInt64Pref(AccountFetcherService::kLastUpdatePref
, 0);
48 KeyedService
* AccountFetcherServiceFactory::BuildServiceInstanceFor(
49 content::BrowserContext
* context
) const {
50 Profile
* profile
= Profile::FromBrowserContext(context
);
51 AccountFetcherService
* service
= new AccountFetcherService();
52 invalidation::ProfileInvalidationProvider
* invalidation_provider
=
53 invalidation::ProfileInvalidationProviderFactory::GetForProfile(profile
);
54 // Chrome OS login and guest profiles do not support invalidation. This is
55 // fine as they do not have GAIA credentials anyway. http://crbug.com/358169
56 invalidation::InvalidationService
* invalidation_service
=
57 invalidation_provider
? invalidation_provider
->GetInvalidationService()
59 service
->Initialize(ChromeSigninClientFactory::GetForProfile(profile
),
60 ProfileOAuth2TokenServiceFactory::GetForProfile(profile
),
61 AccountTrackerServiceFactory::GetForProfile(profile
),
62 invalidation_service
);