| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 EnsureValidIndex(); | 195 EnsureValidIndex(); |
| 196 DCHECK(list_); | 196 DCHECK(list_); |
| 197 ++list_->notify_depth_; | 197 ++list_->notify_depth_; |
| 198 } | 198 } |
| 199 | 199 |
| 200 template <class ObserverType> | 200 template <class ObserverType> |
| 201 template <class ContainerType> | 201 template <class ContainerType> |
| 202 ObserverListBase<ObserverType>::Iter<ContainerType>::~Iter() { | 202 ObserverListBase<ObserverType>::Iter<ContainerType>::~Iter() { |
| 203 if (list_ && --list_->notify_depth_ == 0) | 203 if (list_ && --list_->notify_depth_ == 0) |
| 204 list_->Compact(); | 204 list_->Compact(); |
| 205 #if DCHECK_IS_ON() |
| 206 if (list_) { |
| 207 auto* list_raw = list_.get(); |
| 208 list_ = nullptr; |
| 209 if (!list_raw->HasWeakPtrs()) { |
| 210 list_raw->DetachFromSequence(); |
| 211 } |
| 212 } |
| 213 #endif |
| 205 } | 214 } |
| 206 | 215 |
| 207 template <class ObserverType> | 216 template <class ObserverType> |
| 208 template <class ContainerType> | 217 template <class ContainerType> |
| 209 bool ObserverListBase<ObserverType>::Iter<ContainerType>::operator==( | 218 bool ObserverListBase<ObserverType>::Iter<ContainerType>::operator==( |
| 210 const Iter& other) const { | 219 const Iter& other) const { |
| 211 if (is_end() && other.is_end()) | 220 if (is_end() && other.is_end()) |
| 212 return true; | 221 return true; |
| 213 return list_.get() == other.list_.get() && index_ == other.index_; | 222 return list_.get() == other.list_.get() && index_ == other.index_; |
| 214 } | 223 } |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 } | 349 } |
| 341 | 350 |
| 342 bool might_have_observers() const { | 351 bool might_have_observers() const { |
| 343 return ObserverListBase<ObserverType>::size() != 0; | 352 return ObserverListBase<ObserverType>::size() != 0; |
| 344 } | 353 } |
| 345 }; | 354 }; |
| 346 | 355 |
| 347 } // namespace base | 356 } // namespace base |
| 348 | 357 |
| 349 #endif // BASE_OBSERVER_LIST_H_ | 358 #endif // BASE_OBSERVER_LIST_H_ |
| OLD | NEW |