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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/memory/weak_ptr_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/observer_list.h
diff --git a/base/observer_list.h b/base/observer_list.h
index 0572ba6500da0f3584eb8d507e69a962ebf751f9..8e4442e026da481fec43ea7ce830cd5ff48808db 100644
--- a/base/observer_list.h
+++ b/base/observer_list.h
@@ -202,6 +202,15 @@ template <class ContainerType>
ObserverListBase<ObserverType>::Iter<ContainerType>::~Iter() {
if (list_ && --list_->notify_depth_ == 0)
list_->Compact();
+#if DCHECK_IS_ON()
+ if (list_) {
+ auto* list_raw = list_.get();
+ list_ = nullptr;
+ if (!list_raw->HasWeakPtrs()) {
+ list_raw->DetachFromSequence();
+ }
+ }
+#endif
}
template <class ObserverType>
« 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