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/tabs/pinned_tab_service.h" | 5 #include "chrome/browser/tabs/pinned_tab_service.h" |
6 | 6 |
7 #include "chrome/browser/profiles/profile.h" | 7 #include "chrome/browser/profiles/profile.h" |
8 #include "chrome/browser/tabs/pinned_tab_codec.h" | 8 #include "chrome/browser/tabs/pinned_tab_codec.h" |
9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/browser/ui/browser_list.h" | 10 #include "chrome/browser/ui/browser_list.h" |
| 11 #include "chrome/common/chrome_notification_types.h" |
11 #include "content/common/notification_service.h" | 12 #include "content/common/notification_service.h" |
12 #include "content/common/notification_type.h" | |
13 | 13 |
14 static bool IsLastNormalBrowser(Browser* browser) { | 14 static bool IsLastNormalBrowser(Browser* browser) { |
15 for (BrowserList::const_iterator i = BrowserList::begin(); | 15 for (BrowserList::const_iterator i = BrowserList::begin(); |
16 i != BrowserList::end(); ++i) { | 16 i != BrowserList::end(); ++i) { |
17 if (*i != browser && (*i)->is_type_tabbed() && | 17 if (*i != browser && (*i)->is_type_tabbed() && |
18 (*i)->profile() == browser->profile()) { | 18 (*i)->profile() == browser->profile()) { |
19 return false; | 19 return false; |
20 } | 20 } |
21 } | 21 } |
22 return true; | 22 return true; |
23 } | 23 } |
24 | 24 |
25 PinnedTabService::PinnedTabService(Profile* profile) | 25 PinnedTabService::PinnedTabService(Profile* profile) |
26 : profile_(profile), | 26 : profile_(profile), |
27 got_exiting_(false), | 27 got_exiting_(false), |
28 has_normal_browser_(false) { | 28 has_normal_browser_(false) { |
29 registrar_.Add(this, NotificationType::BROWSER_OPENED, | 29 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_OPENED, |
30 NotificationService::AllSources()); | 30 NotificationService::AllSources()); |
31 registrar_.Add(this, NotificationType::BROWSER_CLOSING, | 31 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_CLOSING, |
32 NotificationService::AllSources()); | 32 NotificationService::AllSources()); |
33 registrar_.Add(this, NotificationType::APP_EXITING, | 33 registrar_.Add(this, content::NOTIFICATION_APP_EXITING, |
34 NotificationService::AllSources()); | 34 NotificationService::AllSources()); |
35 } | 35 } |
36 | 36 |
37 void PinnedTabService::Observe(NotificationType type, | 37 void PinnedTabService::Observe(int type, |
38 const NotificationSource& source, | 38 const NotificationSource& source, |
39 const NotificationDetails& details) { | 39 const NotificationDetails& details) { |
40 if (got_exiting_) | 40 if (got_exiting_) |
41 return; | 41 return; |
42 | 42 |
43 switch (type.value) { | 43 switch (type) { |
44 case NotificationType::BROWSER_OPENED: { | 44 case chrome::NOTIFICATION_BROWSER_OPENED: { |
45 Browser* browser = Source<Browser>(source).ptr(); | 45 Browser* browser = Source<Browser>(source).ptr(); |
46 if (!has_normal_browser_ && browser->is_type_tabbed() && | 46 if (!has_normal_browser_ && browser->is_type_tabbed() && |
47 browser->profile() == profile_) { | 47 browser->profile() == profile_) { |
48 has_normal_browser_ = true; | 48 has_normal_browser_ = true; |
49 } | 49 } |
50 break; | 50 break; |
51 } | 51 } |
52 | 52 |
53 case NotificationType::BROWSER_CLOSING: { | 53 case chrome::NOTIFICATION_BROWSER_CLOSING: { |
54 Browser* browser = Source<Browser>(source).ptr(); | 54 Browser* browser = Source<Browser>(source).ptr(); |
55 if (has_normal_browser_ && browser->profile() == profile_) { | 55 if (has_normal_browser_ && browser->profile() == profile_) { |
56 if (*(Details<bool>(details)).ptr()) { | 56 if (*(Details<bool>(details)).ptr()) { |
57 GotExit(); | 57 GotExit(); |
58 } else if (IsLastNormalBrowser(browser)) { | 58 } else if (IsLastNormalBrowser(browser)) { |
59 has_normal_browser_ = false; | 59 has_normal_browser_ = false; |
60 PinnedTabCodec::WritePinnedTabs(profile_); | 60 PinnedTabCodec::WritePinnedTabs(profile_); |
61 } | 61 } |
62 } | 62 } |
63 break; | 63 break; |
64 } | 64 } |
65 | 65 |
66 case NotificationType::APP_EXITING: { | 66 case content::NOTIFICATION_APP_EXITING: { |
67 if (has_normal_browser_) | 67 if (has_normal_browser_) |
68 GotExit(); | 68 GotExit(); |
69 break; | 69 break; |
70 } | 70 } |
71 | 71 |
72 default: | 72 default: |
73 NOTREACHED(); | 73 NOTREACHED(); |
74 } | 74 } |
75 } | 75 } |
76 | 76 |
77 void PinnedTabService::GotExit() { | 77 void PinnedTabService::GotExit() { |
78 DCHECK(!got_exiting_); | 78 DCHECK(!got_exiting_); |
79 got_exiting_ = true; | 79 got_exiting_ = true; |
80 PinnedTabCodec::WritePinnedTabs(profile_); | 80 PinnedTabCodec::WritePinnedTabs(profile_); |
81 } | 81 } |
OLD | NEW |