OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 | 7 |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <limits> | 9 #include <limits> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 if (notify_depth_) { | 142 if (notify_depth_) { |
143 for (typename ListType::iterator it = observers_.begin(); | 143 for (typename ListType::iterator it = observers_.begin(); |
144 it != observers_.end(); ++it) { | 144 it != observers_.end(); ++it) { |
145 *it = 0; | 145 *it = 0; |
146 } | 146 } |
147 } else { | 147 } else { |
148 observers_.clear(); | 148 observers_.clear(); |
149 } | 149 } |
150 } | 150 } |
151 | 151 |
| 152 size_t size() const { return observers_.size(); } |
| 153 |
152 protected: | 154 protected: |
153 size_t size() const { | |
154 return observers_.size(); | |
155 } | |
156 | |
157 void Compact() { | 155 void Compact() { |
158 typename ListType::iterator it = observers_.begin(); | 156 typename ListType::iterator it = observers_.begin(); |
159 while (it != observers_.end()) { | 157 while (it != observers_.end()) { |
160 if (*it) { | 158 if (*it) { |
161 ++it; | 159 ++it; |
162 } else { | 160 } else { |
163 it = observers_.erase(it); | 161 it = observers_.erase(it); |
164 } | 162 } |
165 } | 163 } |
166 } | 164 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 | 198 |
201 #define FOR_EACH_OBSERVER(ObserverType, observer_list, func) \ | 199 #define FOR_EACH_OBSERVER(ObserverType, observer_list, func) \ |
202 do { \ | 200 do { \ |
203 ObserverListBase<ObserverType>::Iterator it(observer_list); \ | 201 ObserverListBase<ObserverType>::Iterator it(observer_list); \ |
204 ObserverType* obs; \ | 202 ObserverType* obs; \ |
205 while ((obs = it.GetNext()) != NULL) \ | 203 while ((obs = it.GetNext()) != NULL) \ |
206 obs->func; \ | 204 obs->func; \ |
207 } while (0) | 205 } while (0) |
208 | 206 |
209 #endif // BASE_OBSERVER_LIST_H__ | 207 #endif // BASE_OBSERVER_LIST_H__ |
OLD | NEW |