[Segmentation] Adding internal page for segmentation platform
This CL adds a simple internal page for segmentation, it allows devs
to check the optimization targets by segment key.
Will add more features to this page to allow checking of system
status, available segments, etc.
BUG=1271839
Change-Id: I98599befa308babe226c84442ef75cca507e304a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3296844
Commit-Queue: Min Qin <[email protected]>
Reviewed-by: Robert Sesek <[email protected]>
Reviewed-by: calamity <[email protected]>
Cr-Commit-Position: refs/heads/main@{#946509}
diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn
index f37e340..b1577af 100644
--- a/chrome/browser/BUILD.gn
+++ b/chrome/browser/BUILD.gn
@@ -2019,6 +2019,7 @@
"//chrome/browser/ui/webui/read_later/side_panel:mojo_bindings",
"//chrome/browser/ui/webui/realbox:mojo_bindings",
"//chrome/browser/ui/webui/reset_password:mojo_bindings",
+ "//chrome/browser/ui/webui/segmentation_internals:mojo_bindings",
"//chrome/browser/ui/webui/tab_search:mojo_bindings",
"//chrome/browser/ui/webui/usb_internals:mojo_bindings",
"//chrome/browser/updates/announcement_notification",
diff --git a/chrome/browser/chrome_browser_interface_binders.cc b/chrome/browser/chrome_browser_interface_binders.cc
index 3642554..b205cbd 100644
--- a/chrome/browser/chrome_browser_interface_binders.cc
+++ b/chrome/browser/chrome_browser_interface_binders.cc
@@ -40,6 +40,7 @@
#include "chrome/browser/ui/webui/media/media_history_ui.h"
#include "chrome/browser/ui/webui/omnibox/omnibox.mojom.h"
#include "chrome/browser/ui/webui/omnibox/omnibox_ui.h"
+#include "chrome/browser/ui/webui/segmentation_internals/segmentation_internals_ui.h"
#include "chrome/browser/ui/webui/usb_internals/usb_internals.mojom.h"
#include "chrome/browser/ui/webui/usb_internals/usb_internals_ui.h"
#include "chrome/common/chrome_features.h"
@@ -694,6 +695,10 @@
RegisterWebUIControllerInterfaceBinder<federated_learning::mojom::PageHandler,
FlocInternalsUI>(map);
+ RegisterWebUIControllerInterfaceBinder<
+ segmentation_internals::mojom::PageHandlerFactory,
+ SegmentationInternalsUI>(map);
+
#if defined(OS_WIN) || defined(OS_MAC) || defined(OS_LINUX) || \
BUILDFLAG(IS_CHROMEOS_ASH)
RegisterWebUIControllerInterfaceBinder<
diff --git a/chrome/browser/resources/BUILD.gn b/chrome/browser/resources/BUILD.gn
index cf761c9..2a525b3a 100644
--- a/chrome/browser/resources/BUILD.gn
+++ b/chrome/browser/resources/BUILD.gn
@@ -18,7 +18,7 @@
assert(!is_ios, "Chromium/iOS shouldn't use anything in //chrome")
group("resources") {
- public_deps = []
+ public_deps = [ "segmentation_internals:resources" ]
if (!is_android) {
public_deps += [
diff --git a/chrome/browser/resources/segmentation_internals/BUILD.gn b/chrome/browser/resources/segmentation_internals/BUILD.gn
new file mode 100644
index 0000000..b60e7d0e
--- /dev/null
+++ b/chrome/browser/resources/segmentation_internals/BUILD.gn
@@ -0,0 +1,75 @@
+# Copyright 2021 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.
+
+import("//chrome/common/features.gni")
+import("//tools/grit/grit_rule.gni")
+import("//tools/polymer/html_to_js.gni")
+import("//tools/typescript/ts_library.gni")
+import("//ui/webui/resources/tools/generate_grd.gni")
+
+tsc_folder = "tsc"
+
+grit("resources") {
+ defines = chrome_grit_defines
+
+ # These arguments are needed since the grd is generated at build time.
+ enable_input_discovery_for_gn_analyze = false
+ source = "$target_gen_dir/resources.grd"
+ deps = [ ":build_grd" ]
+
+ outputs = [
+ "grit/segmentation_internals_resources.h",
+ "grit/segmentation_internals_resources_map.cc",
+ "grit/segmentation_internals_resources_map.h",
+ "segmentation_internals_resources.pak",
+ ]
+ output_dir = "$root_gen_dir/chrome"
+}
+
+generate_grd("build_grd") {
+ grd_prefix = "segmentation_internals"
+ out_grd = "$target_gen_dir/resources.grd"
+ deps = [ ":build_ts" ]
+ manifest_files = [ "$target_gen_dir/tsconfig.manifest" ]
+ input_files = [ "segmentation_internals.html" ]
+ input_files_base_dir = rebase_path(".", "//")
+}
+
+html_to_js("web_components") {
+ js_files = [ "segmentation_internals.ts" ]
+}
+
+copy("copy_proxy") {
+ sources = [ "segmentation_internals_browser_proxy.ts" ]
+ outputs = [ "$target_gen_dir/{{source_file_part}}" ]
+}
+
+copy("copy_mojo") {
+ deps = [
+ "//chrome/browser/ui/webui/segmentation_internals:mojo_bindings_webui_js",
+ ]
+ mojom_folder = "$root_gen_dir/mojom-webui/chrome/browser/ui/webui/segmentation_internals/"
+ sources = [ "$mojom_folder/segmentation_internals.mojom-webui.js" ]
+ outputs = [ "$target_gen_dir/{{source_file_part}}" ]
+}
+
+ts_library("build_ts") {
+ root_dir = "$target_gen_dir"
+ out_dir = "$target_gen_dir/$tsc_folder"
+ tsconfig_base = "tsconfig_base.json"
+ in_files = [
+ "segmentation_internals.ts",
+ "segmentation_internals_browser_proxy.ts",
+ "segmentation_internals.mojom-webui.js",
+ ]
+ deps = [
+ "//ui/webui/resources:library",
+ "//ui/webui/resources/js/browser_command:build_ts",
+ ]
+ extra_deps = [
+ ":copy_mojo",
+ ":copy_proxy",
+ ":web_components",
+ ]
+}
diff --git a/chrome/browser/resources/segmentation_internals/OWNERS b/chrome/browser/resources/segmentation_internals/OWNERS
new file mode 100644
index 0000000..b3f32429
--- /dev/null
+++ b/chrome/browser/resources/segmentation_internals/OWNERS
@@ -0,0 +1 @@
+file://components/segmentation_platform/OWNERS
\ No newline at end of file
diff --git a/chrome/browser/resources/segmentation_internals/segmentation_internals.html b/chrome/browser/resources/segmentation_internals/segmentation_internals.html
new file mode 100644
index 0000000..09db8ab2
--- /dev/null
+++ b/chrome/browser/resources/segmentation_internals/segmentation_internals.html
@@ -0,0 +1,26 @@
+<!doctype html>
+<html lang="en" dir="ltr">
+ <head>
+ <meta charset="utf-8">
+ <title>Segmentation Internals</title>
+ <meta name="viewport" content="width=device-width">
+ <link rel="stylesheet" href="chrome://resources/css/text_defaults.css">
+ </head>
+ <body>
+ <h1>Segmentation Internals</h1>
+ <h4>Get segment</h4>
+ <div>
+ <Label for="segment-key">Segment key:</Label>
+ <input type="text" id="segment-key">
+ <button id="get-segment">Get segment result</button>
+ </div>
+ <h4>Segment result</h4>
+ <div>
+ Is ready: <span id="is-ready"></span>
+ </div>
+ <div>
+ Optimization target: <span id="optimization-target"></span>
+ </div>
+ <script type="module" src="segmentation_internals.js"></script>
+ </body>
+</html>
diff --git a/chrome/browser/resources/segmentation_internals/segmentation_internals.ts b/chrome/browser/resources/segmentation_internals/segmentation_internals.ts
new file mode 100644
index 0000000..688ef83c
--- /dev/null
+++ b/chrome/browser/resources/segmentation_internals/segmentation_internals.ts
@@ -0,0 +1,22 @@
+// Copyright 2021 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.
+
+import {$} from 'chrome://resources/js/util.m.js';
+
+import {SegmentationInternalsBrowserProxy} from './segmentation_internals_browser_proxy.js';
+
+function getProxy(): SegmentationInternalsBrowserProxy {
+ return SegmentationInternalsBrowserProxy.getInstance();
+}
+
+function initialize() {
+ $('get-segment').onclick = async function() {
+ const {result} = await getProxy().getSegment(
+ ($('segment-key') as HTMLInputElement).value);
+ $('is-ready').textContent = String(result.isReady);
+ $('optimization-target').textContent = String(result.optimizationTarget);
+ };
+}
+
+document.addEventListener('DOMContentLoaded', initialize);
diff --git a/chrome/browser/resources/segmentation_internals/segmentation_internals_browser_proxy.ts b/chrome/browser/resources/segmentation_internals/segmentation_internals_browser_proxy.ts
new file mode 100644
index 0000000..0511df3
--- /dev/null
+++ b/chrome/browser/resources/segmentation_internals/segmentation_internals_browser_proxy.ts
@@ -0,0 +1,25 @@
+// Copyright 2021 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.
+
+import {PageHandlerFactory, PageHandlerRemote} from './segmentation_internals.mojom-webui.js';
+
+export class SegmentationInternalsBrowserProxy {
+ private handler: PageHandlerRemote;
+
+ constructor() {
+ this.handler = new PageHandlerRemote();
+ const factory = PageHandlerFactory.getRemote();
+ factory.createPageHandler(this.handler.$.bindNewPipeAndPassReceiver());
+ }
+
+ getSegment(key: string) {
+ return this.handler.getSegment(key);
+ }
+
+ static getInstance(): SegmentationInternalsBrowserProxy {
+ return instance || (instance = new SegmentationInternalsBrowserProxy());
+ }
+}
+
+let instance: SegmentationInternalsBrowserProxy|null = null;
diff --git a/chrome/browser/resources/segmentation_internals/tsconfig_base.json b/chrome/browser/resources/segmentation_internals/tsconfig_base.json
new file mode 100644
index 0000000..f078dc06
--- /dev/null
+++ b/chrome/browser/resources/segmentation_internals/tsconfig_base.json
@@ -0,0 +1,6 @@
+{
+ "extends": "../../../../tools/typescript/tsconfig_base.json",
+ "compilerOptions": {
+ "allowJs": true
+ }
+}
diff --git a/chrome/browser/ui/BUILD.gn b/chrome/browser/ui/BUILD.gn
index 12a02b2..9829438 100644
--- a/chrome/browser/ui/BUILD.gn
+++ b/chrome/browser/ui/BUILD.gn
@@ -306,6 +306,10 @@
"webui/quota_internals/quota_internals_types.h",
"webui/quota_internals/quota_internals_ui.cc",
"webui/quota_internals/quota_internals_ui.h",
+ "webui/segmentation_internals/segmentation_internals_page_handler_impl.cc",
+ "webui/segmentation_internals/segmentation_internals_page_handler_impl.h",
+ "webui/segmentation_internals/segmentation_internals_ui.cc",
+ "webui/segmentation_internals/segmentation_internals_ui.h",
"webui/signin_internals_ui.cc",
"webui/signin_internals_ui.h",
"webui/support_tool_ui.cc",
@@ -432,6 +436,7 @@
"//chrome/browser/ui/webui/read_later/side_panel:mojo_bindings",
"//chrome/browser/ui/webui/read_later/side_panel/reader_mode:mojo_bindings",
"//chrome/browser/ui/webui/realbox:mojo_bindings",
+ "//chrome/browser/ui/webui/segmentation_internals:mojo_bindings",
"//chrome/browser/ui/webui/tab_search:mojo_bindings",
"//chrome/browser/ui/webui/usb_internals:mojo_bindings",
"//chrome/browser/video_tutorials",
@@ -554,6 +559,7 @@
"//components/security_interstitials/core:unsafe_resource",
"//components/security_state/content",
"//components/security_state/core",
+ "//components/segmentation_platform/public",
"//components/send_tab_to_self",
"//components/sessions",
"//components/signin/core/browser",
diff --git a/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc b/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc
index 77d70ebc6..fb7b4c05 100644
--- a/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc
+++ b/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc
@@ -56,6 +56,7 @@
#include "chrome/browser/ui/webui/policy/policy_ui.h"
#include "chrome/browser/ui/webui/predictors/predictors_ui.h"
#include "chrome/browser/ui/webui/quota_internals/quota_internals_ui.h"
+#include "chrome/browser/ui/webui/segmentation_internals/segmentation_internals_ui.h"
#include "chrome/browser/ui/webui/signin_internals_ui.h"
#include "chrome/browser/ui/webui/support_tool_ui.h"
#include "chrome/browser/ui/webui/sync_internals/sync_internals_ui.h"
@@ -682,6 +683,8 @@
return &NewWebUI<QuotaInternalsUI>;
if (url.host_piece() == safe_browsing::kChromeUISafeBrowsingHost)
return &NewWebUI<safe_browsing::SafeBrowsingUI>;
+ if (url.host_piece() == chrome::kChromeUISegmentationInternalsHost)
+ return &NewWebUI<SegmentationInternalsUI>;
if (url.host_piece() == chrome::kChromeUISignInInternalsHost)
return &NewWebUI<SignInInternalsUI>;
if (url.host_piece() == chrome::kChromeUISupervisedUserPassphrasePageHost)
diff --git a/chrome/browser/ui/webui/segmentation_internals/BUILD.gn b/chrome/browser/ui/webui/segmentation_internals/BUILD.gn
new file mode 100644
index 0000000..63869a54
--- /dev/null
+++ b/chrome/browser/ui/webui/segmentation_internals/BUILD.gn
@@ -0,0 +1,10 @@
+# Copyright 2021 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.
+
+import("//mojo/public/tools/bindings/mojom.gni")
+
+mojom("mojo_bindings") {
+ sources = [ "segmentation_internals.mojom" ]
+ webui_module_path = "/"
+}
diff --git a/chrome/browser/ui/webui/segmentation_internals/OWNERS b/chrome/browser/ui/webui/segmentation_internals/OWNERS
new file mode 100644
index 0000000..849263b
--- /dev/null
+++ b/chrome/browser/ui/webui/segmentation_internals/OWNERS
@@ -0,0 +1,4 @@
+file://components/segmentation_platform/OWNERS
+
+per-file *.mojom=set noparent
+per-file *.mojom=file://ipc/SECURITY_OWNERS
diff --git a/chrome/browser/ui/webui/segmentation_internals/segmentation_internals.mojom b/chrome/browser/ui/webui/segmentation_internals/segmentation_internals.mojom
new file mode 100644
index 0000000..5b4c0b9d
--- /dev/null
+++ b/chrome/browser/ui/webui/segmentation_internals/segmentation_internals.mojom
@@ -0,0 +1,28 @@
+// Copyright 2021 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.
+
+module segmentation_internals.mojom;
+
+// Encapsulates information related to a selected segment. The information
+// includes whether the segment is ready and its optimization target.
+struct SegmentData {
+ // Whether the segment is ready.
+ bool is_ready;
+
+ // Enum value from components/optimization_guide/proto/models.proto. Or -1
+ // if the optimization target is empty.
+ int32 optimization_target;
+};
+
+// Used by the WebUI page to bootstrap bidirectional communication.
+interface PageHandlerFactory {
+ // The WebUI calls this method when the page is first initialized.
+ CreatePageHandler(pending_receiver<PageHandler> handler);
+};
+
+// Browser-side handler for requests from WebUI page.
+interface PageHandler {
+ // Gets the segment result for a given key.
+ GetSegment(string key) => (SegmentData result);
+};
diff --git a/chrome/browser/ui/webui/segmentation_internals/segmentation_internals_page_handler_impl.cc b/chrome/browser/ui/webui/segmentation_internals/segmentation_internals_page_handler_impl.cc
new file mode 100644
index 0000000..cd3ff0d
--- /dev/null
+++ b/chrome/browser/ui/webui/segmentation_internals/segmentation_internals_page_handler_impl.cc
@@ -0,0 +1,40 @@
+// Copyright 2021 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/ui/webui/segmentation_internals/segmentation_internals_page_handler_impl.h"
+
+#include "base/bind.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/segmentation_platform/segmentation_platform_service_factory.h"
+#include "components/segmentation_platform/public/segmentation_platform_service.h"
+
+SegmentationInternalsPageHandlerImpl::SegmentationInternalsPageHandlerImpl(
+ mojo::PendingReceiver<segmentation_internals::mojom::PageHandler> receiver,
+ Profile* profile)
+ : receiver_(this, std::move(receiver)),
+ segmentation_platform_service_(
+ segmentation_platform::SegmentationPlatformServiceFactory::
+ GetForProfile(profile)) {}
+
+SegmentationInternalsPageHandlerImpl::~SegmentationInternalsPageHandlerImpl() =
+ default;
+
+void SegmentationInternalsPageHandlerImpl::GetSegment(
+ const std::string& key,
+ GetSegmentCallback callback) {
+ segmentation_platform_service_->GetSelectedSegment(
+ key, base::BindOnce(
+ &SegmentationInternalsPageHandlerImpl::OnGetSelectedSegmentDone,
+ weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
+}
+
+void SegmentationInternalsPageHandlerImpl::OnGetSelectedSegmentDone(
+ GetSegmentCallback callback,
+ const segmentation_platform::SegmentSelectionResult& result) {
+ auto segment_data = segmentation_internals::mojom::SegmentData::New();
+ segment_data->is_ready = result.is_ready;
+ segment_data->optimization_target =
+ result.segment ? result.segment.value() : -1;
+ std::move(callback).Run(std::move(segment_data));
+}
diff --git a/chrome/browser/ui/webui/segmentation_internals/segmentation_internals_page_handler_impl.h b/chrome/browser/ui/webui/segmentation_internals/segmentation_internals_page_handler_impl.h
new file mode 100644
index 0000000..9162c2f
--- /dev/null
+++ b/chrome/browser/ui/webui/segmentation_internals/segmentation_internals_page_handler_impl.h
@@ -0,0 +1,52 @@
+// Copyright 2021 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_UI_WEBUI_SEGMENTATION_INTERNALS_SEGMENTATION_INTERNALS_PAGE_HANDLER_IMPL_H_
+#define CHROME_BROWSER_UI_WEBUI_SEGMENTATION_INTERNALS_SEGMENTATION_INTERNALS_PAGE_HANDLER_IMPL_H_
+
+#include <string>
+
+#include "base/memory/weak_ptr.h"
+#include "chrome/browser/ui/webui/segmentation_internals/segmentation_internals.mojom.h"
+#include "components/segmentation_platform/public/segment_selection_result.h"
+#include "mojo/public/cpp/bindings/receiver.h"
+
+class Profile;
+
+namespace segmentation_platform {
+class SegmentationPlatformService;
+}
+
+class SegmentationInternalsPageHandlerImpl
+ : public segmentation_internals::mojom::PageHandler {
+ public:
+ SegmentationInternalsPageHandlerImpl(
+ mojo::PendingReceiver<segmentation_internals::mojom::PageHandler>
+ receiver,
+ Profile* profile);
+ ~SegmentationInternalsPageHandlerImpl() override;
+
+ SegmentationInternalsPageHandlerImpl(
+ const SegmentationInternalsPageHandlerImpl&) = delete;
+ SegmentationInternalsPageHandlerImpl& operator=(
+ const SegmentationInternalsPageHandlerImpl&) = delete;
+
+ // segmentation_internals::mojom::PageHandler:
+ void GetSegment(const std::string& key, GetSegmentCallback callback) override;
+
+ private:
+ // Called when segment result is retrieved.
+ void OnGetSelectedSegmentDone(
+ GetSegmentCallback callback,
+ const segmentation_platform::SegmentSelectionResult& result);
+
+ mojo::Receiver<segmentation_internals::mojom::PageHandler> receiver_;
+ segmentation_platform::SegmentationPlatformService*
+ segmentation_platform_service_;
+
+ base::WeakPtrFactory<SegmentationInternalsPageHandlerImpl> weak_ptr_factory_{
+ this};
+};
+
+#endif // CHROME_BROWSER_UI_WEBUI_SEGMENTATION_INTERNALS_SEGMENTATION_INTERNALS_PAGE_HANDLER_IMPL_H_
diff --git a/chrome/browser/ui/webui/segmentation_internals/segmentation_internals_ui.cc b/chrome/browser/ui/webui/segmentation_internals/segmentation_internals_ui.cc
new file mode 100644
index 0000000..62210ac
--- /dev/null
+++ b/chrome/browser/ui/webui/segmentation_internals/segmentation_internals_ui.cc
@@ -0,0 +1,49 @@
+// Copyright 2021 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/ui/webui/segmentation_internals/segmentation_internals_ui.h"
+
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/ui/webui/segmentation_internals/segmentation_internals_page_handler_impl.h"
+#include "chrome/browser/ui/webui/webui_util.h"
+#include "chrome/common/webui_url_constants.h"
+#include "chrome/grit/segmentation_internals_resources.h"
+#include "chrome/grit/segmentation_internals_resources_map.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/browser/web_ui_data_source.h"
+
+SegmentationInternalsUI::SegmentationInternalsUI(content::WebUI* web_ui)
+ : MojoWebUIController(web_ui, /*enable_chrome_send=*/true) {
+ profile_ = Profile::FromWebUI(web_ui);
+ auto source = base::WrapUnique(content::WebUIDataSource::Create(
+ chrome::kChromeUISegmentationInternalsHost));
+ webui::SetupWebUIDataSource(
+ source.get(),
+ base::make_span(kSegmentationInternalsResources,
+ kSegmentationInternalsResourcesSize),
+ IDR_SEGMENTATION_INTERNALS_SEGMENTATION_INTERNALS_HTML);
+
+ content::BrowserContext* browser_context =
+ web_ui->GetWebContents()->GetBrowserContext();
+ content::WebUIDataSource::Add(browser_context, source.release());
+}
+
+SegmentationInternalsUI::~SegmentationInternalsUI() = default;
+
+void SegmentationInternalsUI::BindInterface(
+ mojo::PendingReceiver<segmentation_internals::mojom::PageHandlerFactory>
+ receiver) {
+ segmentation_internals_page_factory_receiver_.reset();
+ segmentation_internals_page_factory_receiver_.Bind(std::move(receiver));
+}
+
+void SegmentationInternalsUI::CreatePageHandler(
+ mojo::PendingReceiver<segmentation_internals::mojom::PageHandler>
+ receiver) {
+ segmentation_internals_page_handler_ =
+ std::make_unique<SegmentationInternalsPageHandlerImpl>(
+ std::move(receiver), profile_);
+}
+
+WEB_UI_CONTROLLER_TYPE_IMPL(SegmentationInternalsUI)
diff --git a/chrome/browser/ui/webui/segmentation_internals/segmentation_internals_ui.h b/chrome/browser/ui/webui/segmentation_internals/segmentation_internals_ui.h
new file mode 100644
index 0000000..0724380a
--- /dev/null
+++ b/chrome/browser/ui/webui/segmentation_internals/segmentation_internals_ui.h
@@ -0,0 +1,45 @@
+// Copyright 2021 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_UI_WEBUI_SEGMENTATION_INTERNALS_SEGMENTATION_INTERNALS_UI_H_
+#define CHROME_BROWSER_UI_WEBUI_SEGMENTATION_INTERNALS_SEGMENTATION_INTERNALS_UI_H_
+
+#include "chrome/browser/ui/webui/segmentation_internals/segmentation_internals.mojom.h" // nogncheck
+#include "mojo/public/cpp/bindings/pending_receiver.h"
+#include "ui/webui/mojo_web_ui_controller.h"
+
+class Profile;
+class SegmentationInternalsPageHandlerImpl;
+
+// The WebUI controller for chrome://segmentation-internals.
+class SegmentationInternalsUI
+ : public ui::MojoWebUIController,
+ public segmentation_internals::mojom::PageHandlerFactory {
+ public:
+ explicit SegmentationInternalsUI(content::WebUI* web_ui);
+ ~SegmentationInternalsUI() override;
+
+ SegmentationInternalsUI(const SegmentationInternalsUI&) = delete;
+ SegmentationInternalsUI& operator=(const SegmentationInternalsUI&) = delete;
+
+ void BindInterface(
+ mojo::PendingReceiver<segmentation_internals::mojom::PageHandlerFactory>
+ receiver);
+
+ private:
+ // segmentation_internals::mojom::PageHandlerFactory impls.
+ void CreatePageHandler(
+ mojo::PendingReceiver<segmentation_internals::mojom::PageHandler>
+ receiver) override;
+
+ Profile* profile_;
+ std::unique_ptr<SegmentationInternalsPageHandlerImpl>
+ segmentation_internals_page_handler_;
+ mojo::Receiver<segmentation_internals::mojom::PageHandlerFactory>
+ segmentation_internals_page_factory_receiver_{this};
+
+ WEB_UI_CONTROLLER_TYPE_DECL();
+};
+
+#endif // CHROME_BROWSER_UI_WEBUI_SEGMENTATION_INTERNALS_SEGMENTATION_INTERNALS_UI_H_
diff --git a/chrome/chrome_paks.gni b/chrome/chrome_paks.gni
index 8df2ead..645a7b0 100644
--- a/chrome/chrome_paks.gni
+++ b/chrome/chrome_paks.gni
@@ -95,6 +95,7 @@
"$root_gen_dir/chrome/browser_resources.pak",
"$root_gen_dir/chrome/chrome_unscaled_resources.pak",
"$root_gen_dir/chrome/common_resources.pak",
+ "$root_gen_dir/chrome/segmentation_internals_resources.pak",
"$root_gen_dir/components/autofill/core/browser/autofill_address_rewriter_resources.pak",
"$root_gen_dir/components/components_resources.pak",
"$root_gen_dir/content/content_resources.pak",
@@ -110,6 +111,7 @@
"//base/tracing/protos:chrome_track_event_resources",
"//chrome/app/theme:chrome_unscaled_resources",
"//chrome/browser:resources",
+ "//chrome/browser/resources/segmentation_internals:resources",
"//chrome/common:resources",
"//components/autofill/core/browser:autofill_address_rewriter_resources",
"//components/resources",
diff --git a/chrome/common/webui_url_constants.cc b/chrome/common/webui_url_constants.cc
index 3b52993..6297db0 100644
--- a/chrome/common/webui_url_constants.cc
+++ b/chrome/common/webui_url_constants.cc
@@ -161,6 +161,7 @@
const char kChromeUIRestartURL[] = "chrome://restart/";
const char kChromeUISafetyPixelbookURL[] = "https://g.co/Pixelbook/legal";
const char kChromeUISafetyPixelSlateURL[] = "https://g.co/PixelSlate/legal";
+const char kChromeUISegmentationInternalsHost[] = "segmentation-internals";
#if BUILDFLAG(ENABLE_SESSION_SERVICE)
const char kChromeUISessionServiceInternalsPath[] = "session-service";
#endif
diff --git a/chrome/common/webui_url_constants.h b/chrome/common/webui_url_constants.h
index de6e89e..a76df7b0 100644
--- a/chrome/common/webui_url_constants.h
+++ b/chrome/common/webui_url_constants.h
@@ -162,6 +162,7 @@
extern const char kChromeUIRestartURL[];
extern const char kChromeUISafetyPixelbookURL[];
extern const char kChromeUISafetyPixelSlateURL[];
+extern const char kChromeUISegmentationInternalsHost[];
#if BUILDFLAG(ENABLE_SESSION_SERVICE)
extern const char kChromeUISessionServiceInternalsPath[];
#endif
diff --git a/tools/gritsettings/resource_ids.spec b/tools/gritsettings/resource_ids.spec
index cd60500..9ce426e 100644
--- a/tools/gritsettings/resource_ids.spec
+++ b/tools/gritsettings/resource_ids.spec
@@ -233,6 +233,10 @@
"META": {"sizes": {"includes": [10],}},
"includes": [1920],
},
+ "<(SHARED_INTERMEDIATE_DIR)/chrome/browser/resources/segmentation_internals/resources.grd": {
+ "META": {"sizes": {"includes": [10]}},
+ "includes": [1930],
+ },
"<(SHARED_INTERMEDIATE_DIR)/chrome/browser/resources/settings/chromeos/os_settings_resources.grd": {
"META": {"sizes": {"includes": [1000],}},
"includes": [1940],