Add option to use KidsManagement url checker according to flag.

feature(supervised_user_url_filter): use KidsManagementURLCheckerClient

BUG=934444

Change-Id: I91461a92721b74620722b895a5ecf743f15ae56b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1481493
Commit-Queue: Caio Lima <caiol@google.com>
Reviewed-by: Marc Treib <treib@chromium.org>
Reviewed-by: Michael Giuffrida <michaelpg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#643366}
diff --git a/chrome/browser/supervised_user/supervised_user_service.cc b/chrome/browser/supervised_user/supervised_user_service.cc
index efc8fbb..4cda49bd 100644
--- a/chrome/browser/supervised_user/supervised_user_service.cc
+++ b/chrome/browser/supervised_user/supervised_user_service.cc
@@ -4,6 +4,7 @@
 
 #include "chrome/browser/supervised_user/supervised_user_service.h"
 
+#include <set>
 #include <utility>
 
 #include "base/bind.h"
@@ -565,12 +566,14 @@
   bool use_online_check =
       supervised_users::IsSafeSitesOnlineCheckEnabled(profile_);
   if (use_online_check != url_filter_.HasAsyncURLChecker()) {
-    if (use_online_check)
+    if (use_online_check) {
       url_filter_.InitAsyncURLChecker(
           content::BrowserContext::GetDefaultStoragePartition(profile_)
-              ->GetURLLoaderFactoryForBrowserProcess());
-    else
+              ->GetURLLoaderFactoryForBrowserProcess(),
+          IdentityManagerFactory::GetForProfile(profile_));
+    } else {
       url_filter_.ClearAsyncURLChecker();
+    }
   }
 }
 
diff --git a/chrome/browser/supervised_user/supervised_user_url_filter.cc b/chrome/browser/supervised_user/supervised_user_url_filter.cc
index adcb55a..44ed513 100644
--- a/chrome/browser/supervised_user/supervised_user_url_filter.cc
+++ b/chrome/browser/supervised_user/supervised_user_url_filter.cc
@@ -23,7 +23,10 @@
 #include "base/task/post_task.h"
 #include "base/task_runner_util.h"
 #include "chrome/browser/browser_process.h"
+#include "chrome/browser/signin/identity_manager_factory.h"
 #include "chrome/browser/supervised_user/experimental/supervised_user_blacklist.h"
+#include "chrome/browser/supervised_user/kids_management_url_checker_client.h"
+#include "chrome/common/chrome_features.h"
 #include "components/policy/core/browser/url_blacklist_manager.h"
 #include "components/policy/core/browser/url_util.h"
 #include "components/safe_search_api/safe_search/safe_search_url_checker_client.h"
@@ -518,9 +521,27 @@
 }
 
 void SupervisedUserURLFilter::InitAsyncURLChecker(
-    scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory) {
-  net::NetworkTrafficAnnotationTag traffic_annotation =
-      net::DefineNetworkTrafficAnnotation("supervised_user_url_filter", R"(
+    scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
+    identity::IdentityManager* identity_manager) {
+  std::string country;
+  variations::VariationsService* variations_service =
+      g_browser_process->variations_service();
+  if (variations_service) {
+    country = variations_service->GetStoredPermanentCountry();
+    if (country.empty())
+      country = variations_service->GetLatestCountry();
+  }
+
+  std::unique_ptr<safe_search_api::URLCheckerClient> url_checker_client;
+
+  if ((base::FeatureList::IsEnabled(
+          features::kKidsManagementUrlClassification))) {
+    url_checker_client = std::make_unique<KidsManagementURLCheckerClient>(
+        std::move(url_loader_factory), country, identity_manager);
+  } else {
+    // TODO(crbug.com/940454): remove safe_search_checker
+    net::NetworkTrafficAnnotationTag traffic_annotation =
+        net::DefineNetworkTrafficAnnotation("supervised_user_url_filter", R"(
         semantics {
           sender: "Supervised Users"
           description:
@@ -540,20 +561,13 @@
             "family dashboard."
           policy_exception_justification: "Not implemented."
         })");
-
-  // Prefer using the permanent stored country, which may be unavailable during
-  // the first run. In that case, try to use the latest country instead.
-  std::string country;
-  variations::VariationsService* variations_service =
-      g_browser_process->variations_service();
-  if (variations_service) {
-    country = variations_service->GetStoredPermanentCountry();
-    if (country.empty())
-      country = variations_service->GetLatestCountry();
+    url_checker_client =
+        std::make_unique<safe_search_api::SafeSearchURLCheckerClient>(
+            std::move(url_loader_factory), traffic_annotation, country);
   }
+
   async_url_checker_ = std::make_unique<safe_search_api::URLChecker>(
-      std::make_unique<safe_search_api::SafeSearchURLCheckerClient>(
-          std::move(url_loader_factory), traffic_annotation, country));
+      std::move(url_checker_client));
 }
 
 void SupervisedUserURLFilter::ClearAsyncURLChecker() {
diff --git a/chrome/browser/supervised_user/supervised_user_url_filter.h b/chrome/browser/supervised_user/supervised_user_url_filter.h
index 6e9cf36..bdb7026f 100644
--- a/chrome/browser/supervised_user/supervised_user_url_filter.h
+++ b/chrome/browser/supervised_user/supervised_user_url_filter.h
@@ -23,6 +23,10 @@
 class GURL;
 class SupervisedUserBlacklist;
 
+namespace identity {
+class IdentityManager;
+}
+
 namespace base {
 class TaskRunner;
 }
@@ -152,7 +156,8 @@
 
   // Initializes the experimental asynchronous checker.
   void InitAsyncURLChecker(
-      scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory);
+      scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
+      identity::IdentityManager* identity_manager);
 
   // Clears any asynchronous checker.
   void ClearAsyncURLChecker();
diff --git a/chrome/common/chrome_features.cc b/chrome/common/chrome_features.cc
index 04aec29..a4f9cae 100644
--- a/chrome/common/chrome_features.cc
+++ b/chrome/common/chrome_features.cc
@@ -370,6 +370,11 @@
 };
 #endif  // !defined(OS_ANDROID)
 
+// Uses KidsManagement UrlClassification instead of SafeSearch for supervised
+// accounts.
+const base::Feature kKidsManagementUrlClassification{
+    "KidsManagementUrlClassification", base::FEATURE_DISABLED_BY_DEFAULT};
+
 #if !defined(OS_ANDROID)
 // Enables Casting a Presentation API-enabled website to a secondary display.
 const base::Feature kLocalScreenCasting{"LocalScreenCasting",
diff --git a/chrome/common/chrome_features.h b/chrome/common/chrome_features.h
index af45cf7..4a03d46 100644
--- a/chrome/common/chrome_features.h
+++ b/chrome/common/chrome_features.h
@@ -238,6 +238,9 @@
 extern const base::Feature kIntentPicker;
 #endif
 
+COMPONENT_EXPORT(CHROME_FEATURES)
+extern const base::Feature kKidsManagementUrlClassification;
+
 #if !defined(OS_ANDROID)
 COMPONENT_EXPORT(CHROME_FEATURES)
 extern const base::Feature kLocalScreenCasting;