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

Side by Side Diff: content/public/browser/browser_thread.h

Issue 2842493004: Add OnceCallback support to PostTaskAndReplyWithResult (Closed)
Patch Set: . 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 | « components/drive/drive_api_util.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 (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 CONTENT_PUBLIC_BROWSER_BROWSER_THREAD_H_ 5 #ifndef CONTENT_PUBLIC_BROWSER_BROWSER_THREAD_H_
6 #define CONTENT_PUBLIC_BROWSER_BROWSER_THREAD_H_ 6 #define CONTENT_PUBLIC_BROWSER_BROWSER_THREAD_H_
7 7
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 135
136 static bool PostTaskAndReply(ID identifier, 136 static bool PostTaskAndReply(ID identifier,
137 const tracked_objects::Location& from_here, 137 const tracked_objects::Location& from_here,
138 base::OnceClosure task, 138 base::OnceClosure task,
139 base::OnceClosure reply); 139 base::OnceClosure reply);
140 140
141 template <typename ReturnType, typename ReplyArgType> 141 template <typename ReturnType, typename ReplyArgType>
142 static bool PostTaskAndReplyWithResult( 142 static bool PostTaskAndReplyWithResult(
143 ID identifier, 143 ID identifier,
144 const tracked_objects::Location& from_here, 144 const tracked_objects::Location& from_here,
145 base::Callback<ReturnType()> task, 145 base::OnceCallback<ReturnType()> task,
146 base::Callback<void(ReplyArgType)> reply) { 146 base::OnceCallback<void(ReplyArgType)> reply) {
147 scoped_refptr<base::SingleThreadTaskRunner> task_runner = 147 scoped_refptr<base::SingleThreadTaskRunner> task_runner =
148 GetTaskRunnerForThread(identifier); 148 GetTaskRunnerForThread(identifier);
149 return base::PostTaskAndReplyWithResult(task_runner.get(), from_here, 149 return base::PostTaskAndReplyWithResult(task_runner.get(), from_here,
150 std::move(task), std::move(reply)); 150 std::move(task), std::move(reply));
151 } 151 }
152 152
153 // Callback version of PostTaskAndReplyWithResult above.
154 // Though RepeatingCallback is convertible to OnceCallback, we need this since
155 // we can not use template deduction and object conversion at once on the
156 // overload resolution.
157 // TODO(tzik): Update all callers of the Callback version to use OnceCallback.
kinuko 2017/05/01 04:48:47 nit: link to the issue?
tzik 2017/05/01 05:13:01 Done.
158 template <typename ReturnType, typename ReplyArgType>
159 static bool PostTaskAndReplyWithResult(
160 ID identifier,
161 const tracked_objects::Location& from_here,
162 base::Callback<ReturnType()> task,
163 base::Callback<void(ReplyArgType)> reply) {
164 return PostTaskAndReplyWithResult(
165 identifier, from_here,
166 static_cast<base::OnceCallback<ReturnType()>>(std::move(task)),
167 static_cast<base::OnceCallback<void(ReplyArgType)>>(std::move(reply)));
168 }
169
153 template <class T> 170 template <class T>
154 static bool DeleteSoon(ID identifier, 171 static bool DeleteSoon(ID identifier,
155 const tracked_objects::Location& from_here, 172 const tracked_objects::Location& from_here,
156 const T* object) { 173 const T* object) {
157 return GetTaskRunnerForThread(identifier)->DeleteSoon(from_here, object); 174 return GetTaskRunnerForThread(identifier)->DeleteSoon(from_here, object);
158 } 175 }
159 176
160 template <class T> 177 template <class T>
161 static bool ReleaseSoon(ID identifier, 178 static bool ReleaseSoon(ID identifier,
162 const tracked_objects::Location& from_here, 179 const tracked_objects::Location& from_here,
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 private: 339 private:
323 friend class BrowserThreadImpl; 340 friend class BrowserThreadImpl;
324 341
325 BrowserThread() {} 342 BrowserThread() {}
326 DISALLOW_COPY_AND_ASSIGN(BrowserThread); 343 DISALLOW_COPY_AND_ASSIGN(BrowserThread);
327 }; 344 };
328 345
329 } // namespace content 346 } // namespace content
330 347
331 #endif // CONTENT_PUBLIC_BROWSER_BROWSER_THREAD_H_ 348 #endif // CONTENT_PUBLIC_BROWSER_BROWSER_THREAD_H_
OLDNEW
« no previous file with comments | « components/drive/drive_api_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698