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 observer_list = NULL; | |
jam
2012/06/06 16:48:05
nit: unnecessary
lengG
2012/06/07 14:08:51
Done.
| |
86 } | |
82 #ifndef NDEBUG | 87 #ifndef NDEBUG |
83 --observer_counts_[type]; | 88 --observer_counts_[type]; |
84 #endif | 89 #endif |
85 } | 90 } |
86 | |
87 // TODO(jhughes): Remove observer list from map if empty? | |
88 } | 91 } |
89 | 92 |
90 void NotificationServiceImpl::Notify( | 93 void NotificationServiceImpl::Notify( |
91 int type, | 94 int type, |
92 const content::NotificationSource& source, | 95 const content::NotificationSource& source, |
93 const content::NotificationDetails& details) { | 96 const content::NotificationDetails& details) { |
94 DCHECK(type > content::NOTIFICATION_ALL) << | 97 DCHECK(type > content::NOTIFICATION_ALL) << |
95 "Allowed for observing, but not posting."; | 98 "Allowed for observing, but not posting."; |
96 | 99 |
97 // There's no particular reason for the order in which the different | 100 // 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 } | 146 } |
144 #endif | 147 #endif |
145 | 148 |
146 for (int i = 0; i < static_cast<int>(observers_.size()); i++) { | 149 for (int i = 0; i < static_cast<int>(observers_.size()); i++) { |
147 NotificationSourceMap omap = observers_[i]; | 150 NotificationSourceMap omap = observers_[i]; |
148 for (NotificationSourceMap::iterator it = omap.begin(); | 151 for (NotificationSourceMap::iterator it = omap.begin(); |
149 it != omap.end(); ++it) | 152 it != omap.end(); ++it) |
150 delete it->second; | 153 delete it->second; |
151 } | 154 } |
152 } | 155 } |
OLD | NEW |