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); |
}; |