summaryrefslogtreecommitdiffstats
path: root/tools/android
diff options
context:
space:
mode:
authoranujk.sharma <anujk.sharma@samsung.com>2014-09-09 23:04:09 -0700
committerCommit bot <commit-bot@chromium.org>2014-09-10 06:10:12 +0000
commitefd2db86e9ac9e90c8cd2641f188a9c420edf2be (patch)
treee9c5a087ece6e480b918f134902012a302f29357 /tools/android
parenta8e2fc2bd5b2ded82a4822d40495a07c9773e85f (diff)
downloadchromium_src-efd2db86e9ac9e90c8cd2641f188a9c420edf2be.zip
chromium_src-efd2db86e9ac9e90c8cd2641f188a9c420edf2be.tar.gz
chromium_src-efd2db86e9ac9e90c8cd2641f188a9c420edf2be.tar.bz2
Fix WeakPtrFactory ordering problems in src/tools
Cleaning up weak_ptr_factory destruction order in "src/tools" module. WeakPtrFactory should remain the last member so it'll be destroyed and invalidate its weak pointers before any other members are destroyed. BUG=303818 Review URL: https://codereview.chromium.org/555093002 Cr-Commit-Position: refs/heads/master@{#294117}
Diffstat (limited to 'tools/android')
-rw-r--r--tools/android/forwarder2/device_controller.cc6
-rw-r--r--tools/android/forwarder2/device_controller.h7
-rw-r--r--tools/android/forwarder2/self_deleter_helper.h13
3 files changed, 18 insertions, 8 deletions
diff --git a/tools/android/forwarder2/device_controller.cc b/tools/android/forwarder2/device_controller.cc
index 7a4c0ad..a4cb9c7 100644
--- a/tools/android/forwarder2/device_controller.cc
+++ b/tools/android/forwarder2/device_controller.cc
@@ -47,10 +47,10 @@ void DeviceController::Start() {
DeviceController::DeviceController(scoped_ptr<Socket> host_socket,
int exit_notifier_fd)
- : weak_ptr_factory_(this),
- host_socket_(host_socket.Pass()),
+ : host_socket_(host_socket.Pass()),
exit_notifier_fd_(exit_notifier_fd),
- construction_task_runner_(base::MessageLoopProxy::current()) {
+ construction_task_runner_(base::MessageLoopProxy::current()),
+ weak_ptr_factory_(this) {
host_socket_->AddEventFd(exit_notifier_fd);
}
diff --git a/tools/android/forwarder2/device_controller.h b/tools/android/forwarder2/device_controller.h
index b1441d8..567a08d 100644
--- a/tools/android/forwarder2/device_controller.h
+++ b/tools/android/forwarder2/device_controller.h
@@ -49,7 +49,6 @@ class DeviceController {
const base::WeakPtr<DeviceController>& device_controller_ptr,
scoped_ptr<DeviceListener> device_listener);
- base::WeakPtrFactory<DeviceController> weak_ptr_factory_;
const scoped_ptr<Socket> host_socket_;
// Used to notify the controller to exit.
const int exit_notifier_fd_;
@@ -58,6 +57,12 @@ class DeviceController {
const scoped_refptr<base::SingleThreadTaskRunner> construction_task_runner_;
ListenersMap listeners_;
+ //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<DeviceController> weak_ptr_factory_;
+
DISALLOW_COPY_AND_ASSIGN(DeviceController);
};
diff --git a/tools/android/forwarder2/self_deleter_helper.h b/tools/android/forwarder2/self_deleter_helper.h
index a9d7498..d96903d 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);
};