| OLD | NEW |
| 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 #include "chrome/browser/lifetime/browser_close_manager.h" | 5 #include "chrome/browser/lifetime/browser_close_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <iterator> | 8 #include <iterator> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 browser->ResetTryToCloseWindow(); | 65 browser->ResetTryToCloseWindow(); |
| 66 } | 66 } |
| 67 | 67 |
| 68 void BrowserCloseManager::TryToCloseBrowsers() { | 68 void BrowserCloseManager::TryToCloseBrowsers() { |
| 69 // If all browser windows can immediately be closed, fall out of this loop and | 69 // If all browser windows can immediately be closed, fall out of this loop and |
| 70 // close the browsers. If any browser window cannot be closed, temporarily | 70 // close the browsers. If any browser window cannot be closed, temporarily |
| 71 // stop closing. CallBeforeUnloadHandlers prompts the user and calls | 71 // stop closing. CallBeforeUnloadHandlers prompts the user and calls |
| 72 // OnBrowserReportCloseable with the result. If the user confirms the close, | 72 // OnBrowserReportCloseable with the result. If the user confirms the close, |
| 73 // this will trigger TryToCloseBrowsers to try again. | 73 // this will trigger TryToCloseBrowsers to try again. |
| 74 for (auto* browser : *BrowserList::GetInstance()) { | 74 for (auto* browser : *BrowserList::GetInstance()) { |
| 75 // Set current_browser_ here since if there are no unload handlers, it might |
| 76 // get used synchronously inside TryToCloseWindow. |
| 77 current_browser_ = browser; |
| 75 if (browser->TryToCloseWindow( | 78 if (browser->TryToCloseWindow( |
| 76 false, | 79 false, |
| 77 base::Bind(&BrowserCloseManager::OnBrowserReportCloseable, this))) { | 80 base::Bind(&BrowserCloseManager::OnBrowserReportCloseable, this))) { |
| 78 current_browser_ = browser; | |
| 79 return; | 81 return; |
| 80 } | 82 } |
| 81 } | 83 } |
| 84 current_browser_ = NULL; |
| 82 CheckForDownloadsInProgress(); | 85 CheckForDownloadsInProgress(); |
| 83 } | 86 } |
| 84 | 87 |
| 85 void BrowserCloseManager::OnBrowserReportCloseable(bool proceed) { | 88 void BrowserCloseManager::OnBrowserReportCloseable(bool proceed) { |
| 86 if (!current_browser_) | 89 if (!current_browser_) |
| 87 return; | 90 return; |
| 88 | 91 |
| 89 current_browser_ = NULL; | 92 current_browser_ = NULL; |
| 90 | 93 |
| 91 if (proceed) | 94 if (proceed) |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 browser->window()->DestroyBrowser(); | 183 browser->window()->DestroyBrowser(); |
| 181 // Destroying the browser should have removed it from the browser list. | 184 // Destroying the browser should have removed it from the browser list. |
| 182 DCHECK(BrowserList::GetInstance()->end() == | 185 DCHECK(BrowserList::GetInstance()->end() == |
| 183 std::find(BrowserList::GetInstance()->begin(), | 186 std::find(BrowserList::GetInstance()->begin(), |
| 184 BrowserList::GetInstance()->end(), browser)); | 187 BrowserList::GetInstance()->end(), browser)); |
| 185 } | 188 } |
| 186 } | 189 } |
| 187 | 190 |
| 188 g_browser_process->notification_ui_manager()->CancelAll(); | 191 g_browser_process->notification_ui_manager()->CancelAll(); |
| 189 } | 192 } |
| OLD | NEW |