OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_CALLBACK_LIST_H_ | 5 #ifndef BASE_CALLBACK_LIST_H_ |
6 #define BASE_CALLBACK_LIST_H_ | 6 #define BASE_CALLBACK_LIST_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 removal_callback_ = callback; | 113 removal_callback_ = callback; |
114 } | 114 } |
115 | 115 |
116 // Returns true if there are no subscriptions. This is only valid to call when | 116 // Returns true if there are no subscriptions. This is only valid to call when |
117 // not looping through the list. | 117 // not looping through the list. |
118 bool empty() { | 118 bool empty() { |
119 DCHECK_EQ(0, active_iterator_count_); | 119 DCHECK_EQ(0, active_iterator_count_); |
120 return callbacks_.empty(); | 120 return callbacks_.empty(); |
121 } | 121 } |
122 | 122 |
| 123 // Clears all the callbacks from this list. |
| 124 void ClearAll() { callbacks_.clear(); } |
| 125 |
123 protected: | 126 protected: |
124 // An iterator class that can be used to access the list of callbacks. | 127 // An iterator class that can be used to access the list of callbacks. |
125 class Iterator { | 128 class Iterator { |
126 public: | 129 public: |
127 explicit Iterator(CallbackListBase<CallbackType>* list) | 130 explicit Iterator(CallbackListBase<CallbackType>* list) |
128 : list_(list), | 131 : list_(list), |
129 list_iter_(list_->callbacks_.begin()) { | 132 list_iter_(list_->callbacks_.begin()) { |
130 ++list_->active_iterator_count_; | 133 ++list_->active_iterator_count_; |
131 } | 134 } |
132 | 135 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 } | 223 } |
221 } | 224 } |
222 | 225 |
223 private: | 226 private: |
224 DISALLOW_COPY_AND_ASSIGN(CallbackList); | 227 DISALLOW_COPY_AND_ASSIGN(CallbackList); |
225 }; | 228 }; |
226 | 229 |
227 } // namespace base | 230 } // namespace base |
228 | 231 |
229 #endif // BASE_CALLBACK_LIST_H_ | 232 #endif // BASE_CALLBACK_LIST_H_ |
OLD | NEW |