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

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

Issue 11016023: Quickly close tabs/window with long-running unload handlers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add UnloadController class comment. 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
« no previous file with comments | « no previous file | chrome/browser/ui/unload_controller.cc » ('j') | chrome/browser/ui/unload_detached_handler.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/unload_controller.h
diff --git a/chrome/browser/ui/unload_controller.h b/chrome/browser/ui/unload_controller.h
index fb51668b0554bd67d563d351b8c5db5ee7081f75..c2784cc74060165bde5a09d286013becd9453a2f 100644
--- a/chrome/browser/ui/unload_controller.h
+++ b/chrome/browser/ui/unload_controller.h
@@ -23,7 +23,34 @@ class WebContents;
}
namespace chrome {
-
+class UnloadDetachedHandler;
+
+// UnloadController manages closing tabs and windows -- especially in
+// regards to beforeunload handlers (proceed/cancel dialogs) and
+// unload handlers (no user interaction).
+//
+// Typical flow of closing a tab:
+// 1. Browser calls |CanCloseContents()|.
+// If true, browser calls |contents::CloseWebContents()|.
Ben Goodger (Google) 2012/10/29 22:12:43 chrome::CloseWebContents()
slamm 2012/10/31 18:03:59 Done.
+// 2. Browser calls |BeforeUnloadFired()| for tabs with beforeunload or unload
Ben Goodger (Google) 2012/10/29 22:12:43 Technically, the WebContents calls BeforeUnloadFir
slamm 2012/10/31 18:03:59 Done. Your description is much better.
+// handlers. If |proceed| is true, |UnloadController| hands-off the tab to
+// |UnloadDetachedHandler| to run the unload handler in the background.
+// |UnloadDetachedHandler| decides if the tab can unload in the background,
+// and removes it from the tab strip if it can.
+//
+// Typical flow of closing a window:
+// 1. Browser calls |ShouldCloseWindow()|.
+// If beforeunload/unload handlers need to run, |UnloadController| returns
+// false and calls |ProcessPendingTabs()| (private method).
+// 2. For each tab with a beforeunload/unload handler, |ProcessPendingTabs()|
+// calls |web_contents->OnCloseStarted()|
+// and |web_contents->GetRenderViewHost()->FirePageBeforeUnload()|.
+// 3. |UnloadController| waits for any tabs from the "closing a tab" flow above
+// to finish detached unloads.
+// 4. For each tab with a beforeunload/unload handler, |ProcessPendingTabs()|
+// calls |web_contents->GetRenderViewHost()->ClosePage()|.
+// 5. |ProcessPendingTabs()| calls |browser_->OnWindowClosing()|.
+//
class UnloadController : public content::NotificationObserver,
public TabStripModelObserver {
public:
@@ -114,11 +141,11 @@ class UnloadController : public content::NotificationObserver,
content::NotificationRegistrar registrar_;
- // Tracks tabs that need there beforeunload event fired before we can
+ // Tracks tabs that need their beforeunload event fired before we can
// close the browser. Only gets populated when we try to close the browser.
UnloadListenerSet tabs_needing_before_unload_fired_;
- // Tracks tabs that need there unload event fired before we can
+ // Tracks tabs that need their unload event fired before we can
// close the browser. Only gets populated when we try to close the browser.
UnloadListenerSet tabs_needing_unload_fired_;
@@ -128,6 +155,9 @@ class UnloadController : public content::NotificationObserver,
// Browser window isn't just immediately closed.
bool is_attempting_to_close_browser_;
+ // Allow unload handlers to run without holding up the UI.
+ UnloadDetachedHandler* const unload_detached_handler_;
Ben Goodger (Google) 2012/10/29 22:12:43 We don't tend to use this type of const in chrome
slamm 2012/10/31 18:03:59 Changed to scoped_ptr.
+
base::WeakPtrFactory<UnloadController> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(UnloadController);
« no previous file with comments | « no previous file | chrome/browser/ui/unload_controller.cc » ('j') | chrome/browser/ui/unload_detached_handler.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698