OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/tabs/pinned_tab_service.h" |
| 6 |
| 7 #include "chrome/browser/browser.h" |
| 8 #include "chrome/browser/profile.h" |
| 9 #include "chrome/browser/tabs/pinned_tab_codec.h" |
| 10 #include "chrome/common/notification_service.h" |
| 11 #include "chrome/common/notification_type.h" |
| 12 |
| 13 PinnedTabService::PinnedTabService(Profile* profile) |
| 14 : profile_(profile), |
| 15 got_exiting_(false) { |
| 16 registrar_.Add(this, NotificationType::BROWSER_CLOSING, |
| 17 NotificationService::AllSources()); |
| 18 registrar_.Add(this, NotificationType::APP_EXITING, |
| 19 NotificationService::AllSources()); |
| 20 } |
| 21 |
| 22 void PinnedTabService::Observe(NotificationType type, |
| 23 const NotificationSource& source, |
| 24 const NotificationDetails& details) { |
| 25 if (got_exiting_) |
| 26 return; |
| 27 |
| 28 switch (type.value) { |
| 29 case NotificationType::BROWSER_CLOSING: { |
| 30 Browser* browser = Source<Browser>(source).ptr(); |
| 31 if (browser->profile() == profile_ && *(Details<bool>(details)).ptr()) |
| 32 GotExit(); |
| 33 break; |
| 34 } |
| 35 |
| 36 case NotificationType::APP_EXITING: { |
| 37 GotExit(); |
| 38 break; |
| 39 } |
| 40 |
| 41 default: |
| 42 NOTREACHED(); |
| 43 } |
| 44 } |
| 45 |
| 46 void PinnedTabService::GotExit() { |
| 47 DCHECK(!got_exiting_); |
| 48 got_exiting_ = true; |
| 49 PinnedTabCodec::WritePinnedTabs(profile_); |
| 50 } |
OLD | NEW |