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

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: Fixed InstantNTPPrerendererTest Created 7 years, 3 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
« no previous file with comments | « chrome/browser/search/instant_service.h ('k') | chrome/browser/search/instant_service_observer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/search/instant_service.cc
diff --git a/chrome/browser/search/instant_service.cc b/chrome/browser/search/instant_service.cc
index 62e8580219b32d5f12b5399ba1ae5057c5085115..c50d2716d87d52072854f151e122b3cca84284c1 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"
@@ -57,7 +65,7 @@ RGBAColor SkColorToRGBAColor(const SkColor& sKColor) {
InstantService::InstantService(Profile* profile)
: profile_(profile),
- ntp_prerenderer_(profile, profile->GetPrefs()),
+ ntp_prerenderer_(profile, this, profile->GetPrefs()),
browser_instant_controller_object_count_(0),
weak_ptr_factory_(this) {
// Stub for unit tests.
@@ -90,15 +98,25 @@ 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, false));
- content::URLDataSource::Add(profile, new ThumbnailSource(profile, true));
- content::URLDataSource::Add(profile, new FaviconSource(
- profile, FaviconSource::FAVICON));
- content::URLDataSource::Add(profile, new LocalNtpSource(profile));
- content::URLDataSource::Add(profile, new MostVisitedIframeSource());
+
+ content::URLDataSource::Add(profile_, new ThumbnailSource(profile_, false));
+ content::URLDataSource::Add(profile_, new ThumbnailSource(profile_, true));
+ 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)));
+
+ registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_URL_UPDATED,
+ content::Source<Profile>(profile_->GetOriginalProfile()));
registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED,
content::Source<Profile>(profile_));
}
@@ -195,7 +213,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() {
@@ -255,6 +273,12 @@ void InstantService::Observe(int type,
ntp_prerenderer_.DeleteNTPContents();
break;
}
+ 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.";
}
@@ -391,6 +415,44 @@ 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() indicates very first run of Chrome. So there
+ // is no need to notify, as there won't be any old state.
+ if (last_prompted_url.is_empty())
+ return;
+
+ // Only the scheme changed. Ignore it since we do not prompt the user in this
+ // case.
+ 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_;
}
« no previous file with comments | « chrome/browser/search/instant_service.h ('k') | chrome/browser/search/instant_service_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698