OLD | NEW |
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 #include "chrome/browser/ui/unload_controller.h" | 5 #include "chrome/browser/ui/unload_controller.h" |
6 | 6 |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
9 #include "chrome/browser/devtools/devtools_window.h" | 9 #include "chrome/browser/devtools/devtools_window.h" |
10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 // If there's a devtools window attached to |web_contents|, | 293 // If there's a devtools window attached to |web_contents|, |
294 // we would like devtools to call its own beforeunload handlers first, | 294 // we would like devtools to call its own beforeunload handlers first, |
295 // and then call beforeunload handlers for |web_contents|. | 295 // and then call beforeunload handlers for |web_contents|. |
296 // See DevToolsWindow::InterceptPageBeforeUnload for details. | 296 // See DevToolsWindow::InterceptPageBeforeUnload for details. |
297 if (!DevToolsWindow::InterceptPageBeforeUnload(web_contents)) | 297 if (!DevToolsWindow::InterceptPageBeforeUnload(web_contents)) |
298 web_contents->DispatchBeforeUnload(false); | 298 web_contents->DispatchBeforeUnload(false); |
299 } else { | 299 } else { |
300 ClearUnloadState(web_contents, true); | 300 ClearUnloadState(web_contents, true); |
301 } | 301 } |
302 } else if (is_calling_before_unload_handlers()) { | 302 } else if (is_calling_before_unload_handlers()) { |
303 on_close_confirmed_.Run(true); | 303 base::Callback<void(bool)> on_close_confirmed = on_close_confirmed_; |
| 304 // Reset |on_close_confirmed_| in case the callback tests |
| 305 // |is_calling_before_unload_handlers()|, we want to return that calling |
| 306 // is complete. |
| 307 if (tabs_needing_unload_fired_.empty()) |
| 308 on_close_confirmed_.Reset(); |
| 309 on_close_confirmed.Run(true); |
304 } else if (!tabs_needing_unload_fired_.empty()) { | 310 } else if (!tabs_needing_unload_fired_.empty()) { |
305 // We've finished firing all beforeunload events and can proceed with unload | 311 // We've finished firing all beforeunload events and can proceed with unload |
306 // events. | 312 // events. |
307 // TODO(ojan): We should add a call to browser_shutdown::OnShutdownStarting | 313 // TODO(ojan): We should add a call to browser_shutdown::OnShutdownStarting |
308 // somewhere around here so that we have accurate measurements of shutdown | 314 // somewhere around here so that we have accurate measurements of shutdown |
309 // time. | 315 // time. |
310 // TODO(ojan): We can probably fire all the unload events in parallel and | 316 // TODO(ojan): We can probably fire all the unload events in parallel and |
311 // get a perf benefit from that in the cases where the tab hangs in it's | 317 // get a perf benefit from that in the cases where the tab hangs in it's |
312 // unload handler or takes a long time to page in. | 318 // unload handler or takes a long time to page in. |
313 content::WebContents* web_contents = *(tabs_needing_unload_fired_.begin()); | 319 content::WebContents* web_contents = *(tabs_needing_unload_fired_.begin()); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 } else { | 358 } else { |
353 base::MessageLoop::current()->PostTask( | 359 base::MessageLoop::current()->PostTask( |
354 FROM_HERE, | 360 FROM_HERE, |
355 base::Bind(&UnloadController::ProcessPendingTabs, | 361 base::Bind(&UnloadController::ProcessPendingTabs, |
356 weak_factory_.GetWeakPtr())); | 362 weak_factory_.GetWeakPtr())); |
357 } | 363 } |
358 } | 364 } |
359 } | 365 } |
360 | 366 |
361 } // namespace chrome | 367 } // namespace chrome |
OLD | NEW |