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/browser_list_impl.h" | 5 #include "chrome/browser/ui/browser_list_impl.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.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" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 // try to catch evil observers that change the list from under us. | 63 // try to catch evil observers that change the list from under us. |
64 size_t original_count = observers_.size(); | 64 size_t original_count = observers_.size(); |
65 FOR_EACH_OBSERVER(BrowserListObserver, observers_, OnBrowserAdded(browser)); | 65 FOR_EACH_OBSERVER(BrowserListObserver, observers_, OnBrowserAdded(browser)); |
66 DCHECK_EQ(original_count, observers_.size()) | 66 DCHECK_EQ(original_count, observers_.size()) |
67 << "observer list modified during notification"; | 67 << "observer list modified during notification"; |
68 } | 68 } |
69 | 69 |
70 void BrowserListImpl::RemoveBrowser(Browser* browser) { | 70 void BrowserListImpl::RemoveBrowser(Browser* browser) { |
71 RemoveBrowserFrom(browser, &last_active_browsers_); | 71 RemoveBrowserFrom(browser, &last_active_browsers_); |
72 | 72 |
| 73 // Many UI tests rely on closing the last browser window quitting the |
| 74 // application. |
| 75 // Mac: Closing all windows does not indicate quitting the application. Lie |
| 76 // for now and ignore behavior outside of unit tests. |
| 77 // ChromeOS: Force closing last window to close app with flag. |
| 78 // TODO(andybons | pkotwicz): Fix the UI tests to Do The Right Thing. |
| 79 #if defined(OS_CHROMEOS) |
| 80 bool closing_app; |
| 81 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 82 switches::kDisableZeroBrowsersOpenForTests)) |
| 83 closing_app = (browsers_.size() == 1); |
| 84 else |
| 85 closing_app = (browsers_.size() == 1 && |
| 86 browser_shutdown::IsTryingToQuit()); |
| 87 #else |
| 88 bool closing_app = (browsers_.size() == 1); |
| 89 #endif // OS_CHROMEOS |
| 90 |
73 content::NotificationService::current()->Notify( | 91 content::NotificationService::current()->Notify( |
74 chrome::NOTIFICATION_BROWSER_CLOSED, | 92 chrome::NOTIFICATION_BROWSER_CLOSED, |
75 content::Source<Browser>(browser), | 93 content::Source<Browser>(browser), |
76 content::NotificationService::NoDetails()); | 94 content::Details<bool>(&closing_app)); |
77 | 95 |
78 RemoveBrowserFrom(browser, &browsers_); | 96 RemoveBrowserFrom(browser, &browsers_); |
79 | 97 |
80 // Do some basic checking to try to catch evil observers | 98 // Do some basic checking to try to catch evil observers |
81 // that change the list from under us. | 99 // that change the list from under us. |
82 size_t original_count = observers_.size(); | 100 size_t original_count = observers_.size(); |
83 FOR_EACH_OBSERVER(BrowserListObserver, observers_, OnBrowserRemoved(browser)); | 101 FOR_EACH_OBSERVER(BrowserListObserver, observers_, OnBrowserRemoved(browser)); |
84 DCHECK_EQ(original_count, observers_.size()) | 102 DCHECK_EQ(original_count, observers_.size()) |
85 << "observer list modified during notification"; | 103 << "observer list modified during notification"; |
86 | 104 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 | 197 |
180 void BrowserListImpl::RemoveBrowserFrom(Browser* browser, | 198 void BrowserListImpl::RemoveBrowserFrom(Browser* browser, |
181 BrowserVector* browser_list) { | 199 BrowserVector* browser_list) { |
182 const iterator remove_browser = | 200 const iterator remove_browser = |
183 std::find(browser_list->begin(), browser_list->end(), browser); | 201 std::find(browser_list->begin(), browser_list->end(), browser); |
184 if (remove_browser != browser_list->end()) | 202 if (remove_browser != browser_list->end()) |
185 browser_list->erase(remove_browser); | 203 browser_list->erase(remove_browser); |
186 } | 204 } |
187 | 205 |
188 } // namespace chrome | 206 } // namespace chrome |
OLD | NEW |