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

Unified Diff: chrome/browser/ui/unload_controller.cc

Issue 11016023: Quickly close tabs/window with long-running unload handlers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add tests. Drop test's use of non-public API. Created 8 years, 2 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: chrome/browser/ui/unload_controller.cc
diff --git a/chrome/browser/ui/unload_controller.cc b/chrome/browser/ui/unload_controller.cc
index bc8c1805360beb6682c6f656a5baf12f41a4aa42..316feebe022bbdaab01babadb76b4399e5962086 100644
--- a/chrome/browser/ui/unload_controller.cc
+++ b/chrome/browser/ui/unload_controller.cc
@@ -4,11 +4,13 @@
#include "chrome/browser/ui/unload_controller.h"
+#include "base/callback.h"
#include "base/message_loop.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/tab_contents/tab_contents.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
+#include "chrome/browser/ui/unload_detached_handler.h"
#include "chrome/common/chrome_notification_types.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_source.h"
@@ -24,12 +26,16 @@ namespace chrome {
UnloadController::UnloadController(Browser* browser)
: browser_(browser),
is_attempting_to_close_browser_(false),
+ unload_detached_handler_(new UnloadDetachedHandler(
+ base::Bind(&UnloadController::DetachedTabsClosedCallback,
+ base::Unretained(this)))),
ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
browser_->tab_strip_model()->AddObserver(this);
}
UnloadController::~UnloadController() {
browser_->tab_strip_model()->RemoveObserver(this);
+ delete unload_detached_handler_;
}
bool UnloadController::CanCloseContents(content::WebContents* contents) {
@@ -43,8 +49,14 @@ bool UnloadController::CanCloseContents(content::WebContents* contents) {
bool UnloadController::BeforeUnloadFired(content::WebContents* contents,
bool proceed) {
if (!is_attempting_to_close_browser_) {
- if (!proceed)
+ if (proceed) {
+ // No more dialogs are possible, so remove the tab and finish
+ // running unload listeners asynchrounously.
+ unload_detached_handler_->DetachWebContents(browser_->tab_strip_model(),
+ contents);
+ } else {
contents->SetClosedByUserGesture(false);
+ }
return proceed;
}
@@ -75,7 +87,7 @@ bool UnloadController::ShouldCloseWindow() {
is_attempting_to_close_browser_ = true;
if (!TabsNeedBeforeUnloadFired())
- return true;
+ return !unload_detached_handler_->HasTabs();
ProcessPendingTabs();
return false;
@@ -93,6 +105,10 @@ bool UnloadController::TabsNeedBeforeUnloadFired() {
return !tabs_needing_before_unload_fired_.empty();
}
+void UnloadController::DetachedTabsClosedCallback() {
+ ProcessPendingTabs();
+}
+
////////////////////////////////////////////////////////////////////////////////
// UnloadController, content::NotificationObserver implementation:
@@ -182,6 +198,7 @@ void UnloadController::ProcessPendingTabs() {
// Null check render_view_host here as this gets called on a PostTask and
// the tab's render_view_host may have been nulled out.
if (web_contents->GetRenderViewHost()) {
+ web_contents->OnCloseStarted();
web_contents->GetRenderViewHost()->FirePageBeforeUnload(false);
} else {
ClearUnloadState(web_contents, true);
@@ -199,7 +216,9 @@ void UnloadController::ProcessPendingTabs() {
// Null check render_view_host here as this gets called on a PostTask and
// the tab's render_view_host may have been nulled out.
if (web_contents->GetRenderViewHost()) {
- web_contents->GetRenderViewHost()->ClosePage();
+ if (!unload_detached_handler_->HasTabs()) {
+ web_contents->GetRenderViewHost()->ClosePage();
+ }
} else {
ClearUnloadState(web_contents, true);
}

Powered by Google App Engine
This is Rietveld 408576698