Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / autofill / personal_data_manager_factory.cc
blobf5e8f4ad9226bf9054e18f6175fe18e0443913f8
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/webdata/web_data_service_factory.h"
13 #include "components/autofill/core/browser/personal_data_manager.h"
14 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
15 #include "components/browser_context_keyed_service/browser_context_dependency_manager.h"
17 namespace autofill {
18 namespace {
20 class PersonalDataManagerServiceImpl : public PersonalDataManagerService {
21 public:
22 explicit PersonalDataManagerServiceImpl(Profile* profile);
23 virtual ~PersonalDataManagerServiceImpl();
25 // PersonalDataManagerService:
26 virtual void Shutdown() OVERRIDE;
27 virtual PersonalDataManager* GetPersonalDataManager() OVERRIDE;
29 private:
30 scoped_ptr<PersonalDataManager> personal_data_manager_;
33 PersonalDataManagerServiceImpl::PersonalDataManagerServiceImpl(
34 Profile* profile) {
35 personal_data_manager_.reset(new PersonalDataManager(
36 g_browser_process->GetApplicationLocale()));
37 personal_data_manager_->Init(
38 WebDataServiceFactory::GetAutofillWebDataForProfile(
39 profile, Profile::EXPLICIT_ACCESS),
40 profile->GetPrefs(),
41 profile->IsOffTheRecord());
44 PersonalDataManagerServiceImpl::~PersonalDataManagerServiceImpl() {}
46 void PersonalDataManagerServiceImpl::Shutdown() {
47 personal_data_manager_.reset();
50 PersonalDataManager* PersonalDataManagerServiceImpl::GetPersonalDataManager() {
51 return personal_data_manager_.get();
54 } // namespace
56 // static
57 PersonalDataManager* PersonalDataManagerFactory::GetForProfile(
58 Profile* profile) {
59 PersonalDataManagerService* service =
60 static_cast<PersonalDataManagerService*>(
61 GetInstance()->GetServiceForBrowserContext(profile, true));
63 if (service)
64 return service->GetPersonalDataManager();
66 // |service| can be NULL in Incognito mode.
67 return NULL;
70 // static
71 PersonalDataManagerFactory* PersonalDataManagerFactory::GetInstance() {
72 return Singleton<PersonalDataManagerFactory>::get();
75 PersonalDataManagerFactory::PersonalDataManagerFactory()
76 : BrowserContextKeyedServiceFactory(
77 "PersonalDataManager",
78 BrowserContextDependencyManager::GetInstance()) {
79 DependsOn(WebDataServiceFactory::GetInstance());
82 PersonalDataManagerFactory::~PersonalDataManagerFactory() {
85 BrowserContextKeyedService* PersonalDataManagerFactory::BuildServiceInstanceFor(
86 content::BrowserContext* profile) const {
87 PersonalDataManagerService* service =
88 new PersonalDataManagerServiceImpl(static_cast<Profile*>(profile));
89 return service;
92 content::BrowserContext* PersonalDataManagerFactory::GetBrowserContextToUse(
93 content::BrowserContext* context) const {
94 return chrome::GetBrowserContextOwnInstanceInIncognito(context);
97 } // namespace autofill