Skip to content

Commit

Permalink
WebUI: Migrate HistoryClustersInternalsUI to WebUIConfig.
Browse files Browse the repository at this point in the history
Bug: 40222519
Change-Id: I891b72a6acc9195f0ac7723526e822561b507f01
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5972761
Reviewed-by: Rebekah Potter <rbpotter@chromium.org>
Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com>
Commit-Queue: Teresa Mao <temao@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1376677}
  • Loading branch information
Teresa Mao authored and pull[bot] committed Nov 5, 2024
1 parent b3526ca commit 1322528
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 22 deletions.
2 changes: 2 additions & 0 deletions chrome/browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ static_library("ui") {
"webui/flags/flags_ui_handler.h",
"webui/gcm_internals_ui.cc",
"webui/gcm_internals_ui.h",
"webui/history_clusters/history_clusters_internals_ui_config.cc",
"webui/history_clusters/history_clusters_internals_ui_config.h",
"webui/internals/internals_ui.cc",
"webui/internals/internals_ui.h",
"webui/interstitials/interstitial_ui.cc",
Expand Down
4 changes: 4 additions & 0 deletions chrome/browser/ui/webui/chrome_web_ui_configs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "chrome/browser/ui/webui/family_link_user_internals/family_link_user_internals_ui.h"
#include "chrome/browser/ui/webui/flags/flags_ui.h"
#include "chrome/browser/ui/webui/gcm_internals_ui.h"
#include "chrome/browser/ui/webui/history_clusters/history_clusters_internals_ui_config.h"
#include "chrome/browser/ui/webui/internals/internals_ui.h"
#include "chrome/browser/ui/webui/interstitials/interstitial_ui.h"
#include "chrome/browser/ui/webui/local_state/local_state_ui.h"
Expand Down Expand Up @@ -227,6 +228,9 @@ void RegisterChromeWebUIConfigs() {
map.AddWebUIConfig(std::make_unique<FamilyLinkUserInternalsUIConfig>());
map.AddWebUIConfig(std::make_unique<FlagsUIConfig>());
map.AddWebUIConfig(std::make_unique<GCMInternalsUIConfig>());
map.AddWebUIConfig(
std::make_unique<
history_clusters_internals::HistoryClustersInternalsUIConfig>());
map.AddWebUIConfig(std::make_unique<InternalsUIConfig>());
map.AddWebUIConfig(std::make_unique<InterstitialUIConfig>());
map.AddWebUIConfig(std::make_unique<LocalStateUIConfig>());
Expand Down
22 changes: 0 additions & 22 deletions chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
#include "chrome/browser/about_flags.h"
#include "chrome/browser/buildflags.h"
#include "chrome/browser/devtools/devtools_ui_bindings.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/history_clusters/history_clusters_service_factory.h"
#include "chrome/browser/optimization_guide/optimization_guide_internals_ui.h"
#include "chrome/browser/optimization_guide/optimization_guide_keyed_service.h"
#include "chrome/browser/optimization_guide/optimization_guide_keyed_service_factory.h"
Expand All @@ -45,9 +43,6 @@
#include "components/favicon_base/select_favicon_frames.h"
#include "components/grit/components_scaled_resources.h"
#include "components/history/core/browser/history_types.h"
#include "components/history_clusters/core/features.h"
#include "components/history_clusters/history_clusters_internals/webui/history_clusters_internals_ui.h"
#include "components/history_clusters/history_clusters_internals/webui/url_constants.h"
#include "components/lens/buildflags.h"
#include "components/optimization_guide/optimization_guide_internals/webui/url_constants.h"
#include "components/password_manager/content/common/web_ui_constants.h"
Expand Down Expand Up @@ -197,19 +192,6 @@ WebUIController* NewWebUI<OptimizationGuideInternalsUI>(WebUI* web_ui,
kChromeUIOptimizationGuideInternalsHost));
}

template <>
WebUIController* NewWebUI<HistoryClustersInternalsUI>(WebUI* web_ui,
const GURL& url) {
Profile* profile = Profile::FromWebUI(web_ui);
return new HistoryClustersInternalsUI(
web_ui, HistoryClustersServiceFactory::GetForBrowserContext(profile),
HistoryServiceFactory::GetForProfile(profile,
ServiceAccessType::EXPLICIT_ACCESS),
base::BindOnce(
&SetUpWebUIDataSource, web_ui,
history_clusters_internals::kChromeUIHistoryClustersInternalsHost));
}

// Returns a function that can be used to create the right type of WebUI for a
// tab, based on its URL. Returns nullptr if the URL doesn't have WebUI
// associated with it.
Expand All @@ -234,10 +216,6 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui,
optimization_guide_internals::kChromeUIOptimizationGuideInternalsHost) {
return &NewWebUI<OptimizationGuideInternalsUI>;
}
if (url.host_piece() ==
history_clusters_internals::kChromeUIHistoryClustersInternalsHost) {
return &NewWebUI<HistoryClustersInternalsUI>;
}

#if !BUILDFLAG(IS_ANDROID)
if (url.SchemeIs(content::kChromeDevToolsScheme)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2024 The Chromium Authors
// 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/history_clusters/history_clusters_internals_ui_config.h"

#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/history_clusters/history_clusters_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/webui_util.h"
#include "components/history_clusters/history_clusters_internals/webui/history_clusters_internals_ui.h"
#include "components/history_clusters/history_clusters_internals/webui/url_constants.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui_data_source.h"

namespace history_clusters_internals {

// TODO(crbug.com/40222519): Move SetupWebUIDataSource() to a location
// accessible from components/, such as in //ui/base/webui, so that the only
// 'wrapping' in this Config class is HistoryClustersServiceFactory.
void SetUpWebUIDataSource(content::WebUI* web_ui,
const char* web_ui_host,
base::span<const webui::ResourcePath> resources,
int default_resource) {
content::WebUIDataSource* source = content::WebUIDataSource::CreateAndAdd(
web_ui->GetWebContents()->GetBrowserContext(), web_ui_host);
webui::SetupWebUIDataSource(source, resources, default_resource);
}

HistoryClustersInternalsUIConfig::HistoryClustersInternalsUIConfig()
: WebUIConfig(
content::kChromeUIScheme,
history_clusters_internals::kChromeUIHistoryClustersInternalsHost) {}

HistoryClustersInternalsUIConfig::~HistoryClustersInternalsUIConfig() = default;

std::unique_ptr<content::WebUIController>
HistoryClustersInternalsUIConfig::CreateWebUIController(content::WebUI* web_ui,
const GURL& url) {
Profile* profile = Profile::FromWebUI(web_ui);
return std::make_unique<HistoryClustersInternalsUI>(
web_ui, HistoryClustersServiceFactory::GetForBrowserContext(profile),
HistoryServiceFactory::GetForProfile(profile,
ServiceAccessType::EXPLICIT_ACCESS),
base::BindOnce(
&SetUpWebUIDataSource, web_ui,
history_clusters_internals::kChromeUIHistoryClustersInternalsHost));
}

} // namespace history_clusters_internals
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2024 The Chromium Authors
// 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_HISTORY_CLUSTERS_HISTORY_CLUSTERS_INTERNALS_UI_CONFIG_H_
#define CHROME_BROWSER_UI_WEBUI_HISTORY_CLUSTERS_HISTORY_CLUSTERS_INTERNALS_UI_CONFIG_H_

#include "content/public/browser/webui_config.h"
#include "content/public/common/url_constants.h"

namespace history_clusters_internals {

class HistoryClustersInternalsUIConfig : public content::WebUIConfig {
public:
HistoryClustersInternalsUIConfig();
~HistoryClustersInternalsUIConfig() override;

// content::WebUIConfig:
std::unique_ptr<content::WebUIController> CreateWebUIController(
content::WebUI* web_ui,
const GURL& url) override;
};

} // namespace history_clusters_internals

#endif // CHROME_BROWSER_UI_WEBUI_HISTORY_CLUSTERS_HISTORY_CLUSTERS_INTERNALS_UI_CONFIG_H_
1 change: 1 addition & 0 deletions tools/metrics/histograms/enums.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34027,6 +34027,7 @@ Called by update_use_counter_feature_enum.py.-->
<enum name="WebUIUrlHashes">
<int value="-2103246641" label="chrome://signin-internals/"/>
<int value="-2086395469" label="chrome://dlp-internals/"/>
<int value="-2069349961" label="chrome://history-clusters-internals/"/>
<int value="-2061366287" label="chrome://dev-ui-loader/"/>
<int value="-2034706497" label="chrome://net-internals/"/>
<int value="-2031269077" label="chrome://signin-error/"/>
Expand Down

0 comments on commit 1322528

Please sign in to comment.