OLD | NEW |
1 // Copyright (c) 2012 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" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 // has its deleted pointer in its map. A garbge object will be called in the | 76 // has its deleted pointer in its map. A garbge object will be called in the |
77 // future. | 77 // future. |
78 // NOTE: when this check shows crashes, use BrowserThread::DeleteOnIOThread or | 78 // NOTE: when this check shows crashes, use BrowserThread::DeleteOnIOThread or |
79 // other variants as the trait on the object. | 79 // other variants as the trait on the object. |
80 CHECK(HasKey(observers_[type], source)); | 80 CHECK(HasKey(observers_[type], source)); |
81 | 81 |
82 NotificationObserverList* observer_list = | 82 NotificationObserverList* observer_list = |
83 observers_[type][source.map_key()]; | 83 observers_[type][source.map_key()]; |
84 if (observer_list) { | 84 if (observer_list) { |
85 observer_list->RemoveObserver(observer); | 85 observer_list->RemoveObserver(observer); |
86 if (!observer_list->size()) { | 86 if (!observer_list->might_have_observers()) { |
87 observers_[type].erase(source.map_key()); | 87 observers_[type].erase(source.map_key()); |
88 delete observer_list; | 88 delete observer_list; |
89 } | 89 } |
90 #ifndef NDEBUG | 90 #ifndef NDEBUG |
91 --observer_counts_[type]; | 91 --observer_counts_[type]; |
92 #endif | 92 #endif |
93 } | 93 } |
94 } | 94 } |
95 | 95 |
96 void NotificationServiceImpl::Notify(int type, | 96 void NotificationServiceImpl::Notify(int type, |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 | 150 |
151 for (int i = 0; i < static_cast<int>(observers_.size()); i++) { | 151 for (int i = 0; i < static_cast<int>(observers_.size()); i++) { |
152 NotificationSourceMap omap = observers_[i]; | 152 NotificationSourceMap omap = observers_[i]; |
153 for (NotificationSourceMap::iterator it = omap.begin(); | 153 for (NotificationSourceMap::iterator it = omap.begin(); |
154 it != omap.end(); ++it) | 154 it != omap.end(); ++it) |
155 delete it->second; | 155 delete it->second; |
156 } | 156 } |
157 } | 157 } |
158 | 158 |
159 } // namespace content | 159 } // namespace content |
OLD | NEW |