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

Unified Diff: tools/android/forwarder2/self_deleter_helper.h

Issue 555093002: Fix WeakPtrFactory ordering problems in src/tools (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added the comment explaining WeakPtrFactory ordering Created 6 years, 3 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 | « tools/android/forwarder2/device_controller.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/android/forwarder2/self_deleter_helper.h
diff --git a/tools/android/forwarder2/self_deleter_helper.h b/tools/android/forwarder2/self_deleter_helper.h
index a9d749865d44ac4d76c1679e5389e921fa511a6d..d96903d5db0677e65e069731cfe4a7e825914afc 100644
--- a/tools/android/forwarder2/self_deleter_helper.h
+++ b/tools/android/forwarder2/self_deleter_helper.h
@@ -99,10 +99,10 @@ class SelfDeleterHelper {
SelfDeleterHelper(T* self_deleting_object,
const DeletionCallback& deletion_callback)
- : weak_ptr_factory_(this),
- construction_runner_(base::MessageLoopProxy::current()),
+ : construction_runner_(base::MessageLoopProxy::current()),
self_deleting_object_(self_deleting_object),
- deletion_callback_(deletion_callback) {
+ deletion_callback_(deletion_callback),
+ weak_ptr_factory_(this) {
}
~SelfDeleterHelper() {
@@ -123,11 +123,16 @@ class SelfDeleterHelper {
deletion_callback_.Run(make_scoped_ptr(self_deleting_object_));
}
- base::WeakPtrFactory<SelfDeleterHelper<T> > weak_ptr_factory_;
const scoped_refptr<base::SingleThreadTaskRunner> construction_runner_;
T* const self_deleting_object_;
const DeletionCallback deletion_callback_;
+ //WeakPtrFactory's documentation says:
+ // Member variables should appear before the WeakPtrFactory, to ensure
+ // that any WeakPtrs to Controller are invalidated before its members
+ // variable's destructors are executed, rendering them invalid.
+ base::WeakPtrFactory<SelfDeleterHelper<T> > weak_ptr_factory_;
+
DISALLOW_COPY_AND_ASSIGN(SelfDeleterHelper);
};
« no previous file with comments | « tools/android/forwarder2/device_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698