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

Side by Side Diff: base/sequenced_task_runner.h

Issue 2686033002: Simplify SequencedTaskRunner::{Delete,Releaose}Soon impl (Closed)
Patch Set: public -> private Created 3 years, 10 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 | « no previous file | base/sequenced_task_runner.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 BASE_SEQUENCED_TASK_RUNNER_H_ 5 #ifndef BASE_SEQUENCED_TASK_RUNNER_H_
6 #define BASE_SEQUENCED_TASK_RUNNER_H_ 6 #define BASE_SEQUENCED_TASK_RUNNER_H_
7 7
8 #include "base/base_export.h" 8 #include "base/base_export.h"
9 #include "base/sequenced_task_runner_helpers.h" 9 #include "base/sequenced_task_runner_helpers.h"
10 #include "base/task_runner.h" 10 #include "base/task_runner.h"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 const tracked_objects::Location& from_here, 115 const tracked_objects::Location& from_here,
116 const Closure& task, 116 const Closure& task,
117 base::TimeDelta delay) = 0; 117 base::TimeDelta delay) = 0;
118 118
119 // Submits a non-nestable task to delete the given object. Returns 119 // Submits a non-nestable task to delete the given object. Returns
120 // true if the object may be deleted at some point in the future, 120 // true if the object may be deleted at some point in the future,
121 // and false if the object definitely will not be deleted. 121 // and false if the object definitely will not be deleted.
122 template <class T> 122 template <class T>
123 bool DeleteSoon(const tracked_objects::Location& from_here, 123 bool DeleteSoon(const tracked_objects::Location& from_here,
124 const T* object) { 124 const T* object) {
125 return 125 return DeleteOrReleaseSoonInternal(from_here, &DeleteHelper<T>::DoDelete,
126 subtle::DeleteHelperInternal<T, bool>::DeleteViaSequencedTaskRunner( 126 object);
127 this, from_here, object);
128 } 127 }
129 128
130 // Submits a non-nestable task to release the given object. Returns 129 // Submits a non-nestable task to release the given object. Returns
131 // true if the object may be released at some point in the future, 130 // true if the object may be released at some point in the future,
132 // and false if the object definitely will not be released. 131 // and false if the object definitely will not be released.
133 template <class T> 132 template <class T>
134 bool ReleaseSoon(const tracked_objects::Location& from_here, 133 bool ReleaseSoon(const tracked_objects::Location& from_here,
135 T* object) { 134 const T* object) {
136 return 135 return DeleteOrReleaseSoonInternal(from_here, &ReleaseHelper<T>::DoRelease,
137 subtle::ReleaseHelperInternal<T, bool>::ReleaseViaSequencedTaskRunner( 136 object);
138 this, from_here, object);
139 } 137 }
140 138
141 protected: 139 protected:
142 ~SequencedTaskRunner() override {} 140 ~SequencedTaskRunner() override {}
143 141
144 private: 142 private:
145 template <class T, class R> friend class subtle::DeleteHelperInternal; 143 bool DeleteOrReleaseSoonInternal(const tracked_objects::Location& from_here,
146 template <class T, class R> friend class subtle::ReleaseHelperInternal; 144 void (*deleter)(const void*),
147 145 const void* object);
148 bool DeleteSoonInternal(const tracked_objects::Location& from_here,
149 void(*deleter)(const void*),
150 const void* object);
151
152 bool ReleaseSoonInternal(const tracked_objects::Location& from_here,
153 void(*releaser)(const void*),
154 const void* object);
155 }; 146 };
156 147
157 struct BASE_EXPORT OnTaskRunnerDeleter { 148 struct BASE_EXPORT OnTaskRunnerDeleter {
158 explicit OnTaskRunnerDeleter(scoped_refptr<SequencedTaskRunner> task_runner); 149 explicit OnTaskRunnerDeleter(scoped_refptr<SequencedTaskRunner> task_runner);
159 ~OnTaskRunnerDeleter(); 150 ~OnTaskRunnerDeleter();
160 151
161 OnTaskRunnerDeleter(OnTaskRunnerDeleter&&); 152 OnTaskRunnerDeleter(OnTaskRunnerDeleter&&);
162 OnTaskRunnerDeleter& operator=(OnTaskRunnerDeleter&&); 153 OnTaskRunnerDeleter& operator=(OnTaskRunnerDeleter&&);
163 154
164 template <typename T> 155 template <typename T>
165 void operator()(const T* ptr) { 156 void operator()(const T* ptr) {
166 if (ptr) 157 if (ptr)
167 task_runner_->DeleteSoon(FROM_HERE, ptr); 158 task_runner_->DeleteSoon(FROM_HERE, ptr);
168 } 159 }
169 160
170 scoped_refptr<SequencedTaskRunner> task_runner_; 161 scoped_refptr<SequencedTaskRunner> task_runner_;
171 }; 162 };
172 163
173 } // namespace base 164 } // namespace base
174 165
175 #endif // BASE_SEQUENCED_TASK_RUNNER_H_ 166 #endif // BASE_SEQUENCED_TASK_RUNNER_H_
OLDNEW
« no previous file with comments | « no previous file | base/sequenced_task_runner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698