| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/chromeos/tab_closeable_state_watcher.h" | 5 #include "chrome/browser/chromeos/tab_closeable_state_watcher.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "chrome/browser/browser_shutdown.h" | 8 #include "chrome/browser/browser_shutdown.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/tabs/tab_strip_model.h" | 10 #include "chrome/browser/tabs/tab_strip_model.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 // TabCloseableStateWatcher, public: | 63 // TabCloseableStateWatcher, public: |
| 64 | 64 |
| 65 TabCloseableStateWatcher::TabCloseableStateWatcher() | 65 TabCloseableStateWatcher::TabCloseableStateWatcher() |
| 66 : can_close_tab_(true), | 66 : can_close_tab_(true), |
| 67 signing_off_(false), | 67 signing_off_(false), |
| 68 guest_session_( | 68 guest_session_( |
| 69 CommandLine::ForCurrentProcess()->HasSwitch( | 69 CommandLine::ForCurrentProcess()->HasSwitch( |
| 70 switches::kGuestSession)), | 70 switches::kGuestSession)), |
| 71 waiting_for_browser_(false) { | 71 waiting_for_browser_(false) { |
| 72 BrowserList::AddObserver(this); | 72 BrowserList::AddObserver(this); |
| 73 notification_registrar_.Add(this, NotificationType::APP_EXITING, | 73 notification_registrar_.Add(this, chrome::APP_EXITING, |
| 74 NotificationService::AllSources()); | 74 NotificationService::AllSources()); |
| 75 } | 75 } |
| 76 | 76 |
| 77 TabCloseableStateWatcher::~TabCloseableStateWatcher() { | 77 TabCloseableStateWatcher::~TabCloseableStateWatcher() { |
| 78 BrowserList::RemoveObserver(this); | 78 BrowserList::RemoveObserver(this); |
| 79 if (!browser_shutdown::ShuttingDownWithoutClosingBrowsers()) | 79 if (!browser_shutdown::ShuttingDownWithoutClosingBrowsers()) |
| 80 DCHECK(tabstrip_watchers_.empty()); | 80 DCHECK(tabstrip_watchers_.empty()); |
| 81 } | 81 } |
| 82 | 82 |
| 83 bool TabCloseableStateWatcher::CanCloseTab(const Browser* browser) const { | 83 bool TabCloseableStateWatcher::CanCloseTab(const Browser* browser) const { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 break; | 180 break; |
| 181 } | 181 } |
| 182 } | 182 } |
| 183 | 183 |
| 184 CheckAndUpdateState(NULL); | 184 CheckAndUpdateState(NULL); |
| 185 } | 185 } |
| 186 | 186 |
| 187 //////////////////////////////////////////////////////////////////////////////// | 187 //////////////////////////////////////////////////////////////////////////////// |
| 188 // TabCloseableStateWatcher, NotificationObserver implementation: | 188 // TabCloseableStateWatcher, NotificationObserver implementation: |
| 189 | 189 |
| 190 void TabCloseableStateWatcher::Observe(NotificationType type, | 190 void TabCloseableStateWatcher::Observe(int type, |
| 191 const NotificationSource& source, const NotificationDetails& details) { | 191 const NotificationSource& source, const NotificationDetails& details) { |
| 192 if (type.value != NotificationType::APP_EXITING) | 192 if (type != chrome::APP_EXITING) |
| 193 NOTREACHED(); | 193 NOTREACHED(); |
| 194 if (!signing_off_) { | 194 if (!signing_off_) { |
| 195 signing_off_ = true; | 195 signing_off_ = true; |
| 196 SetCloseableState(true); | 196 SetCloseableState(true); |
| 197 } | 197 } |
| 198 } | 198 } |
| 199 | 199 |
| 200 //////////////////////////////////////////////////////////////////////////////// | 200 //////////////////////////////////////////////////////////////////////////////// |
| 201 // TabCloseableStateWatcher, private | 201 // TabCloseableStateWatcher, private |
| 202 | 202 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 } | 253 } |
| 254 | 254 |
| 255 void TabCloseableStateWatcher::SetCloseableState(bool closeable) { | 255 void TabCloseableStateWatcher::SetCloseableState(bool closeable) { |
| 256 if (can_close_tab_ == closeable) // No change in state. | 256 if (can_close_tab_ == closeable) // No change in state. |
| 257 return; | 257 return; |
| 258 | 258 |
| 259 can_close_tab_ = closeable; | 259 can_close_tab_ = closeable; |
| 260 | 260 |
| 261 // Notify of change in tab closeable state. | 261 // Notify of change in tab closeable state. |
| 262 NotificationService::current()->Notify( | 262 NotificationService::current()->Notify( |
| 263 NotificationType::TAB_CLOSEABLE_STATE_CHANGED, | 263 chrome::TAB_CLOSEABLE_STATE_CHANGED, |
| 264 NotificationService::AllSources(), | 264 NotificationService::AllSources(), |
| 265 Details<bool>(&can_close_tab_)); | 265 Details<bool>(&can_close_tab_)); |
| 266 } | 266 } |
| 267 | 267 |
| 268 bool TabCloseableStateWatcher::CanCloseBrowserImpl( | 268 bool TabCloseableStateWatcher::CanCloseBrowserImpl( |
| 269 const Browser* browser, | 269 const Browser* browser, |
| 270 BrowserActionType* action_type) { | 270 BrowserActionType* action_type) { |
| 271 *action_type = NONE; | 271 *action_type = NONE; |
| 272 | 272 |
| 273 // If we're waiting for a new browser allow the close. | 273 // If we're waiting for a new browser allow the close. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 300 if (!can_close_tab_) | 300 if (!can_close_tab_) |
| 301 return false; | 301 return false; |
| 302 | 302 |
| 303 // Otherwise, close existing tabs, and deny closing of browser. | 303 // Otherwise, close existing tabs, and deny closing of browser. |
| 304 // TabClosingAt will open NTP when the last tab is being closed. | 304 // TabClosingAt will open NTP when the last tab is being closed. |
| 305 *action_type = OPEN_NTP; | 305 *action_type = OPEN_NTP; |
| 306 return false; | 306 return false; |
| 307 } | 307 } |
| 308 | 308 |
| 309 } // namespace chromeos | 309 } // namespace chromeos |
| OLD | NEW |