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

Side by Side Diff: chrome/browser/ui/fast_unload_controller.h

Issue 2681203002: Add Browser::SkipCallBeforeUnload so that the browser windows can be closed regardless of beforeunl… (Closed)
Patch Set: rebase from master Created 3 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_FAST_UNLOAD_CONTROLLER_H_ 5 #ifndef CHROME_BROWSER_UI_FAST_UNLOAD_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_FAST_UNLOAD_CONTROLLER_H_ 6 #define CHROME_BROWSER_UI_FAST_UNLOAD_CONTROLLER_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <set> 9 #include <set>
10 10
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "base/strings/string_piece.h" 14 #include "base/strings/string_piece.h"
15 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" 15 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
16 #include "content/public/browser/notification_observer.h" 16 #include "content/public/browser/notification_observer.h"
17 #include "content/public/browser/notification_registrar.h" 17 #include "content/public/browser/notification_registrar.h"
18 18
19 class Browser; 19 class Browser;
20 class TabStripModel; 20 class TabStripModel;
21 class UnloadControllerWebContentsDelegate;
21 22
22 namespace content { 23 namespace content {
23 class NotificationSource; 24 class NotificationSource;
24 class NotificationDetails; 25 class NotificationDetails;
25 class WebContents; 26 class WebContents;
26 } 27 }
27 28
28 namespace chrome { 29 namespace chrome {
29 // FastUnloadController manages closing tabs and windows -- especially in 30 // FastUnloadController manages closing tabs and windows -- especially in
30 // regards to beforeunload handlers (have proceed/cancel dialogs) and 31 // regards to beforeunload handlers (have proceed/cancel dialogs) and
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 84
84 bool is_attempting_to_close_browser() const { 85 bool is_attempting_to_close_browser() const {
85 return is_attempting_to_close_browser_; 86 return is_attempting_to_close_browser_;
86 } 87 }
87 88
88 // Called in response to a request to close |browser_|'s window. Returns true 89 // Called in response to a request to close |browser_|'s window. Returns true
89 // when there are no remaining beforeunload handlers to be run. 90 // when there are no remaining beforeunload handlers to be run.
90 bool ShouldCloseWindow(); 91 bool ShouldCloseWindow();
91 92
92 // Begins the process of confirming whether the associated browser can be 93 // Begins the process of confirming whether the associated browser can be
93 // closed. 94 // closed. Beforeunload events won't be fired if |skip_beforeunload|
94 bool CallBeforeUnloadHandlers( 95 // true.
95 const base::Callback<void(bool)>& on_close_confirmed); 96 bool TryToCloseWindow(bool skip_beforeunload,
97 const base::Callback<void(bool)>& on_close_confirmed);
96 98
97 // Clears the results of any beforeunload confirmation dialogs triggered by a 99 // Clears the results of any beforeunload confirmation dialogs triggered by a
98 // CallBeforeUnloadHandlers call. 100 // TryToCloseWindow call.
99 void ResetBeforeUnloadHandlers(); 101 void ResetTryToCloseWindow();
100 102
101 // Returns true if |browser_| has any tabs that have BeforeUnload handlers 103 // Returns true if |browser_| has any tabs that have BeforeUnload handlers
102 // that have not been fired. This method is non-const because it builds a list 104 // that have not been fired. This method is non-const because it builds a list
103 // of tabs that need their BeforeUnloadHandlers fired. 105 // of tabs that need their BeforeUnloadHandlers fired.
104 // TODO(beng): This seems like it could be private but it is used by 106 // TODO(beng): This seems like it could be private but it is used by
105 // AreAllBrowsersCloseable() in application_lifetime.cc. It seems 107 // AreAllBrowsersCloseable() in application_lifetime.cc. It seems
106 // very similar to ShouldCloseWindow() and some consolidation 108 // very similar to ShouldCloseWindow() and some consolidation
107 // could be pursued. 109 // could be pursued.
108 bool TabsNeedBeforeUnloadFired(); 110 bool TabsNeedBeforeUnloadFired();
109 111
(...skipping 23 matching lines...) Expand all
133 void TabStripEmpty() override; 135 void TabStripEmpty() override;
134 136
135 void TabAttachedImpl(content::WebContents* contents); 137 void TabAttachedImpl(content::WebContents* contents);
136 void TabDetachedImpl(content::WebContents* contents); 138 void TabDetachedImpl(content::WebContents* contents);
137 139
138 // Detach |contents| and wait for it to finish closing. 140 // Detach |contents| and wait for it to finish closing.
139 // The close must be inititiated outside of this method. 141 // The close must be inititiated outside of this method.
140 // Returns true if it succeeds. 142 // Returns true if it succeeds.
141 bool DetachWebContents(content::WebContents* contents); 143 bool DetachWebContents(content::WebContents* contents);
142 144
143 // Processes the next tab that needs it's beforeunload/unload event fired. 145 // Processes the next tab that needs its beforeunload/unload event fired.
144 void ProcessPendingTabs(); 146 void ProcessPendingTabs(bool skip_beforeunload);
145 147
146 // Cleans up state appropriately when we are trying to close the 148 // Cleans up state appropriately when we are trying to close the
147 // browser or close a tab in the background. We also use this in the 149 // browser or close a tab in the background. We also use this in the
148 // cases where a tab crashes or hangs even if the 150 // cases where a tab crashes or hangs even if the
149 // beforeunload/unload haven't successfully fired. 151 // beforeunload/unload haven't successfully fired.
150 void ClearUnloadState(content::WebContents* contents); 152 void ClearUnloadState(content::WebContents* contents);
151 153
152 // Helper for |ClearUnloadState| to unwind stack before proceeding. 154 // Helper for |ClearUnloadState| to unwind stack before proceeding.
153 void PostTaskForProcessPendingTabs(); 155 void PostTaskForProcessPendingTabs();
154 156
155 // Log a step of the unload processing. 157 // Log a step of the unload processing.
156 void LogUnloadStep(const base::StringPiece& step_name, 158 void LogUnloadStep(const base::StringPiece& step_name,
157 content::WebContents* contents) const; 159 content::WebContents* contents) const;
158 160
161 void CancelTabNeedingBeforeUnloadAck();
162
159 bool is_calling_before_unload_handlers() { 163 bool is_calling_before_unload_handlers() {
160 return !on_close_confirmed_.is_null(); 164 return !on_close_confirmed_.is_null();
161 } 165 }
162 166
163 Browser* browser_; 167 Browser* browser_;
164 168
165 content::NotificationRegistrar registrar_; 169 content::NotificationRegistrar registrar_;
166 170
167 typedef std::set<content::WebContents*> WebContentsSet; 171 typedef std::set<content::WebContents*> WebContentsSet;
168 172
(...skipping 18 matching lines...) Expand all
187 // state rather than Browser because unload handlers are the only reason that 191 // state rather than Browser because unload handlers are the only reason that
188 // a Browser window isn't just immediately closed. 192 // a Browser window isn't just immediately closed.
189 bool is_attempting_to_close_browser_; 193 bool is_attempting_to_close_browser_;
190 194
191 // A callback to call to report whether the user chose to close all tabs of 195 // A callback to call to report whether the user chose to close all tabs of
192 // |browser_| that have beforeunload event handlers. This is set only if we 196 // |browser_| that have beforeunload event handlers. This is set only if we
193 // are currently confirming that the browser is closable. 197 // are currently confirming that the browser is closable.
194 base::Callback<void(bool)> on_close_confirmed_; 198 base::Callback<void(bool)> on_close_confirmed_;
195 199
196 // Manage tabs with beforeunload/unload handlers that close detached. 200 // Manage tabs with beforeunload/unload handlers that close detached.
197 class DetachedWebContentsDelegate; 201 std::unique_ptr<UnloadControllerWebContentsDelegate> detached_delegate_;
198 std::unique_ptr<DetachedWebContentsDelegate> detached_delegate_;
199 202
200 base::WeakPtrFactory<FastUnloadController> weak_factory_; 203 base::WeakPtrFactory<FastUnloadController> weak_factory_;
201 204
202 DISALLOW_COPY_AND_ASSIGN(FastUnloadController); 205 DISALLOW_COPY_AND_ASSIGN(FastUnloadController);
203 }; 206 };
204 207
205 } // namespace chrome 208 } // namespace chrome
206 209
207 #endif // CHROME_BROWSER_UI_FAST_UNLOAD_CONTROLLER_H_ 210 #endif // CHROME_BROWSER_UI_FAST_UNLOAD_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698