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. 4 5 #include "chrome/browser/autofill/personal_data_manager_factory.h" 6 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/keyed_service/content/browser_context_dependency_manager.h" 16 17 namespace autofill { 18 19 // static 20 PersonalDataManager* PersonalDataManagerFactory::GetForProfile( 21 Profile* profile) { 22 return static_cast<PersonalDataManager*>( 23 GetInstance()->GetServiceForBrowserContext(profile, true)); 24 } 25 26 // static 27 PersonalDataManagerFactory* PersonalDataManagerFactory::GetInstance() { 28 return Singleton<PersonalDataManagerFactory>::get(); 29 } 30 31 PersonalDataManagerFactory::PersonalDataManagerFactory() 32 : BrowserContextKeyedServiceFactory( 33 "PersonalDataManager", 34 BrowserContextDependencyManager::GetInstance()) { 35 DependsOn(WebDataServiceFactory::GetInstance()); 36 } 37 38 PersonalDataManagerFactory::~PersonalDataManagerFactory() { 39 } 40 41 KeyedService* PersonalDataManagerFactory::BuildServiceInstanceFor( 42 content::BrowserContext* context) const { 43 Profile* profile = Profile::FromBrowserContext(context); 44 PersonalDataManager* service = 45 new PersonalDataManager(g_browser_process->GetApplicationLocale()); 46 service->Init(WebDataServiceFactory::GetAutofillWebDataForProfile( 47 profile, Profile::EXPLICIT_ACCESS), 48 profile->GetPrefs(), 49 profile->IsOffTheRecord()); 50 return service; 51 } 52 53 content::BrowserContext* PersonalDataManagerFactory::GetBrowserContextToUse( 54 content::BrowserContext* context) const { 55 return chrome::GetBrowserContextOwnInstanceInIncognito(context); 56 } 57 58 } // namespace autofill 59