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 #ifndef BASE_OBSERVER_LIST_H__ | 5 #ifndef BASE_OBSERVER_LIST_H__ |
6 #define BASE_OBSERVER_LIST_H__ | 6 #define BASE_OBSERVER_LIST_H__ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <limits> | 10 #include <limits> |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 } | 155 } |
156 } else { | 156 } else { |
157 observers_.clear(); | 157 observers_.clear(); |
158 } | 158 } |
159 } | 159 } |
160 | 160 |
161 size_t size() const { return observers_.size(); } | 161 size_t size() const { return observers_.size(); } |
162 | 162 |
163 protected: | 163 protected: |
164 void Compact() { | 164 void Compact() { |
165 typename ListType::iterator it = observers_.begin(); | 165 observers_.erase( |
166 while (it != observers_.end()) { | 166 std::remove(observers_.begin(), observers_.end(), |
167 if (*it) { | 167 static_cast<ObserverType*>(NULL)), observers_.end()); |
168 ++it; | |
169 } else { | |
170 it = observers_.erase(it); | |
171 } | |
172 } | |
173 } | 168 } |
174 | 169 |
175 private: | 170 private: |
176 friend class ObserverListThreadSafe<ObserverType>; | 171 friend class ObserverListThreadSafe<ObserverType>; |
177 | 172 |
178 typedef std::vector<ObserverType*> ListType; | 173 typedef std::vector<ObserverType*> ListType; |
179 | 174 |
180 ListType observers_; | 175 ListType observers_; |
181 int notify_depth_; | 176 int notify_depth_; |
182 NotificationType type_; | 177 NotificationType type_; |
(...skipping 30 matching lines...) Expand all Loading... |
213 do { \ | 208 do { \ |
214 if ((observer_list).might_have_observers()) { \ | 209 if ((observer_list).might_have_observers()) { \ |
215 ObserverListBase<ObserverType>::Iterator it(observer_list); \ | 210 ObserverListBase<ObserverType>::Iterator it(observer_list); \ |
216 ObserverType* obs; \ | 211 ObserverType* obs; \ |
217 while ((obs = it.GetNext()) != NULL) \ | 212 while ((obs = it.GetNext()) != NULL) \ |
218 obs->func; \ | 213 obs->func; \ |
219 } \ | 214 } \ |
220 } while (0) | 215 } while (0) |
221 | 216 |
222 #endif // BASE_OBSERVER_LIST_H__ | 217 #endif // BASE_OBSERVER_LIST_H__ |
OLD | NEW |