| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/browser_list.h" | 5 #include "chrome/browser/browser_list.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 return *i; | 153 return *i; |
| 154 } | 154 } |
| 155 return NULL; | 155 return NULL; |
| 156 } | 156 } |
| 157 | 157 |
| 158 } // namespace | 158 } // namespace |
| 159 | 159 |
| 160 BrowserList::BrowserVector BrowserList::browsers_; | 160 BrowserList::BrowserVector BrowserList::browsers_; |
| 161 ObserverList<BrowserList::Observer> BrowserList::observers_; | 161 ObserverList<BrowserList::Observer> BrowserList::observers_; |
| 162 | 162 |
| 163 #if defined(OS_CHROMEOS) |
| 164 bool BrowserList::notified_window_manager_about_signout_ = false; |
| 165 #endif |
| 166 |
| 163 // static | 167 // static |
| 164 void BrowserList::AddBrowser(Browser* browser) { | 168 void BrowserList::AddBrowser(Browser* browser) { |
| 165 DCHECK(browser); | 169 DCHECK(browser); |
| 166 browsers_.push_back(browser); | 170 browsers_.push_back(browser); |
| 167 | 171 |
| 168 g_browser_process->AddRefModule(); | 172 g_browser_process->AddRefModule(); |
| 169 | 173 |
| 170 if (!activity_observer) | 174 if (!activity_observer) |
| 171 activity_observer = new BrowserActivityObserver; | 175 activity_observer = new BrowserActivityObserver; |
| 172 | 176 |
| 173 NotificationService::current()->Notify( | 177 NotificationService::current()->Notify( |
| 174 NotificationType::BROWSER_OPENED, | 178 NotificationType::BROWSER_OPENED, |
| 175 Source<Browser>(browser), | 179 Source<Browser>(browser), |
| 176 NotificationService::NoDetails()); | 180 NotificationService::NoDetails()); |
| 177 | 181 |
| 178 // Send out notifications after add has occurred. Do some basic checking to | 182 // Send out notifications after add has occurred. Do some basic checking to |
| 179 // try to catch evil observers that change the list from under us. | 183 // try to catch evil observers that change the list from under us. |
| 180 size_t original_count = observers_.size(); | 184 size_t original_count = observers_.size(); |
| 181 FOR_EACH_OBSERVER(Observer, observers_, OnBrowserAdded(browser)); | 185 FOR_EACH_OBSERVER(Observer, observers_, OnBrowserAdded(browser)); |
| 182 DCHECK_EQ(original_count, observers_.size()) | 186 DCHECK_EQ(original_count, observers_.size()) |
| 183 << "observer list modified during notification"; | 187 << "observer list modified during notification"; |
| 184 } | 188 } |
| 185 | 189 |
| 186 | 190 |
| 187 // static | 191 // static |
| 188 void BrowserList::NotifyAndTerminate() { | 192 void BrowserList::NotifyAndTerminate() { |
| 193 #if defined(OS_CHROMEOS) |
| 194 // Let the window manager know that we're going away before we start closing |
| 195 // windows so it can display a graceful transition to a black screen. |
| 196 chromeos::WmIpc::instance()->NotifyAboutSignout(); |
| 197 notified_window_manager_about_signout_ = true; |
| 198 #endif |
| 189 NotificationService::current()->Notify(NotificationType::APP_TERMINATING, | 199 NotificationService::current()->Notify(NotificationType::APP_TERMINATING, |
| 190 NotificationService::AllSources(), | 200 NotificationService::AllSources(), |
| 191 NotificationService::NoDetails()); | 201 NotificationService::NoDetails()); |
| 192 #if defined(OS_CHROMEOS) | 202 #if defined(OS_CHROMEOS) |
| 193 chromeos::WmIpc::instance()->NotifyAboutSignout(); | |
| 194 if (chromeos::CrosLibrary::Get()->EnsureLoaded()) { | 203 if (chromeos::CrosLibrary::Get()->EnsureLoaded()) { |
| 195 chromeos::CrosLibrary::Get()->GetLoginLibrary()->StopSession(""); | 204 chromeos::CrosLibrary::Get()->GetLoginLibrary()->StopSession(""); |
| 196 return; | 205 return; |
| 197 } | 206 } |
| 198 // If running the Chrome OS build, but we're not on the device, fall through | 207 // If running the Chrome OS build, but we're not on the device, fall through |
| 199 #endif | 208 #endif |
| 200 AllBrowsersClosedAndAppExiting(); | 209 AllBrowsersClosedAndAppExiting(); |
| 201 } | 210 } |
| 202 | 211 |
| 203 // static | 212 // static |
| (...skipping 25 matching lines...) Expand all Loading... |
| 229 activity_observer = NULL; | 238 activity_observer = NULL; |
| 230 } | 239 } |
| 231 | 240 |
| 232 g_browser_process->ReleaseModule(); | 241 g_browser_process->ReleaseModule(); |
| 233 | 242 |
| 234 // If we're exiting, send out the APP_TERMINATING notification to allow other | 243 // If we're exiting, send out the APP_TERMINATING notification to allow other |
| 235 // modules to shut themselves down. | 244 // modules to shut themselves down. |
| 236 if (browsers_.empty() && | 245 if (browsers_.empty() && |
| 237 (browser_shutdown::IsTryingToQuit() || | 246 (browser_shutdown::IsTryingToQuit() || |
| 238 g_browser_process->IsShuttingDown())) { | 247 g_browser_process->IsShuttingDown())) { |
| 248 #if defined(OS_CHROMEOS) |
| 249 // We might've already notified the window manager before closing any |
| 250 // windows in NotifyAndTerminate() if we were able to take the |
| 251 // no-beforeunload-handlers-or-downloads fast path; no need to do it again |
| 252 // here. |
| 253 if (!notified_window_manager_about_signout_) { |
| 254 chromeos::WmIpc::instance()->NotifyAboutSignout(); |
| 255 notified_window_manager_about_signout_ = true; |
| 256 } |
| 257 #endif |
| 239 // Last browser has just closed, and this is a user-initiated quit or there | 258 // Last browser has just closed, and this is a user-initiated quit or there |
| 240 // is no module keeping the app alive, so send out our notification. No need | 259 // is no module keeping the app alive, so send out our notification. No need |
| 241 // to call ProfileManager::ShutdownSessionServices() as part of the | 260 // to call ProfileManager::ShutdownSessionServices() as part of the |
| 242 // shutdown, because Browser::WindowClosing() already makes sure that the | 261 // shutdown, because Browser::WindowClosing() already makes sure that the |
| 243 // SessionService is created and notified. | 262 // SessionService is created and notified. |
| 244 NotificationService::current()->Notify(NotificationType::APP_TERMINATING, | 263 NotificationService::current()->Notify(NotificationType::APP_TERMINATING, |
| 245 NotificationService::AllSources(), | 264 NotificationService::AllSources(), |
| 246 NotificationService::NoDetails()); | 265 NotificationService::NoDetails()); |
| 247 AllBrowsersClosedAndAppExiting(); | 266 AllBrowsersClosedAndAppExiting(); |
| 248 } | 267 } |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 } | 612 } |
| 594 | 613 |
| 595 TabContents* next_tab = | 614 TabContents* next_tab = |
| 596 (*browser_iterator_)->GetTabContentsAt(web_view_index_); | 615 (*browser_iterator_)->GetTabContentsAt(web_view_index_); |
| 597 if (next_tab) { | 616 if (next_tab) { |
| 598 cur_ = next_tab; | 617 cur_ = next_tab; |
| 599 return; | 618 return; |
| 600 } | 619 } |
| 601 } | 620 } |
| 602 } | 621 } |
| OLD | NEW |