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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 const NotificationDetails& details) { | 98 const NotificationDetails& details) { |
99 DCHECK_GT(type, NOTIFICATION_ALL) << | 99 DCHECK_GT(type, NOTIFICATION_ALL) << |
100 "Allowed for observing, but not posting."; | 100 "Allowed for observing, but not posting."; |
101 | 101 |
102 // There's no particular reason for the order in which the different | 102 // There's no particular reason for the order in which the different |
103 // classes of observers get notified here. | 103 // classes of observers get notified here. |
104 | 104 |
105 // Notify observers of all types and all sources | 105 // Notify observers of all types and all sources |
106 if (HasKey(observers_[NOTIFICATION_ALL], AllSources()) && | 106 if (HasKey(observers_[NOTIFICATION_ALL], AllSources()) && |
107 source != AllSources()) { | 107 source != AllSources()) { |
108 FOR_EACH_OBSERVER(NotificationObserver, | 108 for (auto& observer : *observers_[NOTIFICATION_ALL][AllSources().map_key()]) |
109 *observers_[NOTIFICATION_ALL][AllSources().map_key()], | 109 observer.Observe(type, source, details); |
110 Observe(type, source, details)); | |
111 } | 110 } |
112 | 111 |
113 // Notify observers of all types and the given source | 112 // Notify observers of all types and the given source |
114 if (HasKey(observers_[NOTIFICATION_ALL], source)) { | 113 if (HasKey(observers_[NOTIFICATION_ALL], source)) { |
115 FOR_EACH_OBSERVER(NotificationObserver, | 114 for (auto& observer : *observers_[NOTIFICATION_ALL][source.map_key()]) |
116 *observers_[NOTIFICATION_ALL][source.map_key()], | 115 observer.Observe(type, source, details); |
117 Observe(type, source, details)); | |
118 } | 116 } |
119 | 117 |
120 // Notify observers of the given type and all sources | 118 // Notify observers of the given type and all sources |
121 if (HasKey(observers_[type], AllSources()) && | 119 if (HasKey(observers_[type], AllSources()) && |
122 source != AllSources()) { | 120 source != AllSources()) { |
123 FOR_EACH_OBSERVER(NotificationObserver, | 121 for (auto& observer : *observers_[type][AllSources().map_key()]) |
124 *observers_[type][AllSources().map_key()], | 122 observer.Observe(type, source, details); |
125 Observe(type, source, details)); | |
126 } | 123 } |
127 | 124 |
128 // Notify observers of the given type and the given source | 125 // Notify observers of the given type and the given source |
129 if (HasKey(observers_[type], source)) { | 126 if (HasKey(observers_[type], source)) { |
130 FOR_EACH_OBSERVER(NotificationObserver, | 127 for (auto& observer : *observers_[type][source.map_key()]) |
131 *observers_[type][source.map_key()], | 128 observer.Observe(type, source, details); |
132 Observe(type, source, details)); | |
133 } | 129 } |
134 } | 130 } |
135 | 131 |
136 | 132 |
137 NotificationServiceImpl::~NotificationServiceImpl() { | 133 NotificationServiceImpl::~NotificationServiceImpl() { |
138 lazy_tls_ptr.Pointer()->Set(NULL); | 134 lazy_tls_ptr.Pointer()->Set(NULL); |
139 | 135 |
140 #ifndef NDEBUG | 136 #ifndef NDEBUG |
141 for (int i = 0; i < static_cast<int>(observer_counts_.size()); i++) { | 137 for (int i = 0; i < static_cast<int>(observer_counts_.size()); i++) { |
142 if (observer_counts_[i] > 0) { | 138 if (observer_counts_[i] > 0) { |
143 // This may not be completely fixable -- see | 139 // This may not be completely fixable -- see |
144 // http://code.google.com/p/chromium/issues/detail?id=11010 . | 140 // http://code.google.com/p/chromium/issues/detail?id=11010 . |
145 VLOG(1) << observer_counts_[i] << " notification observer(s) leaked " | 141 VLOG(1) << observer_counts_[i] << " notification observer(s) leaked " |
146 "of notification type " << i; | 142 "of notification type " << i; |
147 } | 143 } |
148 } | 144 } |
149 #endif | 145 #endif |
150 | 146 |
151 for (int i = 0; i < static_cast<int>(observers_.size()); i++) { | 147 for (int i = 0; i < static_cast<int>(observers_.size()); i++) { |
152 NotificationSourceMap omap = observers_[i]; | 148 NotificationSourceMap omap = observers_[i]; |
153 for (NotificationSourceMap::iterator it = omap.begin(); | 149 for (NotificationSourceMap::iterator it = omap.begin(); |
154 it != omap.end(); ++it) | 150 it != omap.end(); ++it) |
155 delete it->second; | 151 delete it->second; |
156 } | 152 } |
157 } | 153 } |
158 | 154 |
159 } // namespace content | 155 } // namespace content |
OLD | NEW |