1 // Copyright (c) 2014 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/account_tracker_service_factory.h" 6 7 #include "base/memory/scoped_ptr.h" 8 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 10 #include "components/keyed_service/content/browser_context_dependency_manager.h" 11 #include "components/pref_registry/pref_registry_syncable.h" 12 #include "components/signin/core/browser/account_tracker_service.h" 13 #include "components/signin/core/browser/profile_oauth2_token_service.h" 14 #include "components/signin/core/common/signin_pref_names.h" 15 16 AccountTrackerServiceFactory::AccountTrackerServiceFactory() 17 : BrowserContextKeyedServiceFactory( 18 "AccountTrackerServiceFactory", 19 BrowserContextDependencyManager::GetInstance()) { 20 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance()); 21 } 22 23 AccountTrackerServiceFactory::~AccountTrackerServiceFactory() { 24 } 25 26 // static 27 AccountTrackerService* 28 AccountTrackerServiceFactory::GetForProfile(Profile* profile) { 29 return static_cast<AccountTrackerService*>( 30 GetInstance()->GetServiceForBrowserContext(profile, true)); 31 } 32 33 // static 34 AccountTrackerServiceFactory* AccountTrackerServiceFactory::GetInstance() { 35 return Singleton<AccountTrackerServiceFactory>::get(); 36 } 37 38 void AccountTrackerServiceFactory::RegisterProfilePrefs( 39 user_prefs::PrefRegistrySyncable* registry) { 40 registry->RegisterListPref( 41 AccountTrackerService::kAccountInfoPref, 42 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 43 registry->RegisterIntegerPref( 44 prefs::kAccountIdMigrationState, 45 AccountTrackerService::MIGRATION_NOT_STARTED, 46 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 47 } 48 49 KeyedService* AccountTrackerServiceFactory::BuildServiceInstanceFor( 50 content::BrowserContext* context) const { 51 Profile* profile = static_cast<Profile*>(context); 52 AccountTrackerService* service = new AccountTrackerService(); 53 service->Initialize( 54 ProfileOAuth2TokenServiceFactory::GetForProfile(profile), 55 profile->GetPrefs(), 56 profile->GetRequestContext()); 57 return service; 58 } 59