Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: base/observer_list.h

Issue 1602443003: Improve GetWeakPtr() to better protect against unsafe usage patterns. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/memory/weak_ptr_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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_
OLDNEW
« no previous file with comments | « base/memory/weak_ptr_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698