| 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 | 7 |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 Iterator(ObserverListBase<ObserverType>& list) | 82 Iterator(ObserverListBase<ObserverType>& list) |
| 83 : list_(list.AsWeakPtr()), | 83 : list_(list.AsWeakPtr()), |
| 84 index_(0), | 84 index_(0), |
| 85 max_index_(list.type_ == NOTIFY_ALL ? | 85 max_index_(list.type_ == NOTIFY_ALL ? |
| 86 std::numeric_limits<size_t>::max() : | 86 std::numeric_limits<size_t>::max() : |
| 87 list.observers_.size()) { | 87 list.observers_.size()) { |
| 88 ++list_->notify_depth_; | 88 ++list_->notify_depth_; |
| 89 } | 89 } |
| 90 | 90 |
| 91 ~Iterator() { | 91 ~Iterator() { |
| 92 if (list_ && --list_->notify_depth_ == 0) | 92 if (list_.get() && --list_->notify_depth_ == 0) |
| 93 list_->Compact(); | 93 list_->Compact(); |
| 94 } | 94 } |
| 95 | 95 |
| 96 ObserverType* GetNext() { | 96 ObserverType* GetNext() { |
| 97 if (!list_) | 97 if (!list_.get()) |
| 98 return NULL; | 98 return NULL; |
| 99 ListType& observers = list_->observers_; | 99 ListType& observers = list_->observers_; |
| 100 // Advance if the current element is null | 100 // Advance if the current element is null |
| 101 size_t max_index = std::min(max_index_, observers.size()); | 101 size_t max_index = std::min(max_index_, observers.size()); |
| 102 while (index_ < max_index && !observers[index_]) | 102 while (index_ < max_index && !observers[index_]) |
| 103 ++index_; | 103 ++index_; |
| 104 return index_ < max_index ? observers[index_++] : NULL; | 104 return index_ < max_index ? observers[index_++] : NULL; |
| 105 } | 105 } |
| 106 | 106 |
| 107 private: | 107 private: |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 do { \ | 207 do { \ |
| 208 if ((observer_list).might_have_observers()) { \ | 208 if ((observer_list).might_have_observers()) { \ |
| 209 ObserverListBase<ObserverType>::Iterator it(observer_list); \ | 209 ObserverListBase<ObserverType>::Iterator it(observer_list); \ |
| 210 ObserverType* obs; \ | 210 ObserverType* obs; \ |
| 211 while ((obs = it.GetNext()) != NULL) \ | 211 while ((obs = it.GetNext()) != NULL) \ |
| 212 obs->func; \ | 212 obs->func; \ |
| 213 } \ | 213 } \ |
| 214 } while (0) | 214 } while (0) |
| 215 | 215 |
| 216 #endif // BASE_OBSERVER_LIST_H__ | 216 #endif // BASE_OBSERVER_LIST_H__ |
| OLD | NEW |