Chromium Code Reviews| Index: chrome/browser/search/instant_service.cc |
| diff --git a/chrome/browser/search/instant_service.cc b/chrome/browser/search/instant_service.cc |
| index 014cbf806e7c13437bcaf7d9be0559b7a8385a91..1f54948ae10e34eba408a6adde0f27fd464538f2 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" |
| @@ -18,18 +19,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" |
| @@ -89,14 +97,24 @@ 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()); |
| + 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))); |
| + |
| + registrar_.Add(this, |
|
samarth
2013/07/26 23:33:15
Move this up next to the other notification regist
Anuj
2013/07/31 07:16:18
Done.
|
| + chrome::NOTIFICATION_GOOGLE_URL_UPDATED, |
| + content::Source<Profile>(profile_->GetOriginalProfile())); |
| } |
| InstantService::~InstantService() { |
| @@ -191,7 +209,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() { |
| @@ -241,6 +259,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."; |
| } |
| @@ -382,6 +406,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 indicated very first run of Chrome. So there is |
| + // no need to temper with instant resources. |
|
samarth
2013/07/26 23:33:15
s/temper/tamper/
s/instant/Instant/
Anuj
2013/07/31 07:16:18
Done.
|
| + if (last_prompted_url.is_empty()) |
| + return; |
| + |
| + // Google URL change is just the scheme change (http <-> https). |
|
samarth
2013/07/26 23:33:15
This matters. Instant Extended should only happen
Anuj
2013/07/31 07:16:18
As discussed and commented above, this imitates th
|
| + 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_; |
| } |