account_tracker_service_factory.cc revision 1320f92c476a1ad9d19dba2a48c72b75566198e9
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
16AccountTrackerServiceFactory::AccountTrackerServiceFactory()
17    : BrowserContextKeyedServiceFactory(
18        "AccountTrackerServiceFactory",
19        BrowserContextDependencyManager::GetInstance()) {
20  DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance());
21}
22
23AccountTrackerServiceFactory::~AccountTrackerServiceFactory() {
24}
25
26// static
27AccountTrackerService*
28AccountTrackerServiceFactory::GetForProfile(Profile* profile) {
29  return static_cast<AccountTrackerService*>(
30      GetInstance()->GetServiceForBrowserContext(profile, true));
31}
32
33// static
34AccountTrackerServiceFactory* AccountTrackerServiceFactory::GetInstance() {
35  return Singleton<AccountTrackerServiceFactory>::get();
36}
37
38void 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
49KeyedService* 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