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