[MVT Customization] Make CustomLinksManager available on Android.
In order for MostVisitedSites to use CustomLinksManager, the following
are needed:
1. CustomLinksManagerImpl needs to be registered PrefRegistry.
2. When instantiating MostVisitedSites, a CustomLinksManager instance
needs to be passed.
3. MostVisitedSites::EnableCustomLinks() needs to be passed true.
This CL enables the above for Chrome on Android, subject to the feature
flag #most-visited-tiles-customization. Specifically:
* Do (1) on all platforms (previously skipped for Android).
* Do (2) subject to the flag in
ChromeMostVisitedSitesFactory::NewForProfile().
* Do (3) subject to the flag in
MostVisitedSitesBridge CTOR for JNI usage and in
ChromeNTPTilesInternalsMessageHandlerClient::MakeMostVisitedSites()
for chrome://ntp-tiles-internals page.
Bug: 397421743, 388782412
Change-Id: Idd4d1695848a3a2778f987144750ef3211e24f9e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6442920
Reviewed-by: Theresa Sullivan <[email protected]>
Commit-Queue: Samuel Huang <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1445440}
diff --git a/chrome/browser/android/ntp/most_visited_sites_bridge.cc b/chrome/browser/android/ntp/most_visited_sites_bridge.cc
index 551b8fc..551297d7 100644
--- a/chrome/browser/android/ntp/most_visited_sites_bridge.cc
+++ b/chrome/browser/android/ntp/most_visited_sites_bridge.cc
@@ -176,7 +176,7 @@
: most_visited_(ChromeMostVisitedSitesFactory::NewForProfile(profile)),
profile_(profile) {
DCHECK(!profile->IsOffTheRecord());
- // TODO(crbug.com/397421743): Use |enable_custom_links|.
+ most_visited_->EnableCustomLinks(enable_custom_links);
}
MostVisitedSitesBridge::~MostVisitedSitesBridge() = default;
diff --git a/chrome/browser/ntp_tiles/chrome_most_visited_sites_factory.cc b/chrome/browser/ntp_tiles/chrome_most_visited_sites_factory.cc
index c42655f3..1f562c94 100644
--- a/chrome/browser/ntp_tiles/chrome_most_visited_sites_factory.cc
+++ b/chrome/browser/ntp_tiles/chrome_most_visited_sites_factory.cc
@@ -35,10 +35,28 @@
#include "content/public/browser/storage_partition.h"
#include "services/data_decoder/public/cpp/data_decoder.h"
+#if BUILDFLAG(IS_ANDROID)
+#include "base/feature_list.h"
+#include "chrome/browser/flags/android/chrome_feature_list.h"
+#endif
+
#if !BUILDFLAG(IS_ANDROID)
#include "chrome/browser/web_applications/preinstalled_app_install_features.h"
#endif
+namespace {
+
+bool ShouldCreateCustomLinksManager() {
+#if BUILDFLAG(IS_ANDROID)
+ return base::FeatureList::IsEnabled(
+ chrome::android::kMostVisitedTilesCustomization);
+#else
+ return true;
+#endif
+}
+
+} // namespace
+
// static
std::unique_ptr<ntp_tiles::MostVisitedSites>
ChromeMostVisitedSitesFactory::NewForProfile(Profile* profile) {
@@ -71,11 +89,9 @@
#else
nullptr,
#endif
-#if !BUILDFLAG(IS_ANDROID)
- ChromeCustomLinksManagerFactory::NewForProfile(profile),
-#else
- nullptr,
-#endif
+ ShouldCreateCustomLinksManager()
+ ? ChromeCustomLinksManagerFactory::NewForProfile(profile)
+ : nullptr,
std::make_unique<ntp_tiles::IconCacherImpl>(
FaviconServiceFactory::GetForProfile(
profile, ServiceAccessType::IMPLICIT_ACCESS),
diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc
index 24a341d..622b2341 100644
--- a/chrome/browser/prefs/browser_prefs.cc
+++ b/chrome/browser/prefs/browser_prefs.cc
@@ -128,6 +128,7 @@
#include "components/metrics/demographics/user_demographics.h"
#include "components/metrics/metrics_pref_names.h"
#include "components/network_time/network_time_tracker.h"
+#include "components/ntp_tiles/custom_links_manager_impl.h"
#include "components/ntp_tiles/most_visited_sites.h"
#include "components/offline_pages/buildflags/buildflags.h"
#include "components/omnibox/browser/document_provider.h"
@@ -312,7 +313,6 @@
#include "components/lens/lens_overlay_permission_utils.h"
#include "components/live_caption/live_caption_controller.h"
#include "components/live_caption/live_translate_controller.h"
-#include "components/ntp_tiles/custom_links_manager_impl.h"
#endif // BUILDFLAG(IS_ANDROID)
#if BUILDFLAG(ENABLE_DEVTOOLS_FRONTEND)
@@ -1892,6 +1892,7 @@
metrics::RegisterDemographicsProfilePrefs(registry);
NotificationDisplayServiceImpl::RegisterProfilePrefs(registry);
NotifierStateTracker::RegisterProfilePrefs(registry);
+ ntp_tiles::CustomLinksManagerImpl::RegisterProfilePrefs(registry);
ntp_tiles::MostVisitedSites::RegisterProfilePrefs(registry);
optimization_guide::prefs::RegisterProfilePrefs(registry);
optimization_guide::model_execution::prefs::RegisterProfilePrefs(registry);
@@ -2037,7 +2038,6 @@
NewTabPageHandler::RegisterProfilePrefs(registry);
NewTabPageUI::RegisterProfilePrefs(registry);
ntp::SafeBrowsingHandler::RegisterProfilePrefs(registry);
- ntp_tiles::CustomLinksManagerImpl::RegisterProfilePrefs(registry);
OutlookCalendarPageHandler::RegisterProfilePrefs(registry);
PinnedTabCodec::RegisterProfilePrefs(registry);
promos_utils::RegisterProfilePrefs(registry);
diff --git a/chrome/browser/ui/webui/ntp_tiles_internals_ui.cc b/chrome/browser/ui/webui/ntp_tiles_internals_ui.cc
index 0c4d877..e22e047 100644
--- a/chrome/browser/ui/webui/ntp_tiles_internals_ui.cc
+++ b/chrome/browser/ui/webui/ntp_tiles_internals_ui.cc
@@ -33,6 +33,11 @@
#include "services/network/public/mojom/content_security_policy.mojom.h"
#include "ui/webui/webui_util.h"
+#if BUILDFLAG(IS_ANDROID)
+#include "base/feature_list.h"
+#include "chrome/browser/flags/android/chrome_feature_list.h"
+#endif
+
#if !BUILDFLAG(IS_ANDROID)
#include "chrome/browser/ui/webui/new_tab_page/ntp_pref_names.h"
#include "components/prefs/pref_service.h"
@@ -87,8 +92,13 @@
ChromeNTPTilesInternalsMessageHandlerClient::MakeMostVisitedSites() {
auto most_visited_sites = ChromeMostVisitedSitesFactory::NewForProfile(
Profile::FromWebUI(web_ui()));
- // Custom links only exist on Desktop.
-#if !BUILDFLAG(IS_ANDROID)
+#if BUILDFLAG(IS_ANDROID)
+ // Custom links on Android: ntp_prefs::kNtpUseMostVisitedTiles is
+ // unavailable. Use feature list instead.
+ most_visited_sites->EnableCustomLinks(base::FeatureList::IsEnabled(
+ chrome::android::kMostVisitedTilesCustomization));
+#else
+ // Custom links on Desktop.
most_visited_sites->EnableCustomLinks(
!GetPrefs()->GetBoolean(ntp_prefs::kNtpUseMostVisitedTiles));
#endif