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; | |
78 if (browser->TryToCloseWindow( | 75 if (browser->TryToCloseWindow( |
79 false, | 76 false, |
80 base::Bind(&BrowserCloseManager::OnBrowserReportCloseable, this))) { | 77 base::Bind(&BrowserCloseManager::OnBrowserReportCloseable, this))) { |
| 78 current_browser_ = browser; |
81 return; | 79 return; |
82 } | 80 } |
83 } | 81 } |
84 current_browser_ = NULL; | |
85 CheckForDownloadsInProgress(); | 82 CheckForDownloadsInProgress(); |
86 } | 83 } |
87 | 84 |
88 void BrowserCloseManager::OnBrowserReportCloseable(bool proceed) { | 85 void BrowserCloseManager::OnBrowserReportCloseable(bool proceed) { |
89 if (!current_browser_) | 86 if (!current_browser_) |
90 return; | 87 return; |
91 | 88 |
92 current_browser_ = NULL; | 89 current_browser_ = NULL; |
93 | 90 |
94 if (proceed) | 91 if (proceed) |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 browser->window()->DestroyBrowser(); | 180 browser->window()->DestroyBrowser(); |
184 // Destroying the browser should have removed it from the browser list. | 181 // Destroying the browser should have removed it from the browser list. |
185 DCHECK(BrowserList::GetInstance()->end() == | 182 DCHECK(BrowserList::GetInstance()->end() == |
186 std::find(BrowserList::GetInstance()->begin(), | 183 std::find(BrowserList::GetInstance()->begin(), |
187 BrowserList::GetInstance()->end(), browser)); | 184 BrowserList::GetInstance()->end(), browser)); |
188 } | 185 } |
189 } | 186 } |
190 | 187 |
191 g_browser_process->notification_ui_manager()->CancelAll(); | 188 g_browser_process->notification_ui_manager()->CancelAll(); |
192 } | 189 } |
OLD | NEW |