summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autofill/personal_data_manager_factory.cc
blob: 803c628c67bc928be2cfe5c13493a1b0df7741b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/autofill/personal_data_manager_factory.h"

#include "base/memory/scoped_ptr.h"
#include "base/memory/singleton.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_dependency_manager.h"
#include "chrome/browser/webdata/web_data_service_factory.h"
#include "components/autofill/browser/personal_data_manager.h"

namespace {

class PersonalDataManagerServiceImpl : public PersonalDataManagerService {
 public:
  PersonalDataManagerServiceImpl(Profile* profile);
  virtual ~PersonalDataManagerServiceImpl();

  // PersonalDataManagerService:
  virtual void Shutdown() OVERRIDE;
  virtual PersonalDataManager* GetPersonalDataManager() OVERRIDE;

 private:
  scoped_ptr<PersonalDataManager> personal_data_manager_;
};

PersonalDataManagerServiceImpl::PersonalDataManagerServiceImpl(
    Profile* profile) {
  personal_data_manager_.reset(new PersonalDataManager());
  personal_data_manager_->Init(profile);
}

PersonalDataManagerServiceImpl::~PersonalDataManagerServiceImpl() {}

void PersonalDataManagerServiceImpl::Shutdown() {
  personal_data_manager_.reset();
}

PersonalDataManager* PersonalDataManagerServiceImpl::GetPersonalDataManager() {
  return personal_data_manager_.get();
}

}  // namespace

// static
PersonalDataManager* PersonalDataManagerFactory::GetForProfile(
    Profile* profile) {
  PersonalDataManagerService* service =
      static_cast<PersonalDataManagerService*>(
          GetInstance()->GetServiceForProfile(profile, true));

  if (service)
    return service->GetPersonalDataManager();

  // |service| can be NULL in Incognito mode.
  return NULL;
}

// static
PersonalDataManagerFactory* PersonalDataManagerFactory::GetInstance() {
  return Singleton<PersonalDataManagerFactory>::get();
}

PersonalDataManagerFactory::PersonalDataManagerFactory()
    : ProfileKeyedServiceFactory("PersonalDataManager",
                                 ProfileDependencyManager::GetInstance()) {
  DependsOn(WebDataServiceFactory::GetInstance());
}

PersonalDataManagerFactory::~PersonalDataManagerFactory() {
}

ProfileKeyedService* PersonalDataManagerFactory::BuildServiceInstanceFor(
    Profile* profile) const {
  PersonalDataManagerService* service =
      new PersonalDataManagerServiceImpl(profile);
  return service;
}