Index: trunk/src/chrome/browser/search/instant_service.cc |
=================================================================== |
--- trunk/src/chrome/browser/search/instant_service.cc (revision 244428) |
+++ trunk/src/chrome/browser/search/instant_service.cc (working copy) |
@@ -67,6 +67,8 @@ |
InstantService::InstantService(Profile* profile) |
: profile_(profile), |
+ ntp_prerenderer_(profile, this, profile->GetPrefs()), |
+ browser_instant_controller_object_count_(0), |
weak_ptr_factory_(this) { |
// Stub for unit tests. |
if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) |
@@ -122,6 +124,8 @@ |
registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_URL_UPDATED, |
content::Source<Profile>(profile_->GetOriginalProfile())); |
+ registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
+ content::Source<Profile>(profile_)); |
} |
InstantService::~InstantService() { |
@@ -201,6 +205,37 @@ |
instant_io_context_ = NULL; |
} |
+scoped_ptr<content::WebContents> InstantService::ReleaseNTPContents() { |
+ return ntp_prerenderer_.ReleaseNTPContents(); |
+} |
+ |
+content::WebContents* InstantService::GetNTPContents() const { |
+ return ntp_prerenderer_.GetNTPContents(); |
+} |
+ |
+void InstantService::OnBrowserInstantControllerCreated() { |
+ if (profile_->IsOffTheRecord()) |
+ return; |
+ |
+ ++browser_instant_controller_object_count_; |
+ |
+ if (browser_instant_controller_object_count_ == 1) |
+ ntp_prerenderer_.ReloadInstantNTP(); |
+} |
+ |
+void InstantService::OnBrowserInstantControllerDestroyed() { |
+ if (profile_->IsOffTheRecord()) |
+ return; |
+ |
+ DCHECK_GT(browser_instant_controller_object_count_, 0U); |
+ --browser_instant_controller_object_count_; |
+ |
+ // All browser windows have closed, so release the InstantNTP resources to |
+ // work around http://crbug.com/180810. |
+ if (browser_instant_controller_object_count_ == 0) |
+ ntp_prerenderer_.DeleteNTPContents(); |
+} |
+ |
void InstantService::Observe(int type, |
const content::NotificationSource& source, |
const content::NotificationDetails& details) { |
@@ -228,6 +263,16 @@ |
break; |
} |
#endif // defined(ENABLE_THEMES) |
+ case chrome::NOTIFICATION_PROFILE_DESTROYED: { |
+ // Last chance to delete InstantNTP contents. We generally delete |
+ // preloaded InstantNTP when the last BrowserInstantController object is |
+ // destroyed. When the browser shutdown happens without closing browsers, |
+ // there is a race condition between BrowserInstantController destruction |
+ // and Profile destruction. |
+ if (GetNTPContents()) |
+ ntp_prerenderer_.DeleteNTPContents(); |
+ break; |
+ } |
case chrome::NOTIFICATION_GOOGLE_URL_UPDATED: { |
OnGoogleURLUpdated( |
content::Source<Profile>(source).ptr(), |
@@ -431,6 +476,10 @@ |
InstantServiceObserver, observers_, DefaultSearchProviderChanged()); |
} |
+InstantNTPPrerenderer* InstantService::ntp_prerenderer() { |
+ return &ntp_prerenderer_; |
+} |
+ |
void InstantService::ResetInstantSearchPrerenderer() { |
if (!chrome::ShouldPrefetchSearchResults()) |
return; |