Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ios / chrome / browser / autofill / personal_data_manager_factory.cc
blob44978d804973aa8b33286cf89afa2a47b4237255
1 // Copyright 2015 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 "ios/chrome/browser/autofill/personal_data_manager_factory.h"
7 #include "base/memory/singleton.h"
8 #include "components/autofill/core/browser/personal_data_manager.h"
9 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
10 #include "components/keyed_service/core/service_access_type.h"
11 #include "components/keyed_service/ios/browser_state_dependency_manager.h"
12 #include "ios/chrome/browser/application_context.h"
13 #include "ios/chrome/browser/browser_state/browser_state_otr_helper.h"
14 #include "ios/chrome/browser/signin/account_tracker_service_factory.h"
15 #include "ios/chrome/browser/web_data_service_factory.h"
16 #include "ios/public/provider/chrome/browser/browser_state/chrome_browser_state.h"
18 // static
19 autofill::PersonalDataManager* PersonalDataManagerFactory::GetForBrowserState(
20 ios::ChromeBrowserState* browser_state) {
21 return static_cast<autofill::PersonalDataManager*>(
22 GetInstance()->GetServiceForBrowserState(browser_state, true));
25 // static
26 PersonalDataManagerFactory* PersonalDataManagerFactory::GetInstance() {
27 return base::Singleton<PersonalDataManagerFactory>::get();
30 PersonalDataManagerFactory::PersonalDataManagerFactory()
31 : BrowserStateKeyedServiceFactory(
32 "PersonalDataManager",
33 BrowserStateDependencyManager::GetInstance()) {
34 DependsOn(ios::AccountTrackerServiceFactory::GetInstance());
35 DependsOn(ios::WebDataServiceFactory::GetInstance());
38 PersonalDataManagerFactory::~PersonalDataManagerFactory() {}
40 scoped_ptr<KeyedService> PersonalDataManagerFactory::BuildServiceInstanceFor(
41 web::BrowserState* context) const {
42 ios::ChromeBrowserState* chrome_browser_state =
43 ios::ChromeBrowserState::FromBrowserState(context);
44 scoped_ptr<autofill::PersonalDataManager> service(
45 new autofill::PersonalDataManager(
46 GetApplicationContext()->GetApplicationLocale()));
47 service->Init(ios::WebDataServiceFactory::GetAutofillWebDataForBrowserState(
48 chrome_browser_state, ServiceAccessType::EXPLICIT_ACCESS),
49 chrome_browser_state->GetPrefs(),
50 ios::AccountTrackerServiceFactory::GetForBrowserState(
51 chrome_browser_state),
52 chrome_browser_state->IsOffTheRecord());
53 return service.Pass();