/chromium-webcl/src/chrome/browser/autofill/autocheckout_whitelist_manager_factory.cc

https://bitbucket.org/peixuan/chromium_r197479_base · C++ · 89 lines · 64 code · 18 blank · 7 comment · 0 complexity · 61df6e96b8219283533e6a7ed39c2031 MD5 · raw file

  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. #include "chrome/browser/autofill/autocheckout_whitelist_manager_factory.h"
  5. #include "base/memory/scoped_ptr.h"
  6. #include "base/memory/singleton.h"
  7. #include "chrome/browser/profiles/profile.h"
  8. #include "chrome/browser/profiles/profile_dependency_manager.h"
  9. #include "components/autofill/browser/autocheckout/whitelist_manager.h"
  10. namespace autofill {
  11. namespace autocheckout {
  12. class WhitelistManagerServiceImpl
  13. : public WhitelistManagerService {
  14. public:
  15. explicit WhitelistManagerServiceImpl(Profile* profile);
  16. virtual ~WhitelistManagerServiceImpl();
  17. // WhitelistManagerService:
  18. virtual void Shutdown() OVERRIDE;
  19. virtual WhitelistManager* GetWhitelistManager() OVERRIDE;
  20. private:
  21. scoped_ptr<WhitelistManager> whitelist_manager_;
  22. };
  23. WhitelistManagerServiceImpl
  24. ::WhitelistManagerServiceImpl(Profile* profile) {
  25. whitelist_manager_.reset(new WhitelistManager());
  26. whitelist_manager_->Init(profile->GetRequestContext());
  27. }
  28. WhitelistManagerServiceImpl
  29. ::~WhitelistManagerServiceImpl() {}
  30. void WhitelistManagerServiceImpl::Shutdown() {
  31. whitelist_manager_.reset();
  32. }
  33. WhitelistManager*
  34. WhitelistManagerServiceImpl::GetWhitelistManager() {
  35. return whitelist_manager_.get();
  36. }
  37. // static
  38. WhitelistManager*
  39. WhitelistManagerFactory::GetForProfile(Profile* profile) {
  40. WhitelistManagerService* service =
  41. static_cast<WhitelistManagerService*>(
  42. GetInstance()->GetServiceForProfile(profile, true));
  43. // service can be NULL for tests.
  44. return service ? service->GetWhitelistManager() : NULL;
  45. }
  46. // static
  47. WhitelistManagerFactory*
  48. WhitelistManagerFactory::GetInstance() {
  49. return Singleton<WhitelistManagerFactory>::get();
  50. }
  51. WhitelistManagerFactory::WhitelistManagerFactory()
  52. : ProfileKeyedServiceFactory("AutocheckoutWhitelistManager",
  53. ProfileDependencyManager::GetInstance()) {
  54. }
  55. WhitelistManagerFactory::~WhitelistManagerFactory() {
  56. }
  57. ProfileKeyedService*
  58. WhitelistManagerFactory::BuildServiceInstanceFor(
  59. content::BrowserContext* profile) const {
  60. WhitelistManagerService* service =
  61. new WhitelistManagerServiceImpl(static_cast<Profile*>(profile));
  62. return service;
  63. }
  64. bool WhitelistManagerFactory::ServiceRedirectedInIncognito() const {
  65. return true;
  66. }
  67. bool WhitelistManagerFactory::ServiceIsNULLWhileTesting() const {
  68. return true;
  69. }
  70. } // namespace autocheckout
  71. } // namespace autofill