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

Side by Side Diff: tools/android/forwarder2/self_deleter_helper.h

Issue 2881383003: Rename TaskRunner::RunsTasksOnCurrentThread() in //android_webview, //tools (Closed)
Patch Set: add //tools/android Created 3 years, 7 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 | « tools/android/forwarder2/host_controllers_manager.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 TOOLS_ANDROID_FORWARDER2_SELF_DELETER_HELPER_H_ 5 #ifndef TOOLS_ANDROID_FORWARDER2_SELF_DELETER_HELPER_H_
6 #define TOOLS_ANDROID_FORWARDER2_SELF_DELETER_HELPER_H_ 6 #define TOOLS_ANDROID_FORWARDER2_SELF_DELETER_HELPER_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 typedef base::Callback<void(std::unique_ptr<T>)> DeletionCallback; 100 typedef base::Callback<void(std::unique_ptr<T>)> DeletionCallback;
101 101
102 SelfDeleterHelper(T* self_deleting_object, 102 SelfDeleterHelper(T* self_deleting_object,
103 const DeletionCallback& deletion_callback) 103 const DeletionCallback& deletion_callback)
104 : construction_runner_(base::ThreadTaskRunnerHandle::Get()), 104 : construction_runner_(base::ThreadTaskRunnerHandle::Get()),
105 self_deleting_object_(self_deleting_object), 105 self_deleting_object_(self_deleting_object),
106 deletion_callback_(deletion_callback), 106 deletion_callback_(deletion_callback),
107 weak_ptr_factory_(this) {} 107 weak_ptr_factory_(this) {}
108 108
109 ~SelfDeleterHelper() { 109 ~SelfDeleterHelper() {
110 DCHECK(construction_runner_->RunsTasksOnCurrentThread()); 110 DCHECK(construction_runner_->RunsTasksInCurrentSequence());
111 } 111 }
112 112
113 void MaybeSelfDeleteSoon() { 113 void MaybeSelfDeleteSoon() {
114 DCHECK(!construction_runner_->RunsTasksOnCurrentThread()); 114 DCHECK(!construction_runner_->RunsTasksInCurrentSequence());
115 construction_runner_->PostTask( 115 construction_runner_->PostTask(
116 FROM_HERE, 116 FROM_HERE,
117 base::Bind(&SelfDeleterHelper::SelfDelete, 117 base::Bind(&SelfDeleterHelper::SelfDelete,
118 weak_ptr_factory_.GetWeakPtr())); 118 weak_ptr_factory_.GetWeakPtr()));
119 } 119 }
120 120
121 private: 121 private:
122 void SelfDelete() { 122 void SelfDelete() {
123 DCHECK(construction_runner_->RunsTasksOnCurrentThread()); 123 DCHECK(construction_runner_->RunsTasksInCurrentSequence());
124 deletion_callback_.Run(base::WrapUnique(self_deleting_object_)); 124 deletion_callback_.Run(base::WrapUnique(self_deleting_object_));
125 } 125 }
126 126
127 const scoped_refptr<base::SingleThreadTaskRunner> construction_runner_; 127 const scoped_refptr<base::SingleThreadTaskRunner> construction_runner_;
128 T* const self_deleting_object_; 128 T* const self_deleting_object_;
129 const DeletionCallback deletion_callback_; 129 const DeletionCallback deletion_callback_;
130 130
131 //WeakPtrFactory's documentation says: 131 //WeakPtrFactory's documentation says:
132 // Member variables should appear before the WeakPtrFactory, to ensure 132 // Member variables should appear before the WeakPtrFactory, to ensure
133 // that any WeakPtrs to Controller are invalidated before its members 133 // that any WeakPtrs to Controller are invalidated before its members
134 // variable's destructors are executed, rendering them invalid. 134 // variable's destructors are executed, rendering them invalid.
135 base::WeakPtrFactory<SelfDeleterHelper<T> > weak_ptr_factory_; 135 base::WeakPtrFactory<SelfDeleterHelper<T> > weak_ptr_factory_;
136 136
137 DISALLOW_COPY_AND_ASSIGN(SelfDeleterHelper); 137 DISALLOW_COPY_AND_ASSIGN(SelfDeleterHelper);
138 }; 138 };
139 139
140 } // namespace forwarder2 140 } // namespace forwarder2
141 141
142 #endif // TOOLS_ANDROID_FORWARDER2_SELF_DELETER_HELPER_H_ 142 #endif // TOOLS_ANDROID_FORWARDER2_SELF_DELETER_HELPER_H_
OLDNEW
« no previous file with comments | « tools/android/forwarder2/host_controllers_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698