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

Side by Side Diff: chrome/browser/sync_file_system/drive_backend/callback_helper.h.pump

Issue 259503004: [SyncFS] Refine callback helpers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 8 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 $$ This is a pump file for generating file templates. Pump is a python
2 $$ script that is part of the Google Test suite of utilities. Description
3 $$ can be found here:
4 $$
5 $$ http://code.google.com/p/googletest/wiki/PumpManual
6 $$
7 $$ See comment for MAX_ARITY in base/bind.h.pump.
8 $var MAX_ARITY = 7
9
10 // Copyright 2014 The Chromium Authors. All rights reserved.
11 // Use of this source code is governed by a BSD-style license that can be
12 // found in the LICENSE file.
13
14 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_CALLBACK_HELPER_H_
15 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_CALLBACK_HELPER_H_
16
17 #include "base/bind.h"
18 #include "base/location.h"
19 #include "base/logging.h"
20 #include "base/thread_task_runner_handle.h"
21
22 // TODO(tzik): Merge this file to media/base/bind_to_current_loop.h.
23
24 namespace sync_file_system {
25 namespace drive_backend {
26
27 namespace internal {
28
29 template <typename T>
30 typename base::enable_if<
31 base::internal::IsMoveOnlyType<T>::value,
32 base::internal::PassedWrapper<T> >::type
33 RebindForward(T& t) {
34 return base::Passed(&t);
35 }
36
37 template <typename T>
38 typename base::enable_if<
39 !base::internal::IsMoveOnlyType<T>::value,
40 T&>::type
41 RebindForward(T& t) {
42 return t;
43 }
44
45 template <typename>
46 struct RelayToTaskRunnerHelper;
47
48 $range ARITY 0..MAX_ARITY
49 $for ARITY [[
50 $range ARG 1..ARITY
51
52 template <$for ARG , [[typename A$(ARG)]]>
53 struct RelayToTaskRunnerHelper<void($for ARG , [[A$(ARG)]])> {
54 static void Run(base::TaskRunner* task_runner,
55 const tracked_objects::Location& from_here,
56 const base::Callback<void($for ARG , [[A$(ARG)]])>& callback
57 $if ARITY != 0 [[, ]]
58 $for ARG , [[A$(ARG) a$(ARG)]]
59 ) {
60 task_runner->PostTask(from_here, base::Bind(callback
61 $if ARITY != 0 [[, ]]
62 $for ARG , [[RebindForward(a$(ARG))]]));
63 }
64 };
65
66 ]] $$ for ARITY
67
68 } // namespace internal
69
70 template <typename T>
71 base::Callback<T> RelayCallbackToTaskRunner(
72 base::TaskRunner* task_runner,
73 const tracked_objects::Location& from_here,
74 const base::Callback<T>& callback) {
75 DCHECK(task_runner->RunsTasksOnCurrentThread());
76 return base::Bind(&internal::RelayToTaskRunnerHelper<T>::Run,
77 make_scoped_refptr(task_runner), from_here,
78 callback);
79 }
80
81 template <typename T>
82 base::Callback<T> RelayCallbackToCurrentThread(
83 const tracked_objects::Location& from_here,
84 const base::Callback<T>& callback) {
85 return RelayCallbackToTaskRunner(
86 base::ThreadTaskRunnerHandle::Get(),
87 from_here, callback);
88 }
89
90 } // namespace drive_backend
91 } // namespace sync_file_system
92
93 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_CALLBACK_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698