Chromium Code Reviews| Index: chrome/browser/ui/unload_controller.cc |
| diff --git a/chrome/browser/ui/unload_controller.cc b/chrome/browser/ui/unload_controller.cc |
| index 8da59883131c958fbd7a16fe9daa400225b43eb7..7a30244ff82a5b5d2a596bc747714e12bc18e913 100644 |
| --- a/chrome/browser/ui/unload_controller.cc |
| +++ b/chrome/browser/ui/unload_controller.cc |
| @@ -291,6 +291,9 @@ void UnloadController::TabDetachedImpl(content::WebContents* contents) { |
| } |
| void UnloadController::ProcessPendingTabs() { |
| + // Cancel posted/queued ProcessPendingTabs task if there is any. |
| + weak_factory_.InvalidateWeakPtrs(); |
| + |
| if (!is_attempting_to_close_browser_) { |
| // Because we might invoke this after a delay it's possible for the value of |
| // is_attempting_to_close_browser_ to have changed since we scheduled the |
| @@ -298,7 +301,7 @@ void UnloadController::ProcessPendingTabs() { |
| return; |
| } |
| - if (HasCompletedUnloadProcessing()) { |
| + if (HasCompletedUnloadProcessing() && !TabsNeedBeforeUnloadFired()) { |
|
sky
2017/02/16 17:16:53
How come we don't always call TabsNeedBeforeUnload
Michael K. (Yandex Team)
2017/02/17 09:43:04
We do. We always call it.
But since we called it a
|
| // We've finished all the unload events and can proceed to close the |
| // browser. |
| browser_->OnWindowClosing(); |
| @@ -379,6 +382,9 @@ void UnloadController::ClearUnloadState(content::WebContents* web_contents, |
| if (process_now) { |
| ProcessPendingTabs(); |
| } else { |
| + // Do not post a new task if there is already any. |
| + if (weak_factory_.HasWeakPtrs()) |
| + return; |
| base::ThreadTaskRunnerHandle::Get()->PostTask( |
| FROM_HERE, base::Bind(&UnloadController::ProcessPendingTabs, |
| weak_factory_.GetWeakPtr())); |