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 "build/build_config.h" | 7 #include "build/build_config.h" |
8 #include "chrome/browser/background/background_mode_manager.h" | 8 #include "chrome/browser/background/background_mode_manager.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/browser_shutdown.h" | 10 #include "chrome/browser/browser_shutdown.h" |
11 #include "chrome/browser/download/download_service.h" | 11 #include "chrome/browser/download/download_service.h" |
12 #include "chrome/browser/download/download_service_factory.h" | 12 #include "chrome/browser/download/download_service_factory.h" |
13 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
15 #include "chrome/browser/ui/browser_iterator.h" | |
16 #include "chrome/browser/ui/browser_list.h" | 15 #include "chrome/browser/ui/browser_list.h" |
17 #include "chrome/browser/ui/browser_window.h" | 16 #include "chrome/browser/ui/browser_window.h" |
18 #include "chrome/browser/ui/chrome_pages.h" | 17 #include "chrome/browser/ui/chrome_pages.h" |
19 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | 18 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" |
20 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 19 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
21 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
22 | 21 |
23 namespace { | 22 namespace { |
24 | 23 |
25 // Navigates a browser window for |profile|, creating one if necessary, to the | 24 // Navigates a browser window for |profile|, creating one if necessary, to the |
(...skipping 23 matching lines...) Expand all Loading... | |
49 // Tell everyone that we are shutting down. | 48 // Tell everyone that we are shutting down. |
50 browser_shutdown::SetTryingToQuit(true); | 49 browser_shutdown::SetTryingToQuit(true); |
51 CloseBrowsers(); | 50 CloseBrowsers(); |
52 return; | 51 return; |
53 } | 52 } |
54 TryToCloseBrowsers(); | 53 TryToCloseBrowsers(); |
55 } | 54 } |
56 | 55 |
57 void BrowserCloseManager::CancelBrowserClose() { | 56 void BrowserCloseManager::CancelBrowserClose() { |
58 browser_shutdown::SetTryingToQuit(false); | 57 browser_shutdown::SetTryingToQuit(false); |
59 for (chrome::BrowserIterator it; !it.done(); it.Next()) { | 58 for (auto& browser : *BrowserList::GetInstance()) { |
60 it->ResetBeforeUnloadHandlers(); | 59 browser->ResetBeforeUnloadHandlers(); |
61 } | 60 } |
62 } | 61 } |
63 | 62 |
64 void BrowserCloseManager::TryToCloseBrowsers() { | 63 void BrowserCloseManager::TryToCloseBrowsers() { |
65 // If all browser windows can immediately be closed, fall out of this loop and | 64 // If all browser windows can immediately be closed, fall out of this loop and |
66 // close the browsers. If any browser window cannot be closed, temporarily | 65 // close the browsers. If any browser window cannot be closed, temporarily |
67 // stop closing. CallBeforeUnloadHandlers prompts the user and calls | 66 // stop closing. CallBeforeUnloadHandlers prompts the user and calls |
68 // OnBrowserReportCloseable with the result. If the user confirms the close, | 67 // OnBrowserReportCloseable with the result. If the user confirms the close, |
69 // this will trigger TryToCloseBrowsers to try again. | 68 // this will trigger TryToCloseBrowsers to try again. |
70 for (chrome::BrowserIterator it; !it.done(); it.Next()) { | 69 for (auto& browser : *BrowserList::GetInstance()) { |
71 if (it->CallBeforeUnloadHandlers( | 70 if (browser->CallBeforeUnloadHandlers( |
72 base::Bind(&BrowserCloseManager::OnBrowserReportCloseable, this))) { | 71 base::Bind(&BrowserCloseManager::OnBrowserReportCloseable, this))) { |
73 current_browser_ = *it; | 72 current_browser_ = browser; |
74 return; | 73 return; |
75 } | 74 } |
76 } | 75 } |
77 CheckForDownloadsInProgress(); | 76 CheckForDownloadsInProgress(); |
78 } | 77 } |
79 | 78 |
80 void BrowserCloseManager::OnBrowserReportCloseable(bool proceed) { | 79 void BrowserCloseManager::OnBrowserReportCloseable(bool proceed) { |
81 if (!current_browser_) | 80 if (!current_browser_) |
82 return; | 81 return; |
83 | 82 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
145 #endif | 144 #endif |
146 if (!browser_shutdown::IsTryingToQuit()) { | 145 if (!browser_shutdown::IsTryingToQuit()) { |
147 BackgroundModeManager* background_mode_manager = | 146 BackgroundModeManager* background_mode_manager = |
148 g_browser_process->background_mode_manager(); | 147 g_browser_process->background_mode_manager(); |
149 if (background_mode_manager) | 148 if (background_mode_manager) |
150 background_mode_manager->SuspendBackgroundMode(); | 149 background_mode_manager->SuspendBackgroundMode(); |
151 } | 150 } |
152 | 151 |
153 bool session_ending = | 152 bool session_ending = |
154 browser_shutdown::GetShutdownType() == browser_shutdown::END_SESSION; | 153 browser_shutdown::GetShutdownType() == browser_shutdown::END_SESSION; |
155 for (scoped_ptr<chrome::BrowserIterator> it_ptr( | 154 for (BrowserList::const_iterator browser = |
scottmg
2016/01/28 02:19:54
This is the only one that's non-trivial because of
| |
156 new chrome::BrowserIterator()); | 155 BrowserList::GetInstance()->begin(); |
157 !it_ptr->done();) { | 156 browser != BrowserList::GetInstance()->end();) { |
158 Browser* browser = **it_ptr; | 157 (*browser)->window()->Close(); |
159 browser->window()->Close(); | |
160 if (!session_ending) { | 158 if (!session_ending) { |
161 it_ptr->Next(); | 159 browser++; |
162 } else { | 160 } else { |
163 // This path is hit during logoff/power-down. In this case we won't get | 161 // This path is hit during logoff/power-down. In this case we won't get |
164 // a final message and so we force the browser to be deleted. | 162 // a final message and so we force the browser to be deleted. |
165 // Close doesn't immediately destroy the browser | 163 // Close doesn't immediately destroy the browser |
166 // (Browser::TabStripEmpty() uses invoke later) but when we're ending the | 164 // (Browser::TabStripEmpty() uses invoke later) but when we're ending the |
167 // session we need to make sure the browser is destroyed now. So, invoke | 165 // session we need to make sure the browser is destroyed now. So, invoke |
168 // DestroyBrowser to make sure the browser is deleted and cleanup can | 166 // DestroyBrowser to make sure the browser is deleted and cleanup can |
169 // happen. | 167 // happen. |
170 while (browser->tab_strip_model()->count()) | 168 while ((*browser)->tab_strip_model()->count()) |
171 delete browser->tab_strip_model()->GetWebContentsAt(0); | 169 delete (*browser)->tab_strip_model()->GetWebContentsAt(0); |
172 browser->window()->DestroyBrowser(); | 170 Browser* before = (*browser); |
173 it_ptr.reset(new chrome::BrowserIterator()); | 171 (*browser)->window()->DestroyBrowser(); |
174 if (!it_ptr->done() && browser == **it_ptr) { | 172 browser = BrowserList::GetInstance()->begin(); |
173 if (browser != BrowserList::GetInstance()->end() && | |
174 (*browser) == before) { | |
175 // Destroying the browser should have removed it from the browser list. | 175 // Destroying the browser should have removed it from the browser list. |
176 // We should never get here. | 176 // We should never get here. |
177 NOTREACHED(); | 177 NOTREACHED(); |
178 return; | 178 return; |
179 } | 179 } |
180 } | 180 } |
181 } | 181 } |
182 } | 182 } |
OLD | NEW |