ExtensionSyncService: listen for relevant changes instead of being explicitly called...
[chromium-blink-merge.git] / chrome / browser / autofill / personal_data_manager_factory.cc
blobb67e2e56e80d440819638ac9de6a95d69be8bfd4
1 // Copyright (c) 2012 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/autofill/personal_data_manager_factory.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "base/memory/singleton.h"
9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/profiles/incognito_helpers.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/signin/account_tracker_service_factory.h"
13 #include "chrome/browser/web_data_service_factory.h"
14 #include "components/autofill/core/browser/personal_data_manager.h"
15 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
16 #include "components/keyed_service/content/browser_context_dependency_manager.h"
17 #include "components/signin/core/browser/account_tracker_service.h"
19 namespace autofill {
21 // static
22 PersonalDataManager* PersonalDataManagerFactory::GetForProfile(
23 Profile* profile) {
24 return static_cast<PersonalDataManager*>(
25 GetInstance()->GetServiceForBrowserContext(profile, true));
28 // static
29 PersonalDataManagerFactory* PersonalDataManagerFactory::GetInstance() {
30 return Singleton<PersonalDataManagerFactory>::get();
33 PersonalDataManagerFactory::PersonalDataManagerFactory()
34 : BrowserContextKeyedServiceFactory(
35 "PersonalDataManager",
36 BrowserContextDependencyManager::GetInstance()) {
37 DependsOn(AccountTrackerServiceFactory::GetInstance());
38 DependsOn(WebDataServiceFactory::GetInstance());
41 PersonalDataManagerFactory::~PersonalDataManagerFactory() {
44 KeyedService* PersonalDataManagerFactory::BuildServiceInstanceFor(
45 content::BrowserContext* context) const {
46 Profile* profile = Profile::FromBrowserContext(context);
47 PersonalDataManager* service =
48 new PersonalDataManager(g_browser_process->GetApplicationLocale());
49 service->Init(WebDataServiceFactory::GetAutofillWebDataForProfile(
50 profile, ServiceAccessType::EXPLICIT_ACCESS),
51 profile->GetPrefs(),
52 AccountTrackerServiceFactory::GetForProfile(profile),
53 profile->IsOffTheRecord());
54 return service;
57 content::BrowserContext* PersonalDataManagerFactory::GetBrowserContextToUse(
58 content::BrowserContext* context) const {
59 return chrome::GetBrowserContextOwnInstanceInIncognito(context);
62 } // namespace autofill