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

Unified Diff: trunk/src/chrome/browser/search/instant_service.cc

Issue 135903002: Revert 244407 "InstantExtended: remove dead code related to the ..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 11 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
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;
« no previous file with comments | « trunk/src/chrome/browser/search/instant_service.h ('k') | trunk/src/chrome/browser/search/instant_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698