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

Unified Diff: chrome/browser/search/instant_service.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: Added ui and unit tests Created 7 years, 5 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/search/instant_service.cc
diff --git a/chrome/browser/search/instant_service.cc b/chrome/browser/search/instant_service.cc
index d3763b03d1fe9d4713174082a2bb2ec51b4e4bb6..1f00138d0136fadf3bcb44ec9bf4e100b171a020 100644
--- a/chrome/browser/search/instant_service.cc
+++ b/chrome/browser/search/instant_service.cc
@@ -7,6 +7,7 @@
#include <vector>
#include "base/logging.h"
+#include "base/prefs/pref_service.h"
#include "base/strings/string_number_conversions.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/history/history_notifications.h"
@@ -19,18 +20,25 @@
#include "chrome/browser/search/local_ntp_source.h"
#include "chrome/browser/search/most_visited_iframe_source.h"
#include "chrome/browser/search/search.h"
+#include "chrome/browser/search_engines/template_url.h"
+#include "chrome/browser/search_engines/template_url_service.h"
+#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/themes/theme_properties.h"
#include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/themes/theme_service_factory.h"
#include "chrome/browser/ui/webui/favicon_source.h"
#include "chrome/browser/ui/webui/ntp/thumbnail_source.h"
#include "chrome/browser/ui/webui/theme_source.h"
+#include "chrome/common/pref_names.h"
#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_service.h"
+#include "content/public/browser/notification_source.h"
#include "content/public/browser/notification_types.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/url_data_source.h"
#include "grit/theme_resources.h"
+#include "net/base/net_util.h"
#include "net/url_request/url_request.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/image/image_skia.h"
@@ -90,14 +98,26 @@ InstantService::InstantService(Profile* profile)
content::Source<ThemeService>(
ThemeServiceFactory::GetForProfile(profile_)));
- content::URLDataSource::Add(profile, new ThemeSource(profile));
+ content::URLDataSource::Add(profile_, new ThemeSource(profile_));
#endif // defined(ENABLE_THEMES)
- content::URLDataSource::Add(profile, new ThumbnailSource(profile));
- content::URLDataSource::Add(profile, new FaviconSource(
- profile, FaviconSource::FAVICON));
- content::URLDataSource::Add(profile, new LocalNtpSource(profile));
- content::URLDataSource::Add(profile, new MostVisitedIframeSource());
+ registrar_.Add(this,
+ chrome::NOTIFICATION_GOOGLE_URL_UPDATED,
+ content::Source<Profile>(profile_->GetOriginalProfile()));
+
+ content::URLDataSource::Add(profile_, new ThumbnailSource(profile_));
+ content::URLDataSource::Add(
+ profile_, new FaviconSource(profile_, FaviconSource::FAVICON));
+ content::URLDataSource::Add(profile_, new LocalNtpSource(profile_));
+ content::URLDataSource::Add(profile_, new MostVisitedIframeSource());
+
+ profile_pref_registrar_.Init(profile_->GetPrefs());
+ profile_pref_registrar_.Add(
+ prefs::kDefaultSearchProviderID,
+ base::Bind(&InstantService::OnDefaultSearchProviderChanged,
+ base::Unretained(this)));
+
+ AddObserver(ntp_prerenderer());
samarth 2013/08/02 21:51:15 Objects should add themselves as observers rather
Anuj 2013/08/09 07:22:00 Done.
}
InstantService::~InstantService() {
@@ -192,7 +212,7 @@ void InstantService::OnBrowserInstantControllerCreated() {
++browser_instant_controller_object_count_;
if (browser_instant_controller_object_count_ == 1)
- ntp_prerenderer_.PreloadInstantNTP();
+ ntp_prerenderer_.ReloadInstantNTP();
}
void InstantService::OnBrowserInstantControllerDestroyed() {
@@ -242,6 +262,12 @@ void InstantService::Observe(int type,
break;
}
#endif // defined(ENABLE_THEMES)
+ case chrome::NOTIFICATION_GOOGLE_URL_UPDATED: {
+ OnGoogleURLUpdated(
+ content::Source<Profile>(source).ptr(),
+ content::Details<GoogleURLTracker::UpdatedDetails>(details).ptr());
+ break;
+ }
default:
NOTREACHED() << "Unexpected notification type in InstantService.";
}
@@ -383,6 +409,45 @@ void InstantService::OnThemeChanged(ThemeService* theme_service) {
ThemeInfoChanged(*theme_info_));
}
+void InstantService::OnGoogleURLUpdated(
+ Profile* profile,
+ GoogleURLTracker::UpdatedDetails* details) {
+ GURL last_prompted_url(
+ profile->GetPrefs()->GetString(prefs::kLastPromptedGoogleURL));
+
+ // See GoogleURLTracker::OnURLFetchComplete.
+ // last_prompted_url.is_empty indicated very first run of Chrome. So there is
+ // no need to tamper with Instant resources.
+ if (last_prompted_url.is_empty())
+ return;
+
+ // Google URL change is just the scheme change (http <-> https). Since this
samarth 2013/08/02 21:51:15 nit: How about: Only the scheme changed. Ignore it
Anuj 2013/08/09 07:22:00 Done.
+ // does not trigger yellow infobar prompting the search url change, the ntp
+ // url refresh is also not triggered.
+ if (net::StripWWWFromHost(details->first) ==
+ net::StripWWWFromHost(details->second))
+ return;
+
+ FOR_EACH_OBSERVER(InstantServiceObserver, observers_, GoogleURLUpdated());
+}
+
+void InstantService::OnDefaultSearchProviderChanged(
+ const std::string& pref_name) {
+ DCHECK_EQ(pref_name, std::string(prefs::kDefaultSearchProviderID));
+ const TemplateURL* template_url = TemplateURLServiceFactory::GetForProfile(
+ profile_)->GetDefaultSearchProvider();
+ if (!template_url) {
+ // A NULL |template_url| could mean either this notification is sent during
+ // the browser start up operation or the user now has no default search
+ // provider. There is no way for the user to reach this state using the
+ // Chrome settings. Only explicitly poking at the DB or bugs in the Sync
+ // could cause that, neither of which we support.
+ return;
+ }
+ FOR_EACH_OBSERVER(
+ InstantServiceObserver, observers_, DefaultSearchProviderChanged());
+}
+
InstantNTPPrerenderer* InstantService::ntp_prerenderer() {
return &ntp_prerenderer_;
}

Powered by Google App Engine
This is Rietveld 408576698