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

Side by Side 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, 1 month 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_UI_UNLOAD_CONTROLLER_H_ 5 #ifndef CHROME_BROWSER_UI_UNLOAD_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_UNLOAD_CONTROLLER_H_ 6 #define CHROME_BROWSER_UI_UNLOAD_CONTROLLER_H_
7 7
8 #include <set> 8 #include <set>
9 9
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
11 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" 11 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
12 #include "content/public/browser/notification_observer.h" 12 #include "content/public/browser/notification_observer.h"
13 #include "content/public/browser/notification_registrar.h" 13 #include "content/public/browser/notification_registrar.h"
14 14
15 class Browser; 15 class Browser;
16 class TabContents; 16 class TabContents;
17 class TabStripModel; 17 class TabStripModel;
18 18
19 namespace content { 19 namespace content {
20 class NotificationSource; 20 class NotificationSource;
21 class NotifictaionDetails; 21 class NotifictaionDetails;
22 class WebContents; 22 class WebContents;
23 } 23 }
24 24
25 namespace chrome { 25 namespace chrome {
26 class UnloadDetachedHandler;
26 27
28 // UnloadController manages closing tabs and windows -- especially in
29 // regards to beforeunload handlers (proceed/cancel dialogs) and
30 // unload handlers (no user interaction).
31 //
32 // Typical flow of closing a tab:
33 // 1. Browser calls |CanCloseContents()|.
34 // 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.
35 // 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.
36 // handlers. If |proceed| is true, |UnloadController| hands-off the tab to
37 // |UnloadDetachedHandler| to run the unload handler in the background.
38 // |UnloadDetachedHandler| decides if the tab can unload in the background,
39 // and removes it from the tab strip if it can.
40 //
41 // Typical flow of closing a window:
42 // 1. Browser calls |ShouldCloseWindow()|.
43 // If beforeunload/unload handlers need to run, |UnloadController| returns
44 // false and calls |ProcessPendingTabs()| (private method).
45 // 2. For each tab with a beforeunload/unload handler, |ProcessPendingTabs()|
46 // calls |web_contents->OnCloseStarted()|
47 // and |web_contents->GetRenderViewHost()->FirePageBeforeUnload()|.
48 // 3. |UnloadController| waits for any tabs from the "closing a tab" flow above
49 // to finish detached unloads.
50 // 4. For each tab with a beforeunload/unload handler, |ProcessPendingTabs()|
51 // calls |web_contents->GetRenderViewHost()->ClosePage()|.
52 // 5. |ProcessPendingTabs()| calls |browser_->OnWindowClosing()|.
53 //
27 class UnloadController : public content::NotificationObserver, 54 class UnloadController : public content::NotificationObserver,
28 public TabStripModelObserver { 55 public TabStripModelObserver {
29 public: 56 public:
30 explicit UnloadController(Browser* browser); 57 explicit UnloadController(Browser* browser);
31 virtual ~UnloadController(); 58 virtual ~UnloadController();
32 59
33 // Returns true if |contents| can be cleanly closed. When |browser_| is being 60 // Returns true if |contents| can be cleanly closed. When |browser_| is being
34 // closed, this function will return false to indicate |contents| should not 61 // closed, this function will return false to indicate |contents| should not
35 // be cleanly closed, since the fast shutdown path will just kill its 62 // be cleanly closed, since the fast shutdown path will just kill its
36 // renderer. 63 // renderer.
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 // 134 //
108 // Typically you'll want to pass in true for |process_now|. Passing in true 135 // Typically you'll want to pass in true for |process_now|. Passing in true
109 // may result in deleting |tab|. If you know that shouldn't happen (because of 136 // may result in deleting |tab|. If you know that shouldn't happen (because of
110 // the state of the stack), pass in false. 137 // the state of the stack), pass in false.
111 void ClearUnloadState(content::WebContents* web_contents, bool process_now); 138 void ClearUnloadState(content::WebContents* web_contents, bool process_now);
112 139
113 Browser* browser_; 140 Browser* browser_;
114 141
115 content::NotificationRegistrar registrar_; 142 content::NotificationRegistrar registrar_;
116 143
117 // Tracks tabs that need there beforeunload event fired before we can 144 // Tracks tabs that need their beforeunload event fired before we can
118 // close the browser. Only gets populated when we try to close the browser. 145 // close the browser. Only gets populated when we try to close the browser.
119 UnloadListenerSet tabs_needing_before_unload_fired_; 146 UnloadListenerSet tabs_needing_before_unload_fired_;
120 147
121 // Tracks tabs that need there unload event fired before we can 148 // Tracks tabs that need their unload event fired before we can
122 // close the browser. Only gets populated when we try to close the browser. 149 // close the browser. Only gets populated when we try to close the browser.
123 UnloadListenerSet tabs_needing_unload_fired_; 150 UnloadListenerSet tabs_needing_unload_fired_;
124 151
125 // Whether we are processing the beforeunload and unload events of each tab 152 // Whether we are processing the beforeunload and unload events of each tab
126 // in preparation for closing the browser. UnloadController owns this state 153 // in preparation for closing the browser. UnloadController owns this state
127 // rather than Browser because unload handlers are the only reason that a 154 // rather than Browser because unload handlers are the only reason that a
128 // Browser window isn't just immediately closed. 155 // Browser window isn't just immediately closed.
129 bool is_attempting_to_close_browser_; 156 bool is_attempting_to_close_browser_;
130 157
158 // Allow unload handlers to run without holding up the UI.
159 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.
160
131 base::WeakPtrFactory<UnloadController> weak_factory_; 161 base::WeakPtrFactory<UnloadController> weak_factory_;
132 162
133 DISALLOW_COPY_AND_ASSIGN(UnloadController); 163 DISALLOW_COPY_AND_ASSIGN(UnloadController);
134 }; 164 };
135 165
136 } // namespace chrome 166 } // namespace chrome
137 167
138 #endif // CHROME_BROWSER_UI_UNLOAD_CONTROLLER_H_ 168 #endif // CHROME_BROWSER_UI_UNLOAD_CONTROLLER_H_
OLDNEW
« 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