[ios] Convert RealTimeUrlLookupServiceFactory to PKSFIOS

Convert RealTimeUrlLookupServiceFactory to be a
ProfileKeydServiceFactoryIOS.

Fixed: 363218353
Change-Id: Ia6e4287061809cd40981dcc304b8711c5550d1ac
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6074674
Reviewed-by: Aliona Dangla <alionadangla@chromium.org>
Commit-Queue: Aliona Dangla <alionadangla@chromium.org>
Auto-Submit: Sylvain Defresne <sdefresne@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1392344}
diff --git a/ios/chrome/browser/safe_browsing/model/real_time_url_lookup_service_factory.h b/ios/chrome/browser/safe_browsing/model/real_time_url_lookup_service_factory.h
index 2385dae..11a9e42 100644
--- a/ios/chrome/browser/safe_browsing/model/real_time_url_lookup_service_factory.h
+++ b/ios/chrome/browser/safe_browsing/model/real_time_url_lookup_service_factory.h
@@ -6,26 +6,17 @@
 #define IOS_CHROME_BROWSER_SAFE_BROWSING_MODEL_REAL_TIME_URL_LOOKUP_SERVICE_FACTORY_H_
 
 #import "base/no_destructor.h"
-#import "components/keyed_service/ios/browser_state_keyed_service_factory.h"
+#import "ios/chrome/browser/shared/model/profile/profile_keyed_service_factory_ios.h"
 
-class KeyedService;
 class ProfileIOS;
 
 namespace safe_browsing {
 class RealTimeUrlLookupService;
 }
 
-namespace variations {
-class VariationsService;
-}
-
-namespace web {
-class BrowserState;
-}
-
 // Singleton that owns RealTimeUrlLookupService objects, one for each active
 // profile. It returns nullptr for Incognito profiles.
-class RealTimeUrlLookupServiceFactory : public BrowserStateKeyedServiceFactory {
+class RealTimeUrlLookupServiceFactory : public ProfileKeyedServiceFactoryIOS {
  public:
   // Returns null if `profile` is in Incognito mode.
   static safe_browsing::RealTimeUrlLookupService* GetForProfile(
@@ -41,8 +32,6 @@
   // BrowserStateKeyedServiceFactory:
   std::unique_ptr<KeyedService> BuildServiceInstanceFor(
       web::BrowserState* browser_state) const override;
-
-  static variations::VariationsService* GetVariationsService();
 };
 
 #endif  // IOS_CHROME_BROWSER_SAFE_BROWSING_MODEL_REAL_TIME_URL_LOOKUP_SERVICE_FACTORY_H_
diff --git a/ios/chrome/browser/safe_browsing/model/real_time_url_lookup_service_factory.mm b/ios/chrome/browser/safe_browsing/model/real_time_url_lookup_service_factory.mm
index dcb4e2f..73c475d 100644
--- a/ios/chrome/browser/safe_browsing/model/real_time_url_lookup_service_factory.mm
+++ b/ios/chrome/browser/safe_browsing/model/real_time_url_lookup_service_factory.mm
@@ -6,7 +6,6 @@
 
 #import "base/functional/bind.h"
 #import "base/no_destructor.h"
-#import "components/keyed_service/ios/browser_state_dependency_manager.h"
 #import "components/safe_browsing/core/browser/realtime/url_lookup_service.h"
 #import "components/safe_browsing/core/browser/sync/safe_browsing_primary_account_token_fetcher.h"
 #import "components/safe_browsing/core/browser/sync/sync_utils.h"
@@ -21,11 +20,21 @@
 #import "ios/components/security_interstitials/safe_browsing/safe_browsing_service.h"
 #import "services/network/public/cpp/shared_url_loader_factory.h"
 
+namespace {
+
+// Returns the application global variation service.
+variations::VariationsService* GetVariationsService() {
+  return GetApplicationContext()->GetVariationsService();
+}
+
+}  // namespace
+
 // static
 safe_browsing::RealTimeUrlLookupService*
 RealTimeUrlLookupServiceFactory::GetForProfile(ProfileIOS* profile) {
-  return static_cast<safe_browsing::RealTimeUrlLookupService*>(
-      GetInstance()->GetServiceForBrowserState(profile, true));
+  return GetInstance()
+      ->GetServiceForProfileAs<safe_browsing::RealTimeUrlLookupService>(
+          profile, /*create=*/true);
 }
 
 // static
@@ -36,9 +45,7 @@
 }
 
 RealTimeUrlLookupServiceFactory::RealTimeUrlLookupServiceFactory()
-    : BrowserStateKeyedServiceFactory(
-          "RealTimeUrlLookupService",
-          BrowserStateDependencyManager::GetInstance()) {
+    : ProfileKeyedServiceFactoryIOS("RealTimeUrlLookupService") {
   DependsOn(IdentityManagerFactory::GetInstance());
   DependsOn(SyncServiceFactory::GetInstance());
   DependsOn(VerdictCacheManagerFactory::GetInstance());
@@ -52,6 +59,17 @@
   if (!safe_browsing_service) {
     return nullptr;
   }
+
+  // If referrer chains become supported, this callback will need to change
+  // to provide the minimum allowed timestamp instead.
+  base::RepeatingCallback<base::Time()>
+      min_allowed_timestamp_for_referrer_chains_getter = base::NullCallback();
+
+  // Referrer chain provider is currently not available on iOS. Once it
+  // is implemented, inject it to enable referrer chain in real time
+  // requests.
+  safe_browsing::ReferrerChainProvider* referrer_chain_provider = nullptr;
+
   ProfileIOS* profile = ProfileIOS::FromBrowserState(browser_state);
   return std::make_unique<safe_browsing::RealTimeUrlLookupService>(
       safe_browsing_service->GetURLLoaderFactory(),
@@ -64,21 +82,7 @@
                               AreSigninAndSyncSetUpForSafeBrowsingTokenFetches,
                           SyncServiceFactory::GetForProfile(profile),
                           IdentityManagerFactory::GetForProfile(profile)),
-      profile->IsOffTheRecord(),
-      base::BindRepeating(
-          &RealTimeUrlLookupServiceFactory::GetVariationsService),
-      // If referrer chains become supported, this callback will need to change
-      // to provide the minimum allowed timestamp instead.
-      /*min_allowed_timestamp_for_referrer_chains_getter=*/base::NullCallback(),
-      // Referrer chain provider is currently not available on iOS. Once it
-      // is implemented, inject it to enable referrer chain in real time
-      // requests.
-      /*referrer_chain_provider=*/nullptr,
+      profile->IsOffTheRecord(), base::BindRepeating(&GetVariationsService),
+      min_allowed_timestamp_for_referrer_chains_getter, referrer_chain_provider,
       /*webui_delegate=*/nullptr);
 }
-
-// static
-variations::VariationsService*
-RealTimeUrlLookupServiceFactory::GetVariationsService() {
-  return GetApplicationContext()->GetVariationsService();
-}