/ios/chrome/browser/safe_browsing/chrome_password_protection_service_factory.mm

https://github.com/chromium/chromium · Objective C++ · 82 lines · 67 code · 10 blank · 5 comment · 2 complexity · 79b06577d26320d0e6068600116fc498 MD5 · raw file

  1. // Copyright 2021 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. #import "ios/chrome/browser/safe_browsing/chrome_password_protection_service_factory.h"
  5. #include "base/no_destructor.h"
  6. #include "components/keyed_service/core/service_access_type.h"
  7. #include "components/keyed_service/ios/browser_state_dependency_manager.h"
  8. #import "ios/chrome/browser/application_context.h"
  9. #include "ios/chrome/browser/browser_state/browser_state_otr_helper.h"
  10. #import "ios/chrome/browser/browser_state/chrome_browser_state.h"
  11. #include "ios/chrome/browser/history/history_service_factory.h"
  12. #include "ios/chrome/browser/passwords/ios_chrome_password_store_factory.h"
  13. #import "ios/chrome/browser/safe_browsing/chrome_password_protection_service.h"
  14. #import "ios/chrome/browser/safe_browsing/safe_browsing_metrics_collector_factory.h"
  15. #import "ios/chrome/browser/signin/identity_manager_factory.h"
  16. #include "ios/chrome/browser/sync/ios_user_event_service_factory.h"
  17. #import "ios/chrome/browser/sync/sync_service_factory.h"
  18. #if !defined(__has_feature) || !__has_feature(objc_arc)
  19. #error "This file requires ARC support."
  20. #endif
  21. // static
  22. ChromePasswordProtectionService*
  23. ChromePasswordProtectionServiceFactory::GetForBrowserState(
  24. web::BrowserState* browser_state) {
  25. return static_cast<ChromePasswordProtectionService*>(
  26. GetInstance()->GetServiceForBrowserState(browser_state, /*create=*/true));
  27. }
  28. // static
  29. ChromePasswordProtectionServiceFactory*
  30. ChromePasswordProtectionServiceFactory::GetInstance() {
  31. static base::NoDestructor<ChromePasswordProtectionServiceFactory> instance;
  32. return instance.get();
  33. }
  34. ChromePasswordProtectionServiceFactory::ChromePasswordProtectionServiceFactory()
  35. : BrowserStateKeyedServiceFactory(
  36. "ChromePasswordProtectionService",
  37. BrowserStateDependencyManager::GetInstance()) {
  38. DependsOn(IdentityManagerFactory::GetInstance());
  39. DependsOn(IOSChromePasswordStoreFactory::GetInstance());
  40. DependsOn(IOSUserEventServiceFactory::GetInstance());
  41. DependsOn(SafeBrowsingMetricsCollectorFactory::GetInstance());
  42. DependsOn(SyncServiceFactory::GetInstance());
  43. DependsOn(ios::HistoryServiceFactory::GetInstance());
  44. }
  45. std::unique_ptr<KeyedService>
  46. ChromePasswordProtectionServiceFactory::BuildServiceInstanceFor(
  47. web::BrowserState* browser_state) const {
  48. SafeBrowsingService* safe_browsing_service =
  49. GetApplicationContext()->GetSafeBrowsingService();
  50. if (!safe_browsing_service) {
  51. return nullptr;
  52. }
  53. ChromeBrowserState* chrome_browser_state =
  54. ChromeBrowserState::FromBrowserState(browser_state);
  55. return std::make_unique<ChromePasswordProtectionService>(
  56. safe_browsing_service, chrome_browser_state,
  57. ios::HistoryServiceFactory::GetForBrowserState(
  58. chrome_browser_state, ServiceAccessType::EXPLICIT_ACCESS),
  59. SafeBrowsingMetricsCollectorFactory::GetForBrowserState(
  60. chrome_browser_state));
  61. }
  62. bool ChromePasswordProtectionServiceFactory::ServiceIsCreatedWithBrowserState()
  63. const {
  64. return false;
  65. }
  66. web::BrowserState* ChromePasswordProtectionServiceFactory::GetBrowserStateToUse(
  67. web::BrowserState* context) const {
  68. return GetBrowserStateOwnInstanceInIncognito(context);
  69. }
  70. bool ChromePasswordProtectionServiceFactory::ServiceIsNULLWhileTesting() const {
  71. return true;
  72. }