summaryrefslogtreecommitdiffstats
path: root/chrome/browser/prerender
diff options
context:
space:
mode:
authordominich@chromium.org <dominich@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-15 19:22:57 +0000
committerdominich@chromium.org <dominich@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-15 19:22:57 +0000
commitcd9ed79d37636c40bde1f2f7fdb93aadd9542ec1 (patch)
tree4c8ce6c0017caaaa014f5edef463f1a60d8d6532 /chrome/browser/prerender
parent033e0ac1862d984563f313992fb9b9de08b030df (diff)
downloadchromium_src-cd9ed79d37636c40bde1f2f7fdb93aadd9542ec1.zip
chromium_src-cd9ed79d37636c40bde1f2f7fdb93aadd9542ec1.tar.gz
chromium_src-cd9ed79d37636c40bde1f2f7fdb93aadd9542ec1.tar.bz2
Add SwappedOut to TabContentsDelegate to allow us to correctly delete TabContents.
When a page has an unload handler and we swap it out to make way for a Prerendered tab, we expect a call to the TabContentsDelegate when it closes. For cross-site navigations, we don't get that message as the RenderViewHost is swapped instead of closing. BUG=103966 TEST=Enable prerender from omnibox (and ensure it's not disabled by field trial) and repeatedly navigate between cnn.com and telegraph.co.uk in the Omnibox. Note in the TaskManager that you do not see zombie Tab processes. Review URL: http://codereview.chromium.org/8539027 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110145 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/prerender')
-rw-r--r--chrome/browser/prerender/prerender_manager.cc27
1 files changed, 24 insertions, 3 deletions
diff --git a/chrome/browser/prerender/prerender_manager.cc b/chrome/browser/prerender/prerender_manager.cc
index a9e8777..0601d03 100644
--- a/chrome/browser/prerender/prerender_manager.cc
+++ b/chrome/browser/prerender/prerender_manager.cc
@@ -9,6 +9,8 @@
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/logging.h"
+#include "base/memory/weak_ptr.h"
+#include "base/metrics/histogram.h"
#include "base/stl_util.h"
#include "base/time.h"
#include "base/utf_string_conversions.h"
@@ -97,18 +99,29 @@ bool NeedMatchCompleteDummyForFinalStatus(FinalStatus final_status) {
} // namespace
-class PrerenderManager::OnCloseTabContentsDeleter : public TabContentsDelegate {
+class PrerenderManager::OnCloseTabContentsDeleter
+ : public TabContentsDelegate,
+ public base::SupportsWeakPtr<
+ PrerenderManager::OnCloseTabContentsDeleter> {
public:
OnCloseTabContentsDeleter(PrerenderManager* manager,
TabContentsWrapper* tab)
: manager_(manager),
tab_(tab) {
tab_->tab_contents()->set_delegate(this);
+ MessageLoop::current()->PostDelayedTask(FROM_HERE,
+ base::Bind(&OnCloseTabContentsDeleter::ScheduleTabContentsForDeletion,
+ this->AsWeakPtr(), true), kDeleteWithExtremePrejudiceTimeMs);
}
virtual void CloseContents(TabContents* source) OVERRIDE {
- tab_->tab_contents()->set_delegate(NULL);
- manager_->ScheduleDeleteOldTabContents(tab_.release(), this);
+ DCHECK_EQ(tab_->tab_contents(), source);
+ ScheduleTabContentsForDeletion(false);
+ }
+
+ virtual void SwappedOut(TabContents* source) OVERRIDE {
+ DCHECK_EQ(tab_->tab_contents(), source);
+ ScheduleTabContentsForDeletion(false);
}
virtual bool ShouldSuppressDialogs() OVERRIDE {
@@ -116,6 +129,14 @@ class PrerenderManager::OnCloseTabContentsDeleter : public TabContentsDelegate {
}
private:
+ static const int kDeleteWithExtremePrejudiceTimeMs = 3000;
+
+ void ScheduleTabContentsForDeletion(bool timeout) {
+ tab_->tab_contents()->set_delegate(NULL);
+ manager_->ScheduleDeleteOldTabContents(tab_.release(), this);
+ UMA_HISTOGRAM_BOOLEAN("Prerender.TabContentsDeleterTimeout", timeout);
+ }
+
PrerenderManager* manager_;
scoped_ptr<TabContentsWrapper> tab_;