Reland "Reland "[PolicyLogs] Adding chrome://policy/logs on Desktop""

The issue that caused the revert in crrev.com/c/4616067 has been
fixed by crrev.com/c/4626859. The policy logger no longer posts
tasks to a sequence. The lines changed in the files of this CL are
the same as the original reland.

chrome://policy/logs is already available on Android and enabled by
default. This CL brings chrome://policy/logs to desktop behind a
feature flag that is enabled by default.

Bug: b/282733597
Change-Id: I3eaadf0a07a009ed1d2e423dd7024eb89a939155
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4654277
Reviewed-by: Demetrios Papadopoulos <[email protected]>
Commit-Queue: Salma Elmahallawy <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1164140}
diff --git a/chrome/browser/ui/webui/policy/policy_ui.cc b/chrome/browser/ui/webui/policy/policy_ui.cc
index 5547f40..d96bf35 100644
--- a/chrome/browser/ui/webui/policy/policy_ui.cc
+++ b/chrome/browser/ui/webui/policy/policy_ui.cc
@@ -1,3 +1,4 @@
+
 // Copyright 2012 The Chromium Authors
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
@@ -6,6 +7,9 @@
 
 #include <memory>
 
+#include "base/json/json_writer.h"
+#include "base/strings/stringprintf.h"
+#include "base/system/sys_info.h"
 #include "build/build_config.h"
 #include "build/chromeos_buildflags.h"
 #include "chrome/browser/policy/value_provider/chrome_policies_value_provider.h"
@@ -17,33 +21,27 @@
 #include "components/grit/policy_resources.h"
 #include "components/grit/policy_resources_map.h"
 #include "components/policy/core/common/features.h"
+#include "components/policy/core/common/policy_logger.h"
 #include "components/policy/core/common/policy_pref_names.h"
 #include "components/policy/core/common/policy_utils.h"
 #include "components/prefs/pref_registry_simple.h"
 #include "components/strings/grit/components_strings.h"
+#include "components/version_info/version_info.h"
+#include "components/version_ui/version_handler_helper.h"
 #include "content/public/browser/web_ui.h"
 #include "content/public/browser/web_ui_controller.h"
 #include "content/public/browser/web_ui_message_handler.h"
+#include "content/public/common/user_agent.h"
 #include "services/network/public/mojom/content_security_policy.mojom.h"
 #include "ui/base/webui/web_ui_util.h"
 
-#if BUILDFLAG(IS_ANDROID)
-#include "base/json/json_writer.h"
-#include "base/strings/stringprintf.h"
-#include "base/system/sys_info.h"
-#include "components/policy/core/common/policy_logger.h"
-#include "components/version_info/version_info.h"
-#include "components/version_ui/version_handler_helper.h"
-#include "content/public/common/user_agent.h"
-#endif  // BUILDFLAG(IS_ANDROID)
-
 namespace {
 
-#if BUILDFLAG(IS_ANDROID)
 // Returns the operating system information to be displayed on
 // chrome://policy/logs page.
 std::string GetOsInfo() {
-  // The base format for the OS version and build
+#if BUILDFLAG(IS_ANDROID)
+  // The base format for the OS version and build.
   constexpr char kOSVersionAndBuildFormat[] = "Android %s %s";
   return base::StringPrintf(
       kOSVersionAndBuildFormat,
@@ -51,6 +49,11 @@
       (content::GetAndroidOSInfo(content::IncludeAndroidBuildNumber::Include,
                                  content::IncludeAndroidModel::Include))
           .c_str());
+#else
+  return base::StringPrintf("%s %s",
+                            base::SysInfo::OperatingSystemName().c_str(),
+                            base::SysInfo::OperatingSystemVersion().c_str());
+#endif  //  BUILDFLAG (IS_ANDROID)
 }
 
 // Returns the version information to be displayed on the chrome://policy/logs
@@ -65,7 +68,6 @@
 
   return version_info;
 }
-#endif
 
 void CreateAndAddPolicyUIHtmlSource(Profile* profile) {
   content::WebUIDataSource* source = content::WebUIDataSource::CreateAndAdd(
@@ -150,7 +152,6 @@
   };
   source->AddLocalizedStrings(kPolicyLogsStrings);
 
-#if BUILDFLAG(IS_ANDROID)
   source->AddBoolean(
       "loggingEnabled",
       policy::PolicyLogger::GetInstance()->IsPolicyLoggingEnabled());
@@ -164,7 +165,6 @@
 
   source->AddResourcePath("logs/", IDR_POLICY_LOGS_POLICY_LOGS_HTML);
   source->AddResourcePath("logs", IDR_POLICY_LOGS_POLICY_LOGS_HTML);
-#endif  // BUILDFLAG(IS_ANDROID)
 
   if (policy::utils::IsPolicyTestingEnabled(profile->GetPrefs())) {
     // Localized strings for chrome://policy/test.
diff --git a/chrome/browser/ui/webui/policy/policy_ui_handler.cc b/chrome/browser/ui/webui/policy/policy_ui_handler.cc
index 60771960..76f44fa 100644
--- a/chrome/browser/ui/webui/policy/policy_ui_handler.cc
+++ b/chrome/browser/ui/webui/policy/policy_ui_handler.cc
@@ -58,6 +58,7 @@
 #include "components/policy/core/common/cloud/cloud_policy_refresh_scheduler.h"
 #include "components/policy/core/common/cloud/cloud_policy_util.h"
 #include "components/policy/core/common/policy_details.h"
+#include "components/policy/core/common/policy_logger.h"
 #include "components/policy/core/common/policy_scheduler.h"
 #include "components/policy/core/common/policy_types.h"
 #include "components/policy/core/common/remote_commands/remote_commands_service.h"
@@ -76,10 +77,6 @@
 #include "ui/base/l10n/l10n_util.h"
 #include "ui/base/webui/web_ui_util.h"
 
-#if BUILDFLAG(IS_ANDROID)
-#include "components/policy/core/common/policy_logger.h"
-#endif  // BUILDFLAG(IS_ANDROID)
-
 #if BUILDFLAG(IS_CHROMEOS_ASH)
 #include "chrome/browser/ash/policy/core/browser_policy_connector_ash.h"
 #include "chrome/browser/ash/policy/core/device_cloud_policy_store_ash.h"
@@ -183,12 +180,10 @@
       base::BindRepeating(&PolicyUIHandler::HandleCopyPoliciesJson,
                           base::Unretained(this)));
 
-#if BUILDFLAG(IS_ANDROID)
   web_ui()->RegisterMessageCallback(
       "getPolicyLogs",
       base::BindRepeating(&PolicyUIHandler::HandleGetPolicyLogs,
                           base::Unretained(this)));
-#endif  // BUILDFLAG(IS_ANDROID)
 
 #if !BUILDFLAG(IS_CHROMEOS)
   web_ui()->RegisterMessageCallback(
@@ -310,14 +305,12 @@
   scw.WriteText(base::UTF8ToUTF16(policies_json));
 }
 
-#if BUILDFLAG(IS_ANDROID)
 void PolicyUIHandler::HandleGetPolicyLogs(const base::Value::List& args) {
   DCHECK(policy::PolicyLogger::GetInstance()->IsPolicyLoggingEnabled());
   AllowJavascript();
   ResolveJavascriptCallback(args[0],
                             policy::PolicyLogger::GetInstance()->GetAsList());
 }
-#endif  // BUILDFLAG(IS_ANDROID)
 
 #if !BUILDFLAG(IS_CHROMEOS)
 void PolicyUIHandler::HandleUploadReport(const base::Value::List& args) {
diff --git a/chrome/browser/ui/webui/policy/policy_ui_handler.h b/chrome/browser/ui/webui/policy/policy_ui_handler.h
index 0ea02c0..5860623 100644
--- a/chrome/browser/ui/webui/policy/policy_ui_handler.h
+++ b/chrome/browser/ui/webui/policy/policy_ui_handler.h
@@ -65,10 +65,8 @@
   void HandleUploadReport(const base::Value::List& args);
 #endif
 
-#if BUILDFLAG(IS_ANDROID)
   // Handler functions for chrome://policy/logs.
   void HandleGetPolicyLogs(const base::Value::List& args);
-#endif  // BUILDFLAG(IS_ANDROID)
 
   // Send information about the current policy values to the UI. Information is
   // sent in two parts to the UI: