OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/notification_service_impl.h" | 5 #include "content/browser/notification_service_impl.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/threading/thread_local.h" | 8 #include "base/threading/thread_local.h" |
9 #include "content/public/browser/notification_observer.h" | 9 #include "content/public/browser/notification_observer.h" |
10 #include "content/public/browser/notification_types.h" | 10 #include "content/public/browser/notification_types.h" |
11 | 11 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 // has its deleted pointer in its map. A garbge object will be called in the | 72 // has its deleted pointer in its map. A garbge object will be called in the |
73 // future. | 73 // future. |
74 // NOTE: when this check shows crashes, use BrowserThread::DeleteOnIOThread or | 74 // NOTE: when this check shows crashes, use BrowserThread::DeleteOnIOThread or |
75 // other variants as the trait on the object. | 75 // other variants as the trait on the object. |
76 CHECK(HasKey(observers_[type], source)); | 76 CHECK(HasKey(observers_[type], source)); |
77 | 77 |
78 NotificationObserverList* observer_list = | 78 NotificationObserverList* observer_list = |
79 observers_[type][source.map_key()]; | 79 observers_[type][source.map_key()]; |
80 if (observer_list) { | 80 if (observer_list) { |
81 observer_list->RemoveObserver(observer); | 81 observer_list->RemoveObserver(observer); |
| 82 if (!observer_list->size()) { |
| 83 observers_[type].erase(source.map_key()); |
| 84 delete observer_list; |
| 85 } |
82 #ifndef NDEBUG | 86 #ifndef NDEBUG |
83 --observer_counts_[type]; | 87 --observer_counts_[type]; |
84 #endif | 88 #endif |
85 } | 89 } |
86 | |
87 // TODO(jhughes): Remove observer list from map if empty? | |
88 } | 90 } |
89 | 91 |
90 void NotificationServiceImpl::Notify( | 92 void NotificationServiceImpl::Notify( |
91 int type, | 93 int type, |
92 const content::NotificationSource& source, | 94 const content::NotificationSource& source, |
93 const content::NotificationDetails& details) { | 95 const content::NotificationDetails& details) { |
94 DCHECK(type > content::NOTIFICATION_ALL) << | 96 DCHECK(type > content::NOTIFICATION_ALL) << |
95 "Allowed for observing, but not posting."; | 97 "Allowed for observing, but not posting."; |
96 | 98 |
97 // There's no particular reason for the order in which the different | 99 // There's no particular reason for the order in which the different |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 } | 145 } |
144 #endif | 146 #endif |
145 | 147 |
146 for (int i = 0; i < static_cast<int>(observers_.size()); i++) { | 148 for (int i = 0; i < static_cast<int>(observers_.size()); i++) { |
147 NotificationSourceMap omap = observers_[i]; | 149 NotificationSourceMap omap = observers_[i]; |
148 for (NotificationSourceMap::iterator it = omap.begin(); | 150 for (NotificationSourceMap::iterator it = omap.begin(); |
149 it != omap.end(); ++it) | 151 it != omap.end(); ++it) |
150 delete it->second; | 152 delete it->second; |
151 } | 153 } |
152 } | 154 } |
OLD | NEW |