| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 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/autocheckout_whitelist_manager_factory.h" | |
| 6 | |
| 7 #include "base/memory/scoped_ptr.h" | |
| 8 #include "base/memory/singleton.h" | |
| 9 #include "chrome/browser/profiles/incognito_helpers.h" | |
| 10 #include "chrome/browser/profiles/profile.h" | |
| 11 #include "components/autofill/content/browser/autocheckout/whitelist_manager.h" | |
| 12 #include "components/browser_context_keyed_service/browser_context_dependency_ma
nager.h" | |
| 13 | |
| 14 namespace autofill { | |
| 15 namespace autocheckout { | |
| 16 | |
| 17 class WhitelistManagerServiceImpl | |
| 18 : public WhitelistManagerService { | |
| 19 public: | |
| 20 explicit WhitelistManagerServiceImpl(Profile* profile); | |
| 21 virtual ~WhitelistManagerServiceImpl(); | |
| 22 | |
| 23 // WhitelistManagerService: | |
| 24 virtual void Shutdown() OVERRIDE; | |
| 25 virtual WhitelistManager* GetWhitelistManager() OVERRIDE; | |
| 26 | |
| 27 private: | |
| 28 scoped_ptr<WhitelistManager> whitelist_manager_; | |
| 29 }; | |
| 30 | |
| 31 WhitelistManagerServiceImpl | |
| 32 ::WhitelistManagerServiceImpl(Profile* profile) { | |
| 33 whitelist_manager_.reset(new WhitelistManager()); | |
| 34 whitelist_manager_->Init(profile->GetRequestContext()); | |
| 35 } | |
| 36 | |
| 37 WhitelistManagerServiceImpl | |
| 38 ::~WhitelistManagerServiceImpl() {} | |
| 39 | |
| 40 void WhitelistManagerServiceImpl::Shutdown() { | |
| 41 whitelist_manager_.reset(); | |
| 42 } | |
| 43 | |
| 44 WhitelistManager* | |
| 45 WhitelistManagerServiceImpl::GetWhitelistManager() { | |
| 46 return whitelist_manager_.get(); | |
| 47 } | |
| 48 | |
| 49 // static | |
| 50 WhitelistManager* | |
| 51 WhitelistManagerFactory::GetForProfile(Profile* profile) { | |
| 52 WhitelistManagerService* service = | |
| 53 static_cast<WhitelistManagerService*>( | |
| 54 GetInstance()->GetServiceForBrowserContext(profile, true)); | |
| 55 // service can be NULL for tests. | |
| 56 return service ? service->GetWhitelistManager() : NULL; | |
| 57 } | |
| 58 | |
| 59 // static | |
| 60 WhitelistManagerFactory* | |
| 61 WhitelistManagerFactory::GetInstance() { | |
| 62 return Singleton<WhitelistManagerFactory>::get(); | |
| 63 } | |
| 64 | |
| 65 WhitelistManagerFactory::WhitelistManagerFactory() | |
| 66 : BrowserContextKeyedServiceFactory( | |
| 67 "AutocheckoutWhitelistManager", | |
| 68 BrowserContextDependencyManager::GetInstance()) { | |
| 69 } | |
| 70 | |
| 71 WhitelistManagerFactory::~WhitelistManagerFactory() { | |
| 72 } | |
| 73 | |
| 74 BrowserContextKeyedService* | |
| 75 WhitelistManagerFactory::BuildServiceInstanceFor( | |
| 76 content::BrowserContext* profile) const { | |
| 77 WhitelistManagerService* service = | |
| 78 new WhitelistManagerServiceImpl(static_cast<Profile*>(profile)); | |
| 79 return service; | |
| 80 } | |
| 81 | |
| 82 content::BrowserContext* WhitelistManagerFactory::GetBrowserContextToUse( | |
| 83 content::BrowserContext* context) const { | |
| 84 return chrome::GetBrowserContextRedirectedInIncognito(context); | |
| 85 } | |
| 86 | |
| 87 bool WhitelistManagerFactory::ServiceIsNULLWhileTesting() const { | |
| 88 return true; | |
| 89 } | |
| 90 | |
| 91 } // namespace autocheckout | |
| 92 } // namespace autofill | |
| OLD | NEW |