Create OnFileAttachedEnterpriseConnector policy

Bug: 1067631
Change-Id: Iad76528703688589797dd4aa6b6e4f25920c06f6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2135709
Reviewed-by: Gabriel Charette <[email protected]>
Reviewed-by: Sergey Poromov <[email protected]>
Reviewed-by: Roger Tawa <[email protected]>
Commit-Queue: Dominique Fauteux-Chapleau <[email protected]>
Cr-Commit-Position: refs/heads/master@{#760710}
diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn
index b8ac025..35274809 100644
--- a/chrome/browser/BUILD.gn
+++ b/chrome/browser/BUILD.gn
@@ -3184,6 +3184,8 @@
       "enterprise/connectors/common.h",
       "enterprise/connectors/connectors_manager.cc",
       "enterprise/connectors/connectors_manager.h",
+      "enterprise/connectors/connectors_prefs.cc",
+      "enterprise/connectors/connectors_prefs.h",
       "enterprise/connectors/enterprise_connectors_policy_handler.cc",
       "enterprise/connectors/enterprise_connectors_policy_handler.h",
       "enterprise/reporting/browser_report_generator.cc",
diff --git a/chrome/browser/enterprise/connectors/connectors_prefs.cc b/chrome/browser/enterprise/connectors/connectors_prefs.cc
new file mode 100644
index 0000000..a0a78d6
--- /dev/null
+++ b/chrome/browser/enterprise/connectors/connectors_prefs.cc
@@ -0,0 +1,17 @@
+// Copyright 2020 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/enterprise/connectors/connectors_prefs.h"
+
+#include "components/prefs/pref_registry_simple.h"
+
+namespace enterprise_connectors {
+
+const char kOnFileAttachedPref[] = "enterprise_connectors.on_file_attached";
+
+void RegisterLocalStatePrefs(PrefRegistrySimple* registry) {
+  registry->RegisterListPref(kOnFileAttachedPref);
+}
+
+}  // namespace enterprise_connectors
diff --git a/chrome/browser/enterprise/connectors/connectors_prefs.h b/chrome/browser/enterprise/connectors/connectors_prefs.h
new file mode 100644
index 0000000..c6ed747
--- /dev/null
+++ b/chrome/browser/enterprise/connectors/connectors_prefs.h
@@ -0,0 +1,19 @@
+// Copyright 2020 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_ENTERPRISE_CONNECTORS_CONNECTORS_PREFS_H_
+#define CHROME_BROWSER_ENTERPRISE_CONNECTORS_CONNECTORS_PREFS_H_
+
+class PrefRegistrySimple;
+
+namespace enterprise_connectors {
+
+// Pref that maps to the "OnFileAttachedEnterpriseConnector" policy.
+extern const char kOnFileAttachedPref[];
+
+void RegisterLocalStatePrefs(PrefRegistrySimple* registry);
+
+}  // namespace enterprise_connectors
+
+#endif  // CHROME_BROWSER_ENTERPRISE_CONNECTORS_CONNECTORS_PREFS_H_
diff --git a/chrome/browser/policy/configuration_policy_handler_list_factory.cc b/chrome/browser/policy/configuration_policy_handler_list_factory.cc
index 0f0833d..7d9382e 100644
--- a/chrome/browser/policy/configuration_policy_handler_list_factory.cc
+++ b/chrome/browser/policy/configuration_policy_handler_list_factory.cc
@@ -91,6 +91,8 @@
 #else  // defined(OS_ANDROID)
 #include "chrome/browser/download/default_download_dir_policy_handler.h"
 #include "chrome/browser/download/download_dir_policy_handler.h"
+#include "chrome/browser/enterprise/connectors/connectors_prefs.h"
+#include "chrome/browser/enterprise/connectors/enterprise_connectors_policy_handler.h"
 #include "chrome/browser/enterprise/reporting/extension_request_policy_handler.h"
 #include "chrome/browser/media/router/media_router_feature.h"
 #include "chrome/browser/policy/local_sync_policy_handler.h"
@@ -1427,6 +1429,13 @@
           SimpleSchemaValidatingPolicyHandler::MANDATORY_ALLOWED));
   handlers->AddHandler(
       std::make_unique<enterprise_reporting::ExtensionRequestPolicyHandler>());
+
+  // Handlers for Chrome Enterprise Connectors policies.
+  handlers->AddHandler(
+      std::make_unique<
+          enterprise_connectors::EnterpriseConnectorsPolicyHandler>(
+          key::kOnFileAttachedEnterpriseConnector,
+          enterprise_connectors::kOnFileAttachedPref, chrome_schema));
 #endif  // defined(OS_ANDROID)
 
 #if defined(OS_CHROMEOS)
diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc
index de464f38..cda1b54 100644
--- a/chrome/browser/prefs/browser_prefs.cc
+++ b/chrome/browser/prefs/browser_prefs.cc
@@ -23,6 +23,7 @@
 #include "chrome/browser/devtools/devtools_window.h"
 #include "chrome/browser/download/download_prefs.h"
 #include "chrome/browser/engagement/important_sites_util.h"
+#include "chrome/browser/enterprise/connectors/connectors_prefs.h"
 #include "chrome/browser/external_protocol/external_protocol_handler.h"
 #include "chrome/browser/first_run/first_run.h"
 #include "chrome/browser/gpu/gpu_mode_manager.h"
@@ -675,6 +676,7 @@
 #if defined(OS_ANDROID)
   ::android::RegisterPrefs(registry);
 #else
+  enterprise_connectors::RegisterLocalStatePrefs(registry);
   enterprise_reporting::RegisterLocalStatePrefs(registry);
   gcm::RegisterPrefs(registry);
   media_router::RegisterLocalStatePrefs(registry);
diff --git a/chrome/browser/safe_browsing/cloud_content_scanning/deep_scanning_dialog_delegate.cc b/chrome/browser/safe_browsing/cloud_content_scanning/deep_scanning_dialog_delegate.cc
index a46e393..5d82720 100644
--- a/chrome/browser/safe_browsing/cloud_content_scanning/deep_scanning_dialog_delegate.cc
+++ b/chrome/browser/safe_browsing/cloud_content_scanning/deep_scanning_dialog_delegate.cc
@@ -403,10 +403,7 @@
     : web_contents_(web_contents),
       data_(std::move(data)),
       callback_(std::move(callback)),
-      access_point_(access_point),
-      handler_("CheckContentCompliance",
-               prefs::kCheckContentCompliance,
-               policy::GetChromeSchema()) {
+      access_point_(access_point) {
   DCHECK(web_contents_);
   result_.text_results.resize(data_.text.size(), false);
   result_.paths_results.resize(data_.paths.size(), false);
diff --git a/chrome/browser/safe_browsing/cloud_content_scanning/deep_scanning_dialog_delegate.h b/chrome/browser/safe_browsing/cloud_content_scanning/deep_scanning_dialog_delegate.h
index b1e5bdb..be71f23 100644
--- a/chrome/browser/safe_browsing/cloud_content_scanning/deep_scanning_dialog_delegate.h
+++ b/chrome/browser/safe_browsing/cloud_content_scanning/deep_scanning_dialog_delegate.h
@@ -17,7 +17,6 @@
 #include "base/strings/string16.h"
 #include "base/time/time.h"
 #include "chrome/browser/enterprise/connectors/connectors_manager.h"
-#include "chrome/browser/enterprise/connectors/enterprise_connectors_policy_handler.h"
 #include "chrome/browser/safe_browsing/cloud_content_scanning/binary_upload_service.h"
 #include "chrome/browser/safe_browsing/cloud_content_scanning/deep_scanning_utils.h"
 #include "chrome/browser/ui/tab_modal_confirm_dialog.h"
@@ -365,12 +364,6 @@
 
   base::TimeTicks upload_start_time_;
 
-  // TODO(domfc): This is added here so EnterpriseConnectorsPolicyHandler's
-  // tests work. The issue is that a new string used by the handler is being
-  // removed from certain tests because it's unused in prod code for now, so
-  // |handler_| can be removed once that's no longer the case.
-  enterprise_connectors::EnterpriseConnectorsPolicyHandler handler_;
-
   base::WeakPtrFactory<DeepScanningDialogDelegate> weak_ptr_factory_{this};
 };
 
diff --git a/chrome/test/data/policy/policy_test_cases.json b/chrome/test/data/policy/policy_test_cases.json
index cb052a3..6cabad6 100644
--- a/chrome/test/data/policy/policy_test_cases.json
+++ b/chrome/test/data/policy/policy_test_cases.json
@@ -6920,6 +6920,41 @@
     ]
   },
 
+  "OnFileAttachedEnterpriseConnector": {
+    "os": ["win", "linux", "mac", "chromeos"],
+    "policy_pref_mapping_test": [
+      {
+        "policies": {
+          "OnFileAttachedEnterpriseConnector": [
+            {
+              "service_provider": "Google",
+              "enable": [
+                {
+                  "url_list": ["*"],
+                  "tags": ["malware"]
+                },
+                {
+                  "url_list": ["*.them.com", "*.others.com"],
+                  "tags": ["dlp"]
+                }
+              ],
+              "disable": [
+                {
+                  "url_list": ["*.us.com"],
+                  "tags": ["malware"]
+                }
+              ],
+              "block_until_verdict": 0,
+              "block_password_protected": true,
+              "block_large_files": false
+            }
+          ]
+        },
+        "prefs": { "enterprise_connectors.on_file_attached": { "local_state": true } }
+      }
+    ]
+  },
+
   "RendererCodeIntegrityEnabled": {
     "os": ["win"],
     "policy_pref_mapping_test": [