Chromium Code Reviews| 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 7b3957adc56cb3422ac9ec35c2140c24df4c4acd..756b438c9211b8f85595c86c6cf0f986307f8c60 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,22 @@ InstantNTPPrerenderer::~InstantNTPPrerenderer() { |
| net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this); |
| } |
| -void InstantNTPPrerenderer::PreloadInstantNTP() { |
| - DCHECK(!ntp()); |
| - ReloadStaleNTP(); |
| +void InstantNTPPrerenderer::Init() { |
| + InstantService* instant_service = |
| + InstantServiceFactory::GetForProfile(profile_); |
| + instant_service->AddObserver(this); |
| + ReloadInstantNTP(); |
| +} |
| + |
| +void InstantNTPPrerenderer::Destroy() { |
| + InstantService* instant_service = |
| + InstantServiceFactory::GetForProfile(profile_); |
| + instant_service->RemoveObserver(this); |
| + DeleteNTPContents(); |
| +} |
| + |
| +void InstantNTPPrerenderer::ReloadInstantNTP() { |
| + ResetNTP(GetInstantURL()); |
| } |
| scoped_ptr<content::WebContents> InstantNTPPrerenderer::ReleaseNTPContents() { |
| @@ -84,7 +93,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 +184,7 @@ void InstantNTPPrerenderer::OnNetworkChanged( |
| return; |
| if (!ntp() || ntp()->IsLocal()) |
| - ResetNTP(GetInstantURL()); |
| + ReloadInstantNTP(); |
| } |
| void InstantNTPPrerenderer::InstantSupportDetermined( |
| @@ -245,28 +254,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() || |
| @@ -298,3 +294,14 @@ bool InstantNTPPrerenderer::ShouldSwitchToLocalNTP() const { |
| // (unless the finch flag to use the remote NTP is set). |
| return !(InStartup() && chrome::ShouldPreferRemoteNTPOnStartup()); |
| } |
| + |
| +//////////////////////////////////////////////////////////////////////////////// |
|
samarth
2013/08/14 00:24:14
nit: this file isn't really big enough to merit th
Anuj
2013/08/14 06:38:57
Done.
|
| +// InstantNTPPrerenderer, InstantServiceObserver implementation: |
| + |
| +void InstantNTPPrerenderer::DefaultSearchProviderChanged() { |
| + ReloadInstantNTP(); |
| +} |
| + |
| +void InstantNTPPrerenderer::GoogleURLUpdated() { |
| + ReloadInstantNTP(); |
| +} |