Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2757)

Unified Diff: chrome/browser/ui/search/instant_ntp_prerenderer.cc

Issue 20388003: Reload Instant NTP and Instant-process tabs on search url change (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Format and lint Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/search/instant_ntp_prerenderer.cc
diff --git a/chrome/browser/ui/search/instant_ntp_prerenderer.cc b/chrome/browser/ui/search/instant_ntp_prerenderer.cc
index 2edfc11dd058ec678cf8e23164ca43fcb91fc51a..7330ea9764a9087206ec95887ba816bc26ff8bc6 100644
--- a/chrome/browser/ui/search/instant_ntp_prerenderer.cc
+++ b/chrome/browser/ui/search/instant_ntp_prerenderer.cc
@@ -54,11 +54,7 @@ InstantNTPPrerenderer::InstantNTPPrerenderer(Profile* profile,
profile_pref_registrar_.Init(prefs);
profile_pref_registrar_.Add(
prefs::kSearchSuggestEnabled,
- base::Bind(&InstantNTPPrerenderer::ReloadStaleNTP,
- base::Unretained(this)));
- profile_pref_registrar_.Add(
- prefs::kDefaultSearchProviderID,
- base::Bind(&InstantNTPPrerenderer::OnDefaultSearchProviderChanged,
+ base::Bind(&InstantNTPPrerenderer::ReloadInstantNTP,
base::Unretained(this)));
}
net::NetworkChangeNotifier::AddNetworkChangeObserver(this);
@@ -68,9 +64,15 @@ InstantNTPPrerenderer::~InstantNTPPrerenderer() {
net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this);
}
-void InstantNTPPrerenderer::PreloadInstantNTP() {
- DCHECK(!ntp());
- ReloadStaleNTP();
+void InstantNTPPrerenderer::Init() {
samarth 2013/08/12 19:07:28 Currently this function can be called multiple tim
Anuj 2013/08/13 00:18:09 Done.
+ InstantService* instant_service =
+ InstantServiceFactory::GetForProfile(profile_);
+ instant_service->AddObserver(this);
+ ReloadInstantNTP();
+}
+
+void InstantNTPPrerenderer::ReloadInstantNTP() {
+ ResetNTP(GetInstantURL());
}
scoped_ptr<content::WebContents> InstantNTPPrerenderer::ReleaseNTPContents() {
@@ -84,7 +86,7 @@ scoped_ptr<content::WebContents> InstantNTPPrerenderer::ReleaseNTPContents() {
scoped_ptr<content::WebContents> ntp_contents = ntp_->ReleaseContents();
// Preload a new InstantNTP.
- ResetNTP(GetInstantURL());
+ ReloadInstantNTP();
return ntp_contents.Pass();
}
@@ -175,7 +177,7 @@ void InstantNTPPrerenderer::OnNetworkChanged(
return;
if (!ntp() || ntp()->IsLocal())
- ResetNTP(GetInstantURL());
+ ReloadInstantNTP();
}
void InstantNTPPrerenderer::InstantSupportDetermined(
@@ -237,28 +239,15 @@ void InstantNTPPrerenderer::InstantPageLoadFailed(
ResetNTP(GetLocalInstantURL());
}
-void InstantNTPPrerenderer::OnDefaultSearchProviderChanged(
- const std::string& pref_name) {
- DCHECK_EQ(pref_name, std::string(prefs::kDefaultSearchProviderID));
- if (!ntp())
- return;
-
- ResetNTP(GetInstantURL());
-}
-
void InstantNTPPrerenderer::ResetNTP(const std::string& instant_url) {
// Instant NTP is only used in extended mode so we should always have a
// non-empty URL to use.
DCHECK(!instant_url.empty());
ntp_.reset(new InstantNTP(this, instant_url, profile_));
- ntp_->InitContents(base::Bind(&InstantNTPPrerenderer::ReloadStaleNTP,
+ ntp_->InitContents(base::Bind(&InstantNTPPrerenderer::ReloadInstantNTP,
base::Unretained(this)));
}
-void InstantNTPPrerenderer::ReloadStaleNTP() {
- ResetNTP(GetInstantURL());
-}
-
bool InstantNTPPrerenderer::PageIsCurrent() const {
const std::string& instant_url = GetInstantURL();
if (instant_url.empty() ||
@@ -290,3 +279,14 @@ bool InstantNTPPrerenderer::ShouldSwitchToLocalNTP() const {
// (unless the finch flag to use the remote NTP is set).
return !(InStartup() && chrome::ShouldPreferRemoteNTPOnStartup());
}
+
+////////////////////////////////////////////////////////////////////////////////
+// InstantNTPPrerenderer, InstantServiceObserver implementation:
+
+void InstantNTPPrerenderer::DefaultSearchProviderChanged() {
+ ReloadInstantNTP();
+}
+
+void InstantNTPPrerenderer::GoogleURLUpdated() {
+ ReloadInstantNTP();
+}

Powered by Google App Engine
This is Rietveld 408576698