| Index: chrome/browser/search/instant_service.cc
|
| diff --git a/chrome/browser/search/instant_service.cc b/chrome/browser/search/instant_service.cc
|
| index 196c8a3b1afb2eecc94912efb0b58c16bf6653ef..f03ffa481644a3455d495d0aa7d93c3931d2c9cd 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,16 +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()));
|
| +
|
| registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED,
|
| content::Source<Profile>(profile_));
|
| +
|
| + 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)));
|
| }
|
|
|
| InstantService::~InstantService() {
|
| @@ -194,7 +212,7 @@ void InstantService::OnBrowserInstantControllerCreated() {
|
| ++browser_instant_controller_object_count_;
|
|
|
| if (browser_instant_controller_object_count_ == 1)
|
| - ntp_prerenderer_.PreloadInstantNTP();
|
| + ntp_prerenderer_.Init();
|
| }
|
|
|
| void InstantService::OnBrowserInstantControllerDestroyed() {
|
| @@ -254,6 +272,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.";
|
| }
|
| @@ -395,6 +419,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 tamper with Instant resources.
|
| + 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_;
|
| }
|
|
|