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 | |
91 content::NotificationService::current()->Notify( | 73 content::NotificationService::current()->Notify( |
92 chrome::NOTIFICATION_BROWSER_CLOSED, | 74 chrome::NOTIFICATION_BROWSER_CLOSED, |
93 content::Source<Browser>(browser), | 75 content::Source<Browser>(browser), |
94 content::Details<bool>(&closing_app)); | 76 content::NotificationService::NoDetails()); |
95 | 77 |
96 RemoveBrowserFrom(browser, &browsers_); | 78 RemoveBrowserFrom(browser, &browsers_); |
97 | 79 |
98 // Do some basic checking to try to catch evil observers | 80 // Do some basic checking to try to catch evil observers |
99 // that change the list from under us. | 81 // that change the list from under us. |
100 size_t original_count = observers_.size(); | 82 size_t original_count = observers_.size(); |
101 FOR_EACH_OBSERVER(BrowserListObserver, observers_, OnBrowserRemoved(browser)); | 83 FOR_EACH_OBSERVER(BrowserListObserver, observers_, OnBrowserRemoved(browser)); |
102 DCHECK_EQ(original_count, observers_.size()) | 84 DCHECK_EQ(original_count, observers_.size()) |
103 << "observer list modified during notification"; | 85 << "observer list modified during notification"; |
104 | 86 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 | 179 |
198 void BrowserListImpl::RemoveBrowserFrom(Browser* browser, | 180 void BrowserListImpl::RemoveBrowserFrom(Browser* browser, |
199 BrowserVector* browser_list) { | 181 BrowserVector* browser_list) { |
200 const iterator remove_browser = | 182 const iterator remove_browser = |
201 std::find(browser_list->begin(), browser_list->end(), browser); | 183 std::find(browser_list->begin(), browser_list->end(), browser); |
202 if (remove_browser != browser_list->end()) | 184 if (remove_browser != browser_list->end()) |
203 browser_list->erase(remove_browser); | 185 browser_list->erase(remove_browser); |
204 } | 186 } |
205 | 187 |
206 } // namespace chrome | 188 } // namespace chrome |
OLD | NEW |