[ntp] Remove custom background handling from instant NTPs
Since the removal of the 1P local NTP and cutting the dependency between
InstantService and WebUI NTP, handling of custom backgrounds in instant
NTPs is obsolete. This CL removes the associated code.
This CL does have a user visible impact. Previously, we reset custom
backgrounds when switching DSEs. This meant when switching from Google
to 3P DSE and back to Google your set custom background was removed.
With this CL, you'll still have your custom background when switching
back to Google. NTPs of 3P DSEs never showed and still don't show a
custom background.
Bug: 1041125
Change-Id: I90777273bfc69bdffdcc78adb4198a739a0f63e3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3087962
Commit-Queue: Tibor Goldschwendt <tiborg@chromium.org>
Reviewed-by: Moe Ahmadi <mahmadi@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: Alex Gough <ajgo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#912406}
diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc
index 8fadd3a..1b8465c 100644
--- a/chrome/browser/prefs/browser_prefs.cc
+++ b/chrome/browser/prefs/browser_prefs.cc
@@ -242,7 +242,7 @@
#include "chrome/browser/new_tab_page/modules/drive/drive_service.h"
#include "chrome/browser/new_tab_page/modules/task_module/task_module_service.h"
#include "chrome/browser/new_tab_page/promos/promo_service.h"
-#include "chrome/browser/search/instant_service.h"
+#include "chrome/browser/search/background/ntp_custom_background_service.h"
#include "chrome/browser/search/search_suggest/search_suggest_service.h"
#include "chrome/browser/serial/serial_policy_allowed_ports.h"
#include "chrome/browser/signin/signin_promo.h"
@@ -1222,7 +1222,7 @@
first_run::RegisterProfilePrefs(registry);
gcm::RegisterProfilePrefs(registry);
HatsService::RegisterProfilePrefs(registry);
- InstantService::RegisterProfilePrefs(registry);
+ NtpCustomBackgroundService::RegisterProfilePrefs(registry);
media_router::RegisterProfilePrefs(registry);
NewTabPageHandler::RegisterProfilePrefs(registry);
NewTabPageUI::RegisterProfilePrefs(registry);
diff --git a/chrome/browser/profile_resetter/profile_resetter.cc b/chrome/browser/profile_resetter/profile_resetter.cc
index 2d2b667..1eb57e8 100644
--- a/chrome/browser/profile_resetter/profile_resetter.cc
+++ b/chrome/browser/profile_resetter/profile_resetter.cc
@@ -21,7 +21,7 @@
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profile_resetter/brandcoded_default_settings.h"
#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/search/instant_service_factory.h"
+#include "chrome/browser/search/background/ntp_custom_background_service.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/translate/chrome_translate_client.h"
#include "chrome/browser/ui/browser.h"
@@ -83,8 +83,7 @@
: profile_(profile),
template_url_service_(TemplateURLServiceFactory::GetForProfile(profile_)),
pending_reset_flags_(0),
- cookies_remover_(nullptr),
- ntp_service_(InstantServiceFactory::GetForProfile(profile)) {
+ cookies_remover_(nullptr) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(profile_);
}
@@ -342,7 +341,7 @@
}
void ProfileResetter::ResetNtpCustomizations() {
- ntp_service_->ResetToDefault();
+ NtpCustomBackgroundService::ResetProfilePrefs(profile_);
NewTabPageUI::ResetProfilePrefs(profile_->GetPrefs());
MarkAsDone(NTP_CUSTOMIZATIONS);
}
diff --git a/chrome/browser/profile_resetter/profile_resetter.h b/chrome/browser/profile_resetter/profile_resetter.h
index 1ebf4919..f3dcfd2 100644
--- a/chrome/browser/profile_resetter/profile_resetter.h
+++ b/chrome/browser/profile_resetter/profile_resetter.h
@@ -19,7 +19,6 @@
#include "base/memory/weak_ptr.h"
#include "base/sequence_checker.h"
#include "chrome/browser/profile_resetter/brandcoded_default_settings.h"
-#include "chrome/browser/search/instant_service.h"
#include "components/search_engines/template_url_service.h"
#include "content/public/browser/browsing_data_remover.h"
@@ -118,9 +117,6 @@
SEQUENCE_CHECKER(sequence_checker_);
- // Used for resetting NTP customizations.
- InstantService* ntp_service_;
-
base::WeakPtrFactory<ProfileResetter> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(ProfileResetter);
diff --git a/chrome/browser/profile_resetter/profile_resetter_unittest.cc b/chrome/browser/profile_resetter/profile_resetter_unittest.cc
index 2e27ce3c..03ce2790 100644
--- a/chrome/browser/profile_resetter/profile_resetter_unittest.cc
+++ b/chrome/browser/profile_resetter/profile_resetter_unittest.cc
@@ -29,7 +29,8 @@
#include "chrome/browser/profile_resetter/profile_reset_report.pb.h"
#include "chrome/browser/profile_resetter/profile_resetter_test_base.h"
#include "chrome/browser/profile_resetter/resettable_settings_snapshot.h"
-#include "chrome/browser/search/instant_service.h"
+#include "chrome/browser/search/background/ntp_custom_background_service.h"
+#include "chrome/browser/search/background/ntp_custom_background_service_factory.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/themes/test/theme_service_changed_waiter.h"
#include "chrome/browser/themes/theme_service.h"
@@ -338,15 +339,6 @@
}
#endif // defined(OS_WIN)
-// MockInstantService
-class MockInstantService : public InstantService {
- public:
- explicit MockInstantService(Profile* profile) : InstantService(profile) {}
- ~MockInstantService() override = default;
-
- MOCK_METHOD0(ResetToDefault, void());
-};
-
// helper functions -----------------------------------------------------------
scoped_refptr<Extension> CreateExtension(const std::u16string& name,
@@ -1026,11 +1018,20 @@
}
TEST_F(ProfileResetterTest, ResetNTPCustomizationsTest) {
- MockInstantService mock_ntp_service(profile());
- resetter_->ntp_service_ = &mock_ntp_service;
-
- EXPECT_CALL(mock_ntp_service, ResetToDefault());
+ auto* ntp_custom_background_service =
+ NtpCustomBackgroundServiceFactory::GetForProfile(profile());
+ ntp_custom_background_service->AddValidBackdropUrlForTesting(
+ GURL("https://background.com"));
+ ntp_custom_background_service->SetCustomBackgroundInfo(
+ /*background_url=*/GURL("https://background.com"),
+ /*attribution_line_1=*/"line 1",
+ /*attribution_line_2=*/"line 2",
+ /*action_url=*/GURL("https://action.com"),
+ /*collection_id=*/"");
+ EXPECT_TRUE(ntp_custom_background_service->GetCustomBackground().has_value());
ResetAndWait(ProfileResetter::NTP_CUSTOMIZATIONS);
+ EXPECT_FALSE(
+ ntp_custom_background_service->GetCustomBackground().has_value());
}
} // namespace
diff --git a/chrome/browser/search/background/ntp_custom_background_service.cc b/chrome/browser/search/background/ntp_custom_background_service.cc
index 4a34535..bbb323fb 100644
--- a/chrome/browser/search/background/ntp_custom_background_service.cc
+++ b/chrome/browser/search/background/ntp_custom_background_service.cc
@@ -92,6 +92,14 @@
chrome::kChromeUIUntrustedNewTabPageBackgroundFilename));
}
+void RemoveLocalBackgroundImageCopy(Profile* profile) {
+ base::FilePath path = profile->GetPath().AppendASCII(
+ chrome::kChromeUIUntrustedNewTabPageBackgroundFilename);
+ base::ThreadPool::PostTask(
+ FROM_HERE, {base::TaskPriority::BEST_EFFORT, base::MayBlock()},
+ base::BindOnce(base::GetDeleteFileCallback(), path));
+}
+
} // namespace
// static
@@ -104,6 +112,14 @@
false);
}
+// static
+void NtpCustomBackgroundService::ResetProfilePrefs(Profile* profile) {
+ profile->GetPrefs()->ClearPref(prefs::kNtpCustomBackgroundDict);
+ profile->GetPrefs()->SetBoolean(prefs::kNtpCustomBackgroundLocalToDevice,
+ false);
+ RemoveLocalBackgroundImageCopy(profile);
+}
+
NtpCustomBackgroundService::NtpCustomBackgroundService(Profile* profile)
: profile_(profile),
pref_service_(profile_->GetPrefs()),
@@ -161,7 +177,7 @@
void NtpCustomBackgroundService::UpdateBackgroundFromSync() {
// Any incoming change to synced background data should clear the local image.
pref_service_->SetBoolean(prefs::kNtpCustomBackgroundLocalToDevice, false);
- RemoveLocalBackgroundImageCopy();
+ RemoveLocalBackgroundImageCopy(profile_);
NotifyAboutBackgrounds();
}
@@ -192,7 +208,7 @@
pref_service_->FindPreference(prefs::kNtpCustomBackgroundDict)
->IsDefaultValue();
pref_service_->SetBoolean(prefs::kNtpCustomBackgroundLocalToDevice, false);
- RemoveLocalBackgroundImageCopy();
+ RemoveLocalBackgroundImageCopy(profile_);
background_updated_timestamp_ = base::TimeTicks::Now();
@@ -227,13 +243,6 @@
weak_ptr_factory_.GetWeakPtr()));
}
-void NtpCustomBackgroundService::ResetCustomBackgroundNtpTheme() {
- DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
- pref_service_->ClearPref(prefs::kNtpCustomBackgroundDict);
- pref_service_->SetBoolean(prefs::kNtpCustomBackgroundLocalToDevice, false);
- RemoveLocalBackgroundImageCopy();
-}
-
void NtpCustomBackgroundService::RefreshBackgroundIfNeeded() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
const base::DictionaryValue* background_info =
@@ -373,14 +382,6 @@
clock_ = clock;
}
-void NtpCustomBackgroundService::RemoveLocalBackgroundImageCopy() {
- base::FilePath path = profile_->GetPath().AppendASCII(
- chrome::kChromeUIUntrustedNewTabPageBackgroundFilename);
- base::ThreadPool::PostTask(
- FROM_HERE, {base::TaskPriority::BEST_EFFORT, base::MayBlock()},
- base::BindOnce(base::GetDeleteFileCallback(), path));
-}
-
void NtpCustomBackgroundService::SetBackgroundToLocalResource() {
background_updated_timestamp_ = base::TimeTicks::Now();
pref_service_->SetBoolean(prefs::kNtpCustomBackgroundLocalToDevice, true);
diff --git a/chrome/browser/search/background/ntp_custom_background_service.h b/chrome/browser/search/background/ntp_custom_background_service.h
index 63b77f5..72fb8ab 100644
--- a/chrome/browser/search/background/ntp_custom_background_service.h
+++ b/chrome/browser/search/background/ntp_custom_background_service.h
@@ -28,6 +28,7 @@
public NtpBackgroundServiceObserver {
public:
static void RegisterProfilePrefs(PrefRegistrySimple* registry);
+ static void ResetProfilePrefs(Profile* profile);
explicit NtpCustomBackgroundService(Profile* profile);
~NtpCustomBackgroundService() override;
@@ -58,9 +59,6 @@
// Invoked when a user selected the "Upload an image" option on the NTP.
void SelectLocalBackgroundImage(const base::FilePath& path);
- // Marked virtual for mocking in tests.
- virtual void ResetCustomBackgroundNtpTheme();
-
void RefreshBackgroundIfNeeded();
// Virtual for testing.
@@ -83,7 +81,6 @@
void SetClockForTesting(base::Clock* clock);
private:
- void RemoveLocalBackgroundImageCopy();
void SetBackgroundToLocalResource();
// Returns false if the custom background pref cannot be parsed, otherwise
// returns true.
diff --git a/chrome/browser/search/instant_service.cc b/chrome/browser/search/instant_service.cc
index ef5deb4..d0a137f3 100644
--- a/chrome/browser/search/instant_service.cc
+++ b/chrome/browser/search/instant_service.cc
@@ -22,7 +22,6 @@
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/ntp_tiles/chrome_most_visited_sites_factory.h"
#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/search/background/ntp_custom_background_service_factory.h"
#include "chrome/browser/search/chrome_colors/chrome_colors_service.h"
#include "chrome/browser/search/instant_service_factory.h"
#include "chrome/browser/search/instant_service_observer.h"
@@ -83,9 +82,6 @@
this, ntp_tiles::kMaxNumMostVisited);
}
- custom_background_service_ =
- NtpCustomBackgroundServiceFactory::GetForProfile(profile_);
-
// Listen for theme installation.
ThemeServiceFactory::GetForProfile(profile_)->AddObserver(this);
@@ -104,9 +100,6 @@
std::make_unique<MostVisitedIframeSource>());
theme_observation_.Observe(native_theme_);
-
- if (custom_background_service_)
- custom_background_service_observation_.Observe(custom_background_service_);
}
InstantService::~InstantService() = default;
@@ -157,7 +150,6 @@
}
void InstantService::UpdateNtpTheme() {
- ApplyOrResetCustomBackgroundNtpTheme();
SetNtpElementsNtpTheme();
NotifyAboutNtpTheme();
@@ -167,36 +159,7 @@
NotifyAboutMostVisitedInfo();
}
-void InstantService::ResetCustomBackgroundInfo() {
- if (custom_background_service_) {
- custom_background_service_->ResetCustomBackgroundInfo();
- }
-}
-
-void InstantService::SetCustomBackgroundInfo(
- const GURL& background_url,
- const std::string& attribution_line_1,
- const std::string& attribution_line_2,
- const GURL& action_url,
- const std::string& collection_id) {
- if (custom_background_service_) {
- custom_background_service_->SetCustomBackgroundInfo(
- background_url, attribution_line_1, attribution_line_2, action_url,
- collection_id);
- }
-}
-
-void InstantService::SelectLocalBackgroundImage(const base::FilePath& path) {
- if (custom_background_service_) {
- custom_background_service_->SelectLocalBackgroundImage(path);
- }
-}
-
NtpTheme* InstantService::GetInitializedNtpTheme() {
- if (custom_background_service_) {
- custom_background_service_->RefreshBackgroundIfNeeded();
- }
-
if (!theme_)
BuildNtpTheme();
return theme_.get();
@@ -218,17 +181,6 @@
ThemeServiceFactory::GetForProfile(profile_)->RemoveObserver(this);
}
-void InstantService::OnCustomBackgroundImageUpdated() {
- DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
- UpdateNtpTheme();
-}
-
-void InstantService::OnNtpCustomBackgroundServiceShuttingDown() {
- DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
- custom_background_service_observation_.Reset();
- custom_background_service_ = nullptr;
-}
-
void InstantService::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
@@ -369,85 +321,6 @@
}
}
-void InstantService::ApplyOrResetCustomBackgroundNtpTheme() {
- // Custom backgrounds for non-Google search providers are not supported.
- if (!search::DefaultSearchProviderIsGoogle(profile_)) {
- ResetCustomBackgroundNtpTheme();
- return;
- }
-
- auto custom_background =
- custom_background_service_
- ? custom_background_service_->GetCustomBackground()
- : absl::optional<CustomBackground>();
-
- if (!custom_background) {
- ResetCustomBackgroundNtpTheme();
- return;
- }
-
- GetInitializedNtpTheme()->custom_background_url =
- custom_background->custom_background_url;
- GetInitializedNtpTheme()->custom_background_attribution_line_1 =
- custom_background->custom_background_attribution_line_1;
- GetInitializedNtpTheme()->custom_background_attribution_line_2 =
- custom_background->custom_background_attribution_line_2;
- GetInitializedNtpTheme()->custom_background_attribution_action_url =
- custom_background->custom_background_attribution_action_url;
- GetInitializedNtpTheme()->collection_id = custom_background->collection_id;
-}
-
-void InstantService::ResetCustomBackgroundNtpTheme() {
- DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
- if (custom_background_service_) {
- custom_background_service_->ResetCustomBackgroundNtpTheme();
- }
- FallbackToDefaultNtpTheme();
-}
-
-void InstantService::FallbackToDefaultNtpTheme() {
- NtpTheme* theme = GetInitializedNtpTheme();
- theme->custom_background_url = GURL();
- theme->custom_background_attribution_line_1 = std::string();
- theme->custom_background_attribution_line_2 = std::string();
- theme->custom_background_attribution_action_url = GURL();
- theme->collection_id = std::string();
-}
-
-bool InstantService::IsCustomBackgroundDisabledByPolicy() {
- return custom_background_service_ &&
- custom_background_service_->IsCustomBackgroundDisabledByPolicy();
-}
-
-bool InstantService::IsCustomBackgroundSet() {
- return custom_background_service_ &&
- custom_background_service_->IsCustomBackgroundSet();
-}
-
-void InstantService::ResetToDefault() {
- ResetCustomBackgroundNtpTheme();
-}
-
-void InstantService::AddValidBackdropUrlForTesting(const GURL& url) const {
- custom_background_service_->AddValidBackdropUrlForTesting(url);
-}
-
-void InstantService::AddValidBackdropCollectionForTesting(
- const std::string& collection_id) const {
- custom_background_service_->AddValidBackdropCollectionForTesting(
- collection_id);
-}
-
-void InstantService::SetNextCollectionImageForTesting(
- const CollectionImage& image) const {
- custom_background_service_->SetNextCollectionImageForTesting(image);
-}
-
-// static
-void InstantService::RegisterProfilePrefs(PrefRegistrySimple* registry) {
- NtpCustomBackgroundService::RegisterProfilePrefs(registry);
-}
-
// static
bool InstantService::ShouldServiceRequest(
const GURL& url,
@@ -467,21 +340,11 @@
instant_service->IsInstantProcess(render_process_id);
}
-void InstantService::SetClockForTesting(base::Clock* clock) {
- custom_background_service_->SetClockForTesting(clock);
-}
-
void InstantService::SetNtpElementsNtpTheme() {
NtpTheme* theme = GetInitializedNtpTheme();
- if (IsCustomBackgroundSet()) {
- theme->text_color = gfx::kGoogleGrey050;
- theme->logo_alternate = true;
- } else {
- const ui::ThemeProvider& theme_provider =
- ThemeService::GetThemeProviderForProfile(profile_);
- theme->text_color =
- theme_provider.GetColor(ThemeProperties::COLOR_NTP_TEXT);
- theme->logo_alternate = theme_provider.GetDisplayProperty(
- ThemeProperties::NTP_LOGO_ALTERNATE) == 1;
- }
+ const ui::ThemeProvider& theme_provider =
+ ThemeService::GetThemeProviderForProfile(profile_);
+ theme->text_color = theme_provider.GetColor(ThemeProperties::COLOR_NTP_TEXT);
+ theme->logo_alternate = theme_provider.GetDisplayProperty(
+ ThemeProperties::NTP_LOGO_ALTERNATE) == 1;
}
diff --git a/chrome/browser/search/instant_service.h b/chrome/browser/search/instant_service.h
index 6c9774f..9994e75e 100644
--- a/chrome/browser/search/instant_service.h
+++ b/chrome/browser/search/instant_service.h
@@ -17,8 +17,6 @@
#include "base/observer_list.h"
#include "base/scoped_observation.h"
#include "build/build_config.h"
-#include "chrome/browser/search/background/ntp_custom_background_service.h"
-#include "chrome/browser/search/background/ntp_custom_background_service_observer.h"
#include "chrome/browser/themes/theme_service_observer.h"
#include "components/history/core/browser/history_types.h"
#include "components/keyed_service/core/keyed_service.h"
@@ -56,7 +54,6 @@
// necessary information (most visited tiles and theme info) updated in those
// renderer processes.
class InstantService : public KeyedService,
- public NtpCustomBackgroundServiceObserver,
public content::NotificationObserver,
public ntp_tiles::MostVisitedSites::Observer,
public ui::NativeThemeObserver,
@@ -74,9 +71,6 @@
virtual void AddObserver(InstantServiceObserver* observer);
void RemoveObserver(InstantServiceObserver* observer);
- // Register prefs associated with the NTP.
- static void RegisterProfilePrefs(PrefRegistrySimple* registry);
-
// Determine if this chrome-search: request is coming from an Instant render
// process.
static bool ShouldServiceRequest(const GURL& url,
@@ -112,66 +106,23 @@
// NTP.
void UpdateMostVisitedInfo();
- // Invoked when the background is reset on the NTP.
- void ResetCustomBackgroundInfo();
-
- // Invoked when a custom background is configured on the NTP.
- void SetCustomBackgroundInfo(const GURL& background_url,
- const std::string& attribution_line_1,
- const std::string& attribution_line_2,
- const GURL& action_url,
- const std::string& collection_id);
-
- // Invoked when a user selected the "Upload an image" option on the NTP.
- void SelectLocalBackgroundImage(const base::FilePath& path);
-
// Getter for |theme_| that will also initialize it if necessary.
NtpTheme* GetInitializedNtpTheme();
// Used for testing.
void SetNativeThemeForTesting(ui::NativeTheme* theme);
- // Used for testing.
- void AddValidBackdropUrlForTesting(const GURL& url) const;
-
- // Used for testing.
- void AddValidBackdropCollectionForTesting(
- const std::string& collection_id) const;
-
- // Used for testing.
- void SetNextCollectionImageForTesting(const CollectionImage& image) const;
-
- // Returns whether having a custom background is disabled by policy.
- bool IsCustomBackgroundDisabledByPolicy();
-
- // Returns whether a custom background has been set by the user.
- bool IsCustomBackgroundSet();
-
- // Reset all NTP customizations to default. Marked virtual for mocking in
- // tests.
- virtual void ResetToDefault();
-
private:
friend class InstantExtendedTest;
friend class InstantUnitTestBase;
friend class TestInstantService;
- FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, ProcessIsolation);
FRIEND_TEST_ALL_PREFIXES(InstantServiceTest, GetNTPTileSuggestion);
- FRIEND_TEST_ALL_PREFIXES(InstantServiceTest, DoesToggleShortcutsVisibility);
FRIEND_TEST_ALL_PREFIXES(InstantServiceTest, TestNoNtpTheme);
- FRIEND_TEST_ALL_PREFIXES(InstantServiceTest, TestUpdateCustomBackgroundColor);
- FRIEND_TEST_ALL_PREFIXES(InstantServiceTest,
- LocalImageDoesNotUpdateCustomBackgroundColor);
- FRIEND_TEST_ALL_PREFIXES(InstantServiceTest, RefreshesBackgroundAfter24Hours);
// KeyedService:
void Shutdown() override;
- // NtpCustomBackgroundServiceObserver:
- void OnCustomBackgroundImageUpdated() override;
- void OnNtpCustomBackgroundServiceShuttingDown() override;
-
// content::NotificationObserver:
void Observe(int type,
const content::NotificationSource& source,
@@ -194,15 +145,6 @@
void BuildNtpTheme();
- void ApplyOrResetCustomBackgroundNtpTheme();
-
- // Marked virtual for mocking in tests.
- virtual void ResetCustomBackgroundNtpTheme();
-
- void FallbackToDefaultNtpTheme();
-
- void SetClockForTesting(base::Clock* clock);
-
base::TimeTicks GetBackgroundUpdatedTimestampForTesting() {
return background_updated_timestamp_;
}
@@ -237,14 +179,8 @@
base::ScopedObservation<ui::NativeTheme, ui::NativeThemeObserver>
theme_observation_{this};
- base::ScopedObservation<NtpCustomBackgroundService,
- NtpCustomBackgroundServiceObserver>
- custom_background_service_observation_{this};
-
ui::NativeTheme* native_theme_;
- NtpCustomBackgroundService* custom_background_service_;
-
base::TimeTicks background_updated_timestamp_;
base::WeakPtrFactory<InstantService> weak_ptr_factory_{this};
diff --git a/chrome/browser/search/instant_service_unittest.cc b/chrome/browser/search/instant_service_unittest.cc
index e280067..77e54f9 100644
--- a/chrome/browser/search/instant_service_unittest.cc
+++ b/chrome/browser/search/instant_service_unittest.cc
@@ -6,8 +6,6 @@
#include <vector>
-#include "base/files/file_util.h"
-#include "base/path_service.h"
#include "base/task/thread_pool/thread_pool_instance.h"
#include "base/test/mock_callback.h"
#include "build/build_config.h"
@@ -17,7 +15,6 @@
#include "chrome/browser/themes/theme_properties.h"
#include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/themes/theme_service_factory.h"
-#include "chrome/common/chrome_paths.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/search/instant_types.h"
#include "chrome/common/url_constants.h"
@@ -68,116 +65,9 @@
EXPECT_EQ(ntp_tiles::TileTitleSource::TITLE_TAG, items[0].title_source);
}
-TEST_F(InstantServiceTest, ChangingSearchProviderClearsNtpThemeAndPref) {
- ASSERT_FALSE(instant_service_->IsCustomBackgroundSet());
- const GURL kUrl("https://www.foo.com");
- const std::string kAttributionLine1 = "foo";
- const std::string kAttributionLine2 = "bar";
- const GURL kActionUrl("https://www.bar.com");
-
- SetUserSelectedDefaultSearchProvider("{google:baseURL}");
- instant_service_->AddValidBackdropUrlForTesting(kUrl);
- instant_service_->SetCustomBackgroundInfo(kUrl, kAttributionLine1,
- kAttributionLine2, kActionUrl, "");
-
- NtpTheme* theme = instant_service_->GetInitializedNtpTheme();
- EXPECT_EQ(kUrl, theme->custom_background_url);
- EXPECT_EQ(kAttributionLine1, theme->custom_background_attribution_line_1);
- EXPECT_EQ(kAttributionLine2, theme->custom_background_attribution_line_2);
- EXPECT_EQ(kActionUrl, theme->custom_background_attribution_action_url);
- EXPECT_TRUE(instant_service_->IsCustomBackgroundSet());
-
- SetUserSelectedDefaultSearchProvider("https://www.search.com");
- instant_service_->UpdateNtpTheme();
-
- theme = instant_service_->GetInitializedNtpTheme();
- EXPECT_EQ(GURL(), theme->custom_background_url);
- EXPECT_EQ("", theme->custom_background_attribution_line_1);
- EXPECT_EQ("", theme->custom_background_attribution_line_2);
- EXPECT_EQ(GURL(), theme->custom_background_attribution_action_url);
- EXPECT_FALSE(instant_service_->IsCustomBackgroundSet());
-
- SetUserSelectedDefaultSearchProvider("{google:baseURL}");
- instant_service_->UpdateNtpTheme();
-
- theme = instant_service_->GetInitializedNtpTheme();
- EXPECT_EQ(GURL(), theme->custom_background_url);
- EXPECT_EQ("", theme->custom_background_attribution_line_1);
- EXPECT_EQ("", theme->custom_background_attribution_line_2);
- EXPECT_EQ(GURL(), theme->custom_background_attribution_action_url);
- EXPECT_FALSE(instant_service_->IsCustomBackgroundSet());
-}
-
-TEST_F(InstantServiceTest,
- ChangingSearchProviderRemovesLocalBackgroundImageCopy) {
- ASSERT_FALSE(instant_service_->IsCustomBackgroundSet());
- base::FilePath profile_path = profile()->GetPath();
- base::FilePath path(profile_path.AppendASCII(
- chrome::kChromeUIUntrustedNewTabPageBackgroundFilename));
-
- base::WriteFile(path, "background_image", 16);
-
- SetUserSelectedDefaultSearchProvider("https://www.search.com");
- instant_service_->UpdateNtpTheme();
-
- task_environment()->RunUntilIdle();
-
- bool file_exists = base::PathExists(path);
-
- EXPECT_EQ(false, file_exists);
- EXPECT_EQ(false, profile()->GetTestingPrefService()->GetBoolean(
- prefs::kNtpCustomBackgroundLocalToDevice));
- EXPECT_FALSE(instant_service_->IsCustomBackgroundSet());
-}
-
-TEST_F(InstantServiceTest, CustomBackgroundAttributionActionUrlReset) {
- ASSERT_FALSE(instant_service_->IsCustomBackgroundSet());
- const GURL kUrl("https://www.foo.com");
- const std::string kAttributionLine1 = "foo";
- const std::string kAttributionLine2 = "bar";
- const GURL kHttpsActionUrl("https://www.bar.com");
- const GURL kHttpActionUrl("http://www.bar.com");
-
- SetUserSelectedDefaultSearchProvider("{google:baseURL}");
- instant_service_->AddValidBackdropUrlForTesting(kUrl);
- instant_service_->SetCustomBackgroundInfo(
- kUrl, kAttributionLine1, kAttributionLine2, kHttpsActionUrl, "");
-
- NtpTheme* theme = instant_service_->GetInitializedNtpTheme();
- EXPECT_EQ(kHttpsActionUrl, theme->custom_background_attribution_action_url);
- EXPECT_TRUE(instant_service_->IsCustomBackgroundSet());
-
- instant_service_->SetCustomBackgroundInfo(
- kUrl, kAttributionLine1, kAttributionLine2, kHttpActionUrl, "");
-
- theme = instant_service_->GetInitializedNtpTheme();
- EXPECT_EQ(GURL(), theme->custom_background_attribution_action_url);
- EXPECT_TRUE(instant_service_->IsCustomBackgroundSet());
-
- instant_service_->SetCustomBackgroundInfo(
- kUrl, kAttributionLine1, kAttributionLine2, kHttpsActionUrl, "");
-
- theme = instant_service_->GetInitializedNtpTheme();
- EXPECT_EQ(kHttpsActionUrl, theme->custom_background_attribution_action_url);
- EXPECT_TRUE(instant_service_->IsCustomBackgroundSet());
-
- instant_service_->SetCustomBackgroundInfo(kUrl, kAttributionLine1,
- kAttributionLine2, GURL(), "");
-
- theme = instant_service_->GetInitializedNtpTheme();
- EXPECT_EQ(GURL(), theme->custom_background_attribution_action_url);
- EXPECT_TRUE(instant_service_->IsCustomBackgroundSet());
-}
-
TEST_F(InstantServiceTest, TestNoNtpTheme) {
instant_service_->theme_ = nullptr;
EXPECT_NE(nullptr, instant_service_->GetInitializedNtpTheme());
-
- instant_service_->theme_ = nullptr;
- // As |FallbackToDefaultNtpTheme| uses |theme_| it should initialize it
- // otherwise the test should crash.
- instant_service_->FallbackToDefaultNtpTheme();
- EXPECT_NE(nullptr, instant_service_->theme_);
}
class InstantServiceThemeTest : public InstantServiceTest {
@@ -199,8 +89,6 @@
SkColor default_text_color =
theme_provider.GetColor(ThemeProperties::COLOR_NTP_TEXT);
- ASSERT_FALSE(instant_service_->IsCustomBackgroundSet());
-
// Check defaults when no theme and no custom backgrounds is set.
NtpTheme* theme = instant_service_->GetInitializedNtpTheme();
EXPECT_EQ(default_text_color, theme->text_color);
@@ -220,9 +108,6 @@
// Setting a custom background should call SetNTPElementsNtpTheme() and
// update NTP themed elements info.
const GURL kUrl("https://www.foo.com");
- instant_service_->AddValidBackdropUrlForTesting(kUrl);
- instant_service_->SetCustomBackgroundInfo(kUrl, "", "", GURL(), "");
- ASSERT_TRUE(instant_service_->IsCustomBackgroundSet());
theme = instant_service_->GetInitializedNtpTheme();
EXPECT_NE(default_text_color, theme->text_color);
diff --git a/chrome/browser/ui/search/ntp_user_data_logger.cc b/chrome/browser/ui/search/ntp_user_data_logger.cc
index 80eb35c..9984056 100644
--- a/chrome/browser/ui/search/ntp_user_data_logger.cc
+++ b/chrome/browser/ui/search/ntp_user_data_logger.cc
@@ -11,8 +11,8 @@
#include "base/metrics/histogram_macros.h"
#include "base/metrics/user_metrics.h"
#include "chrome/browser/after_startup_task_utils.h"
-#include "chrome/browser/search/instant_service.h"
-#include "chrome/browser/search/instant_service_factory.h"
+#include "chrome/browser/search/background/ntp_custom_background_service.h"
+#include "chrome/browser/search/background/ntp_custom_background_service_factory.h"
#include "chrome/browser/search/search.h"
#include "chrome/browser/ui/search/ntp_user_data_types.h"
#include "chrome/common/pref_names.h"
@@ -448,9 +448,8 @@
}
bool NTPUserDataLogger::CustomBackgroundIsConfigured() const {
- InstantService* instant_service =
- InstantServiceFactory::GetForProfile(profile_);
- return instant_service->IsCustomBackgroundSet();
+ return NtpCustomBackgroundServiceFactory::GetForProfile(profile_)
+ ->IsCustomBackgroundSet();
}
void NTPUserDataLogger::EmitNtpStatistics(base::TimeDelta load_time,
diff --git a/chrome/browser/ui/search/search_ipc_router.cc b/chrome/browser/ui/search/search_ipc_router.cc
index 6531a99..04720be 100644
--- a/chrome/browser/ui/search/search_ipc_router.cc
+++ b/chrome/browser/ui/search/search_ipc_router.cc
@@ -163,15 +163,6 @@
embedded_search_client()->ThemeChanged(theme);
}
-void SearchIPCRouter::SendLocalBackgroundSelected() {
- if (!policy_->ShouldSendLocalBackgroundSelected() ||
- !embedded_search_client()) {
- return;
- }
-
- embedded_search_client()->LocalBackgroundSelected();
-}
-
void SearchIPCRouter::OnTabActivated() {
is_active_tab_ = true;
}
@@ -273,27 +264,6 @@
delegate_->OnLogMostVisitedNavigation(impression);
}
-void SearchIPCRouter::SetCustomBackgroundInfo(
- const GURL& background_url,
- const std::string& attribution_line_1,
- const std::string& attribution_line_2,
- const GURL& action_url,
- const std::string& collection_id) {
- if (!policy_->ShouldProcessSetCustomBackgroundInfo())
- return;
-
- delegate_->OnSetCustomBackgroundInfo(background_url, attribution_line_1,
- attribution_line_2, action_url,
- collection_id);
-}
-
-void SearchIPCRouter::SelectLocalBackgroundImage() {
- if (!policy_->ShouldProcessSelectLocalBackgroundImage())
- return;
-
- delegate_->OnSelectLocalBackgroundImage();
-}
-
void SearchIPCRouter::BlocklistSearchSuggestion(int32_t task_version,
int64_t task_id) {
if (!policy_->ShouldProcessBlocklistSearchSuggestion())
diff --git a/chrome/browser/ui/search/search_ipc_router.h b/chrome/browser/ui/search/search_ipc_router.h
index efc10588..7483400 100644
--- a/chrome/browser/ui/search/search_ipc_router.h
+++ b/chrome/browser/ui/search/search_ipc_router.h
@@ -74,23 +74,6 @@
virtual void OnLogMostVisitedNavigation(
const ntp_tiles::NTPTileImpression& impression) = 0;
- // Called when a custom background is configured on the NTP.
- // background_url: Url of the background image.
- // attribution_line_1: First attribution line for the image.
- // attribution_line_2: Second attribution line for the image.
- // action_url: Url to learn more about the backgrounds image.
- // collection_id: Id of the collection that was selected.
- virtual void OnSetCustomBackgroundInfo(
- const GURL& background_url,
- const std::string& attribution_line_1,
- const std::string& attribution_line_2,
- const GURL& action_url,
- const std::string& collection_id) = 0;
-
- // Called to open the file select dialog for selecting a
- // NTP background image.
- virtual void OnSelectLocalBackgroundImage() = 0;
-
// Called when a search suggestion is blocklisted on the local NTP.
virtual void OnBlocklistSearchSuggestion(int task_version,
long task_id) = 0;
@@ -142,9 +125,6 @@
virtual bool ShouldSendOmniboxFocusChanged() = 0;
virtual bool ShouldSendMostVisitedInfo() = 0;
virtual bool ShouldSendNtpTheme() = 0;
- virtual bool ShouldSendLocalBackgroundSelected() = 0;
- virtual bool ShouldProcessSetCustomBackgroundInfo() = 0;
- virtual bool ShouldProcessSelectLocalBackgroundImage() = 0;
virtual bool ShouldProcessBlocklistSearchSuggestion() = 0;
virtual bool ShouldProcessBlocklistSearchSuggestionWithHash() = 0;
virtual bool ShouldProcessSearchSuggestionSelected() = 0;
@@ -196,10 +176,6 @@
// Tells the renderer about the current theme background.
void SendNtpTheme(const NtpTheme& theme);
- // Tells the renderer that "Done" was clicked on the file selection dialog for
- // uploading a image to use as the NTP background.
- void SendLocalBackgroundSelected();
-
// Called when the tab corresponding to |this| instance is activated.
void OnTabActivated();
@@ -224,12 +200,6 @@
void LogMostVisitedNavigation(
int page_seq_no,
const ntp_tiles::NTPTileImpression& impression) override;
- void SetCustomBackgroundInfo(const GURL& background_url,
- const std::string& attribution_line_1,
- const std::string& attribution_line_2,
- const GURL& action_url,
- const std::string& collection_id) override;
- void SelectLocalBackgroundImage() override;
void BlocklistSearchSuggestion(int32_t task_version,
int64_t task_id) override;
void BlocklistSearchSuggestionWithHash(
diff --git a/chrome/browser/ui/search/search_ipc_router_policy_impl.cc b/chrome/browser/ui/search/search_ipc_router_policy_impl.cc
index 5f7b726..65dd4a1 100644
--- a/chrome/browser/ui/search/search_ipc_router_policy_impl.cc
+++ b/chrome/browser/ui/search/search_ipc_router_policy_impl.cc
@@ -62,18 +62,6 @@
return !is_incognito_ && search::IsInstantNTP(web_contents_);
}
-bool SearchIPCRouterPolicyImpl::ShouldSendLocalBackgroundSelected() {
- return !is_incognito_ && search::IsInstantNTP(web_contents_);
-}
-
-bool SearchIPCRouterPolicyImpl::ShouldProcessSelectLocalBackgroundImage() {
- return !is_incognito_ && search::IsInstantNTP(web_contents_);
-}
-
-bool SearchIPCRouterPolicyImpl::ShouldProcessSetCustomBackgroundInfo() {
- return !is_incognito_ && search::IsInstantNTP(web_contents_);
-}
-
bool SearchIPCRouterPolicyImpl::ShouldProcessBlocklistSearchSuggestion() {
return !is_incognito_ && search::IsInstantNTP(web_contents_);
}
diff --git a/chrome/browser/ui/search/search_ipc_router_policy_impl.h b/chrome/browser/ui/search/search_ipc_router_policy_impl.h
index 198afa9..57bb3e14 100644
--- a/chrome/browser/ui/search/search_ipc_router_policy_impl.h
+++ b/chrome/browser/ui/search/search_ipc_router_policy_impl.h
@@ -37,9 +37,6 @@
bool ShouldSendOmniboxFocusChanged() override;
bool ShouldSendMostVisitedInfo() override;
bool ShouldSendNtpTheme() override;
- bool ShouldSendLocalBackgroundSelected() override;
- bool ShouldProcessSetCustomBackgroundInfo() override;
- bool ShouldProcessSelectLocalBackgroundImage() override;
bool ShouldProcessBlocklistSearchSuggestion() override;
bool ShouldProcessBlocklistSearchSuggestionWithHash() override;
bool ShouldProcessSearchSuggestionSelected() override;
diff --git a/chrome/browser/ui/search/search_ipc_router_unittest.cc b/chrome/browser/ui/search/search_ipc_router_unittest.cc
index 46e36ce..8b50cac 100644
--- a/chrome/browser/ui/search/search_ipc_router_unittest.cc
+++ b/chrome/browser/ui/search/search_ipc_router_unittest.cc
@@ -72,13 +72,6 @@
MOCK_METHOD1(OnLogMostVisitedNavigation,
void(const ntp_tiles::NTPTileImpression& impression));
MOCK_METHOD1(OnSetCustomBackgroundURL, void(const GURL& url));
- MOCK_METHOD5(OnSetCustomBackgroundInfo,
- void(const GURL& background_url,
- const std::string& attribution1,
- const std::string& attribution2,
- const GURL& attributionActionUrl,
- const std::string& collection_id));
- MOCK_METHOD0(OnSelectLocalBackgroundImage, void());
MOCK_METHOD2(OnBlocklistSearchSuggestion,
void(int task_version, long task_id));
MOCK_METHOD3(OnBlocklistSearchSuggestionWithHash,
@@ -102,9 +95,6 @@
MOCK_METHOD0(ShouldProcessUndoAllMostVisitedDeletions, bool());
MOCK_METHOD0(ShouldProcessLogEvent, bool());
MOCK_METHOD0(ShouldProcessLogSuggestionEventWithValue, bool());
- MOCK_METHOD0(ShouldProcessSetCustomBackgroundURL, bool());
- MOCK_METHOD0(ShouldProcessSetCustomBackgroundInfo, bool());
- MOCK_METHOD0(ShouldProcessSelectLocalBackgroundImage, bool());
MOCK_METHOD0(ShouldProcessBlocklistSearchSuggestion, bool());
MOCK_METHOD0(ShouldProcessBlocklistSearchSuggestionWithHash, bool());
MOCK_METHOD0(ShouldProcessSearchSuggestionSelected, bool());
@@ -113,7 +103,6 @@
MOCK_METHOD0(ShouldSendOmniboxFocusChanged, bool());
MOCK_METHOD0(ShouldSendMostVisitedInfo, bool());
MOCK_METHOD0(ShouldSendNtpTheme, bool());
- MOCK_METHOD0(ShouldSendLocalBackgroundSelected, bool());
MOCK_METHOD0(ShouldProcessThemeChangeMessages, bool());
};
@@ -552,99 +541,6 @@
GetSearchIPCRouter().SendNtpTheme(NtpTheme());
}
-TEST_F(SearchIPCRouterTest, SendLocalBackgroundSelectedMsg) {
- NavigateAndCommitActiveTab(GURL("chrome-search://foo/baz"));
- SetupMockDelegateAndPolicy();
- MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
- EXPECT_CALL(*policy, ShouldSendLocalBackgroundSelected())
- .Times(1)
- .WillOnce(Return(true));
-
- EXPECT_CALL(*mock_embedded_search_client(), LocalBackgroundSelected());
- GetSearchIPCRouter().SendLocalBackgroundSelected();
-}
-
-TEST_F(SearchIPCRouterTest, DoNotSendLocalBackgroundSelectedMsg) {
- NavigateAndCommitActiveTab(GURL("chrome-search://foo/baz"));
- SetupMockDelegateAndPolicy();
- MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
- EXPECT_CALL(*policy, ShouldSendLocalBackgroundSelected())
- .Times(1)
- .WillOnce(Return(false));
-
- EXPECT_CALL(*mock_embedded_search_client(), LocalBackgroundSelected())
- .Times(0);
- GetSearchIPCRouter().SendLocalBackgroundSelected();
-}
-
-TEST_F(SearchIPCRouterTest, ProcessSetCustomBackgroundInfoMsg) {
- NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
- SetupMockDelegateAndPolicy();
- MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
- GURL bg_url("www.foo.com");
- std::string attr1("foo");
- std::string attr2("bar");
- GURL action_url("www.bar.com");
- std::string collection_id("Art");
- EXPECT_CALL(*mock_delegate(),
- OnSetCustomBackgroundInfo(bg_url, attr1, attr2, action_url,
- collection_id))
- .Times(1);
- EXPECT_CALL(*policy, ShouldProcessSetCustomBackgroundInfo())
- .Times(1)
- .WillOnce(Return(true));
-
- GetSearchIPCRouter().SetCustomBackgroundInfo(bg_url, attr1, attr2, action_url,
- collection_id);
-}
-
-TEST_F(SearchIPCRouterTest, IgnoreSetCustomBackgroundInfoMsg) {
- NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
- SetupMockDelegateAndPolicy();
- MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
- GURL bg_url("www.foo.com");
- std::string attr1("foo");
- std::string attr2("bar");
- GURL action_url("www.bar.com");
- std::string collection_id("Art");
- EXPECT_CALL(*mock_delegate(),
- OnSetCustomBackgroundInfo(bg_url, attr1, attr2, action_url,
- collection_id))
- .Times(0);
- EXPECT_CALL(*policy, ShouldProcessSetCustomBackgroundInfo())
- .Times(1)
- .WillOnce(Return(false));
-
- GetSearchIPCRouter().SetCustomBackgroundInfo(bg_url, attr1, attr2, action_url,
- collection_id);
-}
-
-TEST_F(SearchIPCRouterTest, ProcessSelectLocalBackgroundImageMsg) {
- NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
- SetupMockDelegateAndPolicy();
- MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
- GURL bg_url("www.foo.com");
- EXPECT_CALL(*mock_delegate(), OnSelectLocalBackgroundImage()).Times(1);
- EXPECT_CALL(*policy, ShouldProcessSelectLocalBackgroundImage())
- .Times(1)
- .WillOnce(Return(true));
-
- GetSearchIPCRouter().SelectLocalBackgroundImage();
-}
-
-TEST_F(SearchIPCRouterTest, IgnoreSelectLocalBackgroundImageMsg) {
- NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
- SetupMockDelegateAndPolicy();
- MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
- GURL bg_url("www.foo.com");
- EXPECT_CALL(*mock_delegate(), OnSelectLocalBackgroundImage()).Times(0);
- EXPECT_CALL(*policy, ShouldProcessSelectLocalBackgroundImage())
- .Times(1)
- .WillOnce(Return(false));
-
- GetSearchIPCRouter().SelectLocalBackgroundImage();
-}
-
TEST_F(SearchIPCRouterTest, ProcessBlocklistSearchSuggestion) {
NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
SetupMockDelegateAndPolicy();
diff --git a/chrome/browser/ui/search/search_tab_helper.cc b/chrome/browser/ui/search/search_tab_helper.cc
index 38f37ce0..ab00dbc5 100644
--- a/chrome/browser/ui/search/search_tab_helper.cc
+++ b/chrome/browser/ui/search/search_tab_helper.cc
@@ -140,8 +140,6 @@
instant_service_->RemoveObserver(this);
if (auto* helper = OmniboxTabHelper::FromWebContents(web_contents_))
helper->RemoveObserver(this);
- if (select_file_dialog_)
- select_file_dialog_->ListenerDestroyed();
}
void SearchTabHelper::BindEmbeddedSearchConnecter(
@@ -311,52 +309,6 @@
logger_->LogMostVisitedNavigation(impression);
}
-void SearchTabHelper::OnSetCustomBackgroundInfo(
- const GURL& background_url,
- const std::string& attribution_line_1,
- const std::string& attribution_line_2,
- const GURL& action_url,
- const std::string& collection_id) {
- if (instant_service_) {
- instant_service_->SetCustomBackgroundInfo(
- background_url, attribution_line_1, attribution_line_2, action_url,
- collection_id);
- }
-}
-
-void SearchTabHelper::FileSelected(const base::FilePath& path,
- int index,
- void* params) {
- if (instant_service_) {
- profile()->set_last_selected_directory(path.DirName());
- instant_service_->SelectLocalBackgroundImage(path);
- }
-
- select_file_dialog_ = nullptr;
- // File selection can happen at any time after NTP load, and is not logged
- // with the event.
- if (logger_) {
- logger_->LogEvent(NTP_CUSTOMIZE_LOCAL_IMAGE_DONE,
- base::TimeDelta::FromSeconds(0));
- logger_->LogEvent(NTP_BACKGROUND_UPLOAD_DONE,
- base::TimeDelta::FromSeconds(0));
- }
-
- ipc_router_.SendLocalBackgroundSelected();
-}
-
-void SearchTabHelper::FileSelectionCanceled(void* params) {
- select_file_dialog_ = nullptr;
- // File selection can happen at any time after NTP load, and is not logged
- // with the event.
- if (logger_) {
- logger_->LogEvent(NTP_CUSTOMIZE_LOCAL_IMAGE_CANCEL,
- base::TimeDelta::FromSeconds(0));
- logger_->LogEvent(NTP_BACKGROUND_UPLOAD_CANCEL,
- base::TimeDelta::FromSeconds(0));
- }
-}
-
void SearchTabHelper::OnOmniboxInputStateChanged() {
ipc_router_.SetInputInProgress(IsInputInProgress());
}
@@ -372,31 +324,6 @@
ipc_router_.SetInputInProgress(IsInputInProgress());
}
-void SearchTabHelper::OnSelectLocalBackgroundImage() {
- if (select_file_dialog_)
- return;
-
- select_file_dialog_ = ui::SelectFileDialog::Create(
- this, std::make_unique<ChromeSelectFilePolicy>(web_contents_));
-
- const base::FilePath directory = profile()->last_selected_directory();
-
- gfx::NativeWindow parent_window = web_contents_->GetTopLevelNativeWindow();
-
- ui::SelectFileDialog::FileTypeInfo file_types;
- file_types.allowed_paths = ui::SelectFileDialog::FileTypeInfo::NATIVE_PATH;
- file_types.extensions.resize(1);
- file_types.extensions[0].push_back(FILE_PATH_LITERAL("jpg"));
- file_types.extensions[0].push_back(FILE_PATH_LITERAL("jpeg"));
- file_types.extensions[0].push_back(FILE_PATH_LITERAL("png"));
- file_types.extension_description_overrides.push_back(
- l10n_util::GetStringUTF16(IDS_UPLOAD_IMAGE_FORMAT));
-
- select_file_dialog_->SelectFile(
- ui::SelectFileDialog::SELECT_OPEN_FILE, std::u16string(), directory,
- &file_types, 0, base::FilePath::StringType(), parent_window, nullptr);
-}
-
void SearchTabHelper::OnBlocklistSearchSuggestion(int task_version,
long task_id) {
if (search_suggest_service_)
diff --git a/chrome/browser/ui/search/search_tab_helper.h b/chrome/browser/ui/search/search_tab_helper.h
index feadf6e..3a0eab1 100644
--- a/chrome/browser/ui/search/search_tab_helper.h
+++ b/chrome/browser/ui/search/search_tab_helper.h
@@ -25,7 +25,6 @@
#include "content/public/browser/reload_type.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_user_data.h"
-#include "ui/shell_dialogs/select_file_dialog.h"
#if defined(OS_ANDROID)
#error "Instant is only used on desktop";
@@ -54,7 +53,6 @@
public content::WebContentsUserData<SearchTabHelper>,
public InstantServiceObserver,
public SearchIPCRouter::Delegate,
- public ui::SelectFileDialog::Listener,
public OmniboxTabHelper::Observer {
public:
~SearchTabHelper() override;
@@ -79,9 +77,6 @@
friend class content::WebContentsUserData<SearchTabHelper>;
friend class SearchIPCRouterTest;
- FRIEND_TEST_ALL_PREFIXES(SearchTabHelperTest,
- FileSelectedUpdatesLastSelectedDirectory);
-
explicit SearchTabHelper(content::WebContents* web_contents);
// Overridden from contents::WebContentsObserver:
@@ -108,12 +103,6 @@
const ntp_tiles::NTPTileImpression& impression) override;
void OnLogMostVisitedNavigation(
const ntp_tiles::NTPTileImpression& impression) override;
- void OnSetCustomBackgroundInfo(const GURL& background_url,
- const std::string& attribution_line_1,
- const std::string& attribution_line_2,
- const GURL& action_url,
- const std::string& collection_id) override;
- void OnSelectLocalBackgroundImage() override;
void OnBlocklistSearchSuggestion(int task_version, long task_id) override;
void OnBlocklistSearchSuggestionWithHash(int task_version,
long task_id,
@@ -132,12 +121,6 @@
void MostVisitedInfoChanged(
const InstantMostVisitedInfo& most_visited_info) override;
- // Overridden from SelectFileDialog::Listener:
- void FileSelected(const base::FilePath& path,
- int index,
- void* params) override;
- void FileSelectionCanceled(void* params) override;
-
// Overridden from OmniboxTabHelper::Observer:
void OnOmniboxInputStateChanged() override;
void OnOmniboxFocusChanged(OmniboxFocusState state,
@@ -174,8 +157,6 @@
bool is_setting_title_ = false;
- scoped_refptr<ui::SelectFileDialog> select_file_dialog_;
-
chrome_colors::ChromeColorsService* chrome_colors_service_;
std::unique_ptr<NTPUserDataLogger> logger_;
diff --git a/chrome/browser/ui/webui/welcome/ntp_background_handler.cc b/chrome/browser/ui/webui/welcome/ntp_background_handler.cc
index c515b9d1..7fa1d79b 100644
--- a/chrome/browser/ui/webui/welcome/ntp_background_handler.cc
+++ b/chrome/browser/ui/webui/welcome/ntp_background_handler.cc
@@ -12,8 +12,8 @@
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search/background/ntp_backgrounds.h"
-#include "chrome/browser/search/instant_service.h"
-#include "chrome/browser/search/instant_service_factory.h"
+#include "chrome/browser/search/background/ntp_custom_background_service.h"
+#include "chrome/browser/search/background/ntp_custom_background_service_factory.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/grit/welcome_resources.h"
#include "components/strings/grit/components_strings.h"
@@ -52,9 +52,9 @@
}
void NtpBackgroundHandler::HandleClearBackground(const base::ListValue* args) {
- InstantService* instant_service =
- InstantServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()));
- instant_service->ResetCustomBackgroundInfo();
+ auto* service = NtpCustomBackgroundServiceFactory::GetForProfile(
+ Profile::FromWebUI(web_ui()));
+ service->ResetCustomBackgroundInfo();
}
void NtpBackgroundHandler::HandleGetBackgrounds(const base::ListValue* args) {
@@ -122,18 +122,18 @@
int background_index = list[0].GetInt();
std::array<GURL, kNtpBackgroundsCount> NtpBackgrounds = GetNtpBackgrounds();
- InstantService* instant_service =
- InstantServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()));
+ auto* service = NtpCustomBackgroundServiceFactory::GetForProfile(
+ Profile::FromWebUI(web_ui()));
switch (background_index) {
case static_cast<int>(NtpBackgrounds::kArt):
- instant_service->SetCustomBackgroundInfo(
+ service->SetCustomBackgroundInfo(
NtpBackgrounds[background_index], "Universe Cosmic Vacum",
"Philipp Rietz — Walli",
GURL("https://walli.shanga.co/image/view/?id=370"), "");
break;
case static_cast<int>(NtpBackgrounds::kCityscape):
- instant_service->SetCustomBackgroundInfo(
+ service->SetCustomBackgroundInfo(
NtpBackgrounds[background_index],
l10n_util::GetStringFUTF8(IDS_WELCOME_NTP_BACKGROUND_PHOTO_BY_LABEL,
u"Ev Tchebotarev"),
@@ -143,20 +143,20 @@
"");
break;
case static_cast<int>(NtpBackgrounds::kEarth):
- instant_service->SetCustomBackgroundInfo(
+ service->SetCustomBackgroundInfo(
NtpBackgrounds[background_index],
l10n_util::GetStringFUTF8(IDS_WELCOME_NTP_BACKGROUND_PHOTO_BY_LABEL,
u"NASA Image Library"),
"", GURL("https://www.google.com/sky/"), "");
break;
case static_cast<int>(NtpBackgrounds::kGeometricShapes):
- instant_service->SetCustomBackgroundInfo(
+ service->SetCustomBackgroundInfo(
NtpBackgrounds[background_index], "Tessellation 15",
"Justin Prno — Walli",
GURL("https://walli.shanga.co/image/view/?id=1375"), "");
break;
case static_cast<int>(NtpBackgrounds::kLandscape):
- instant_service->SetCustomBackgroundInfo(
+ service->SetCustomBackgroundInfo(
NtpBackgrounds[background_index],
l10n_util::GetStringFUTF8(IDS_WELCOME_NTP_BACKGROUND_PHOTO_BY_LABEL,
u"Giulio Rosso Chioso"),
diff --git a/chrome/common/search/instant_mojom_traits.h b/chrome/common/search/instant_mojom_traits.h
index ac1d2907..67ca202 100644
--- a/chrome/common/search/instant_mojom_traits.h
+++ b/chrome/common/search/instant_mojom_traits.h
@@ -59,11 +59,6 @@
IPC_STRUCT_TRAITS_BEGIN(NtpTheme)
IPC_STRUCT_TRAITS_MEMBER(using_default_theme)
- IPC_STRUCT_TRAITS_MEMBER(custom_background_url)
- IPC_STRUCT_TRAITS_MEMBER(custom_background_attribution_line_1)
- IPC_STRUCT_TRAITS_MEMBER(custom_background_attribution_line_2)
- IPC_STRUCT_TRAITS_MEMBER(custom_background_attribution_action_url)
- IPC_STRUCT_TRAITS_MEMBER(collection_id)
IPC_STRUCT_TRAITS_MEMBER(background_color)
IPC_STRUCT_TRAITS_MEMBER(text_color)
IPC_STRUCT_TRAITS_MEMBER(text_color_light)
diff --git a/chrome/common/search/instant_types.cc b/chrome/common/search/instant_types.cc
index 7991d6e..2662979 100644
--- a/chrome/common/search/instant_types.cc
+++ b/chrome/common/search/instant_types.cc
@@ -12,14 +12,6 @@
bool NtpTheme::operator==(const NtpTheme& rhs) const {
return using_default_theme == rhs.using_default_theme &&
- custom_background_url == rhs.custom_background_url &&
- custom_background_attribution_line_1 ==
- rhs.custom_background_attribution_line_1 &&
- custom_background_attribution_line_2 ==
- rhs.custom_background_attribution_line_2 &&
- custom_background_attribution_action_url ==
- rhs.custom_background_attribution_action_url &&
- collection_id == rhs.collection_id &&
background_color == rhs.background_color &&
text_color == rhs.text_color &&
text_color_light == rhs.text_color_light && theme_id == rhs.theme_id &&
diff --git a/chrome/common/search/instant_types.h b/chrome/common/search/instant_types.h
index a3aaf18..73106778 100644
--- a/chrome/common/search/instant_types.h
+++ b/chrome/common/search/instant_types.h
@@ -54,21 +54,6 @@
// True if the default theme is selected.
bool using_default_theme = true;
- // Url of the custom background selected by the user.
- GURL custom_background_url;
-
- // First attribution string for custom background.
- std::string custom_background_attribution_line_1;
-
- // Second attribution string for custom background.
- std::string custom_background_attribution_line_2;
-
- // Url to learn more info about the custom background.
- GURL custom_background_attribution_action_url;
-
- // Id of the collection being used for "daily refresh".
- std::string collection_id;
-
// The theme background color. Always valid.
SkColor background_color = gfx::kPlaceholderColor;
diff --git a/chrome/common/search/mock_embedded_search_client.h b/chrome/common/search/mock_embedded_search_client.h
index fe61415..2f9143e3e 100644
--- a/chrome/common/search/mock_embedded_search_client.h
+++ b/chrome/common/search/mock_embedded_search_client.h
@@ -19,7 +19,6 @@
MOCK_METHOD1(MostVisitedInfoChanged, void(const InstantMostVisitedInfo&));
MOCK_METHOD1(SetInputInProgress, void(bool));
MOCK_METHOD1(ThemeChanged, void(const NtpTheme&));
- MOCK_METHOD0(LocalBackgroundSelected, void());
};
#endif // CHROME_COMMON_SEARCH_MOCK_EMBEDDED_SEARCH_CLIENT_H_
diff --git a/chrome/common/search/search.mojom b/chrome/common/search/search.mojom
index c442fb49..78aea98 100644
--- a/chrome/common/search/search.mojom
+++ b/chrome/common/search/search.mojom
@@ -70,16 +70,6 @@
// New Tab Page.
LogMostVisitedNavigation(int32 page_seq_no, NTPTileImpression impression);
- // Updates the NTP custom background preferences.
- SetCustomBackgroundInfo(url.mojom.Url background_url,
- string attribution_line_1,
- string attribution_line_2,
- url.mojom.Url action_url,
- string collection_id);
-
- // Let the user select a local file for the NTP background.
- SelectLocalBackgroundImage();
-
// Add a search suggestion task id to the blocklist.
BlocklistSearchSuggestion(int32 task_version, int64 task_id);
@@ -137,7 +127,4 @@
// The NTP theme has changed; update accordingly.
ThemeChanged(NtpTheme theme);
-
- // A background image was selected from the file upload dialog.
- LocalBackgroundSelected();
};
diff --git a/chrome/renderer/searchbox/searchbox.cc b/chrome/renderer/searchbox/searchbox.cc
index a3f4938..69ee61c 100644
--- a/chrome/renderer/searchbox/searchbox.cc
+++ b/chrome/renderer/searchbox/searchbox.cc
@@ -287,20 +287,6 @@
embedded_search_service_->UndoMostVisitedDeletion(page_seq_no_, url);
}
-void SearchBox::SetCustomBackgroundInfo(const GURL& background_url,
- const std::string& attribution_line_1,
- const std::string& attribution_line_2,
- const GURL& action_url,
- const std::string& collection_id) {
- embedded_search_service_->SetCustomBackgroundInfo(
- background_url, attribution_line_1, attribution_line_2, action_url,
- collection_id);
-}
-
-void SearchBox::SelectLocalBackgroundImage() {
- embedded_search_service_->SelectLocalBackgroundImage();
-}
-
void SearchBox::BlocklistSearchSuggestion(int task_version, long task_id) {
embedded_search_service_->BlocklistSearchSuggestion(task_version, task_id);
}
@@ -416,13 +402,6 @@
SearchBoxExtension::DispatchThemeChange(render_frame()->GetWebFrame());
}
-void SearchBox::LocalBackgroundSelected() {
- if (can_run_js_in_renderframe_) {
- SearchBoxExtension::DispatchLocalBackgroundSelected(
- render_frame()->GetWebFrame());
- }
-}
-
GURL SearchBox::GetURLForMostVisitedItem(InstantRestrictedID item_id) const {
InstantMostVisitedItem item;
return GetMostVisitedItemWithID(item_id, &item) ? item.url : GURL();
diff --git a/chrome/renderer/searchbox/searchbox.h b/chrome/renderer/searchbox/searchbox.h
index d96bf9add..8dd0416b 100644
--- a/chrome/renderer/searchbox/searchbox.h
+++ b/chrome/renderer/searchbox/searchbox.h
@@ -109,17 +109,6 @@
// Sends ToggleShortcutsVisibility to the browser.
void ToggleShortcutsVisibility(bool do_notify);
- // Updates the NTP custom background preferences, sometimes this includes
- // image attributions.
- void SetCustomBackgroundInfo(const GURL& background_url,
- const std::string& attribution_line_1,
- const std::string& attribution_line_2,
- const GURL& action_url,
- const std::string& collection_id);
-
- // Let the user select a local file for the NTP background.
- void SelectLocalBackgroundImage();
-
// Add a search suggestion task id to the blocklist.
void BlocklistSearchSuggestion(int task_version, long task_id);
@@ -166,7 +155,6 @@
const InstantMostVisitedInfo& most_visited_info) override;
void SetInputInProgress(bool input_in_progress) override;
void ThemeChanged(const NtpTheme& theme) override;
- void LocalBackgroundSelected() override;
void AddCustomLinkResult(bool success);
void UpdateCustomLinkResult(bool success);
diff --git a/chrome/renderer/searchbox/searchbox_extension.cc b/chrome/renderer/searchbox/searchbox_extension.cc
index 0d5c9a2..8e8e84a 100644
--- a/chrome/renderer/searchbox/searchbox_extension.cc
+++ b/chrome/renderer/searchbox/searchbox_extension.cc
@@ -318,23 +318,6 @@
}
}
- builder.Set("customBackgroundConfigured",
- !theme.custom_background_url.is_empty());
-
- // If a custom background has been set provide the relevant information to the
- // page.
- if (!theme.custom_background_url.is_empty()) {
- builder.Set("imageUrl", theme.custom_background_url.spec());
- builder.Set("attributionActionUrl",
- theme.custom_background_attribution_action_url.spec());
- builder.Set("attribution1", theme.custom_background_attribution_line_1);
- builder.Set("attribution2", theme.custom_background_attribution_line_2);
- builder.Set("collectionId", theme.collection_id);
- // Clear the theme attribution url, as it shouldn't be shown when
- // a custom background is set.
- builder.Set("attributionUrl", std::string());
- }
-
return builder.Build();
}
@@ -422,20 +405,6 @@
" true;"
"}";
-static const char kDispatchLocalBackgroundSelectedScript[] =
- "if (window.chrome &&"
- " window.chrome.embeddedSearch &&"
- " window.chrome.embeddedSearch.newTabPage &&"
- " window.chrome.embeddedSearch.newTabPage.onlocalbackgroundselected &&"
- " typeof "
- "window.chrome.embeddedSearch.newTabPage.onlocalbackgroundselected =="
- " 'function') {"
- " "
- "window.chrome.embeddedSearch.newTabPage."
- "onlocalbackgroundselected();"
- " true;"
- "}";
-
// ----------------------------------------------------------------------------
class SearchBoxBindings : public gin::Wrappable<SearchBoxBindings> {
@@ -553,13 +522,6 @@
int tile_title_source,
int tile_source,
int tile_type);
- static void ResetCustomBackgroundInfo();
- static void SetCustomBackgroundInfo(const std::string& background_url,
- const std::string& attribution_line_1,
- const std::string& attribution_line_2,
- const std::string& attributionActionUrl,
- const std::string& collection_id);
- static void SelectLocalBackgroundImage();
static void BlocklistSearchSuggestion(int task_version, int task_id);
static void BlocklistSearchSuggestionWithHash(int task_version,
int task_id,
@@ -612,12 +574,6 @@
&NewTabPageBindings::LogMostVisitedImpression)
.SetMethod("logMostVisitedNavigation",
&NewTabPageBindings::LogMostVisitedNavigation)
- .SetMethod("resetBackgroundInfo",
- &NewTabPageBindings::ResetCustomBackgroundInfo)
- .SetMethod("setBackgroundInfo",
- &NewTabPageBindings::SetCustomBackgroundInfo)
- .SetMethod("selectLocalBackgroundImage",
- &NewTabPageBindings::SelectLocalBackgroundImage)
// These methods have been renamed to match BlocklistSearchSuggestion*
// below, but are kept until JavaScript calls can be migrated.
// TODO: Remove the following two additions per guidance in b/179534247
@@ -832,45 +788,6 @@
}
// static
-void NewTabPageBindings::ResetCustomBackgroundInfo() {
- SetCustomBackgroundInfo(std::string(), std::string(), std::string(),
- std::string(), std::string());
-}
-
-// static
-void NewTabPageBindings::SetCustomBackgroundInfo(
- const std::string& background_url,
- const std::string& attribution_line_1,
- const std::string& attribution_line_2,
- const std::string& attribution_action_url,
- const std::string& collection_id) {
- SearchBox* search_box = GetSearchBoxForCurrentContext();
- search_box->SetCustomBackgroundInfo(
- GURL(background_url), attribution_line_1, attribution_line_2,
- GURL(attribution_action_url), collection_id);
- // Captures different events that occur when a background selection is made
- // and 'Done' is clicked on the dialog.
- if (!collection_id.empty()) {
- search_box->LogEvent(
- NTPLoggingEventType::NTP_BACKGROUND_DAILY_REFRESH_ENABLED);
- } else if (background_url.empty()) {
- search_box->LogEvent(
- NTPLoggingEventType::NTP_CUSTOMIZE_RESTORE_BACKGROUND_CLICKED);
- search_box->LogEvent(NTPLoggingEventType::NTP_BACKGROUND_IMAGE_RESET);
- } else {
- search_box->LogEvent(
- NTPLoggingEventType::NTP_CUSTOMIZE_CHROME_BACKGROUND_DONE);
- search_box->LogEvent(NTPLoggingEventType::NTP_BACKGROUND_IMAGE_SET);
- }
-}
-
-// static
-void NewTabPageBindings::SelectLocalBackgroundImage() {
- SearchBox* search_box = GetSearchBoxForCurrentContext();
- search_box->SelectLocalBackgroundImage();
-}
-
-// static
void NewTabPageBindings::BlocklistSearchSuggestion(const int task_version,
const int task_id) {
SearchBox* search_box = GetSearchBoxForCurrentContext();
@@ -1052,9 +969,3 @@
void SearchBoxExtension::DispatchThemeChange(blink::WebLocalFrame* frame) {
Dispatch(frame, kDispatchThemeChangeEventScript);
}
-
-// static
-void SearchBoxExtension::DispatchLocalBackgroundSelected(
- blink::WebLocalFrame* frame) {
- Dispatch(frame, kDispatchLocalBackgroundSelectedScript);
-}
diff --git a/chrome/renderer/searchbox/searchbox_extension.h b/chrome/renderer/searchbox/searchbox_extension.h
index 6a2359f..be0b812 100644
--- a/chrome/renderer/searchbox/searchbox_extension.h
+++ b/chrome/renderer/searchbox/searchbox_extension.h
@@ -35,7 +35,6 @@
static void DispatchKeyCaptureChange(blink::WebLocalFrame* frame);
static void DispatchMostVisitedChanged(blink::WebLocalFrame* frame);
static void DispatchThemeChange(blink::WebLocalFrame* frame);
- static void DispatchLocalBackgroundSelected(blink::WebLocalFrame* frame);
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(SearchBoxExtension);