Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / sync_file_system / drive_backend / callback_helper.h
1 // This file was GENERATED by command:
2 //     pump.py callback_helper.h.pump
3 // DO NOT EDIT BY HAND!!!
4
5
6 // Copyright 2014 The Chromium Authors. All rights reserved.
7 // Use of this source code is governed by a BSD-style license that can be
8 // found in the LICENSE file.
9
10 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_CALLBACK_HELPER_H_
11 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_CALLBACK_HELPER_H_
12
13 #include "base/bind.h"
14 #include "base/location.h"
15 #include "base/logging.h"
16 #include "base/thread_task_runner_handle.h"
17
18 // TODO(tzik): Merge this file to media/base/bind_to_current_loop.h.
19
20 namespace sync_file_system {
21 namespace drive_backend {
22
23 namespace internal {
24
25 template <typename T>
26 typename base::enable_if<
27     base::internal::IsMoveOnlyType<T>::value,
28     base::internal::PassedWrapper<T> >::type
29 RebindForward(T& t) {
30   return base::Passed(&t);
31 }
32
33 template <typename T>
34 typename base::enable_if<
35     !base::internal::IsMoveOnlyType<T>::value,
36     T&>::type
37 RebindForward(T& t) {
38   return t;
39 }
40
41 template <typename>
42 struct RelayToTaskRunnerHelper;
43
44 template <>
45 struct RelayToTaskRunnerHelper<void()> {
46   static void Run(base::TaskRunner* task_runner,
47                   const tracked_objects::Location& from_here,
48                   const base::Callback<void()>& callback) {
49     task_runner->PostTask(from_here, base::Bind(callback));
50   }
51 };
52
53 template <typename A1>
54 struct RelayToTaskRunnerHelper<void(A1)> {
55   static void Run(base::TaskRunner* task_runner,
56                   const tracked_objects::Location& from_here,
57                   const base::Callback<void(A1)>& callback, A1 a1) {
58     task_runner->PostTask(from_here, base::Bind(callback, RebindForward(a1)));
59   }
60 };
61
62 template <typename A1, typename A2>
63 struct RelayToTaskRunnerHelper<void(A1, A2)> {
64   static void Run(base::TaskRunner* task_runner,
65                   const tracked_objects::Location& from_here,
66                   const base::Callback<void(A1, A2)>& callback, A1 a1, A2 a2) {
67     task_runner->PostTask(from_here, base::Bind(callback, RebindForward(a1),
68         RebindForward(a2)));
69   }
70 };
71
72 template <typename A1, typename A2, typename A3>
73 struct RelayToTaskRunnerHelper<void(A1, A2, A3)> {
74   static void Run(base::TaskRunner* task_runner,
75                   const tracked_objects::Location& from_here,
76                   const base::Callback<void(A1, A2, A3)>& callback, A1 a1,
77                       A2 a2, A3 a3) {
78     task_runner->PostTask(from_here, base::Bind(callback, RebindForward(a1),
79         RebindForward(a2), RebindForward(a3)));
80   }
81 };
82
83 template <typename A1, typename A2, typename A3, typename A4>
84 struct RelayToTaskRunnerHelper<void(A1, A2, A3, A4)> {
85   static void Run(base::TaskRunner* task_runner,
86                   const tracked_objects::Location& from_here,
87                   const base::Callback<void(A1, A2, A3, A4)>& callback, A1 a1,
88                       A2 a2, A3 a3, A4 a4) {
89     task_runner->PostTask(from_here, base::Bind(callback, RebindForward(a1),
90         RebindForward(a2), RebindForward(a3), RebindForward(a4)));
91   }
92 };
93
94 template <typename A1, typename A2, typename A3, typename A4, typename A5>
95 struct RelayToTaskRunnerHelper<void(A1, A2, A3, A4, A5)> {
96   static void Run(base::TaskRunner* task_runner,
97                   const tracked_objects::Location& from_here,
98                   const base::Callback<void(A1, A2, A3, A4, A5)>& callback,
99                       A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) {
100     task_runner->PostTask(from_here, base::Bind(callback, RebindForward(a1),
101         RebindForward(a2), RebindForward(a3), RebindForward(a4),
102         RebindForward(a5)));
103   }
104 };
105
106 template <typename A1, typename A2, typename A3, typename A4, typename A5,
107     typename A6>
108 struct RelayToTaskRunnerHelper<void(A1, A2, A3, A4, A5, A6)> {
109   static void Run(base::TaskRunner* task_runner,
110                   const tracked_objects::Location& from_here,
111                   const base::Callback<void(A1, A2, A3, A4, A5, A6)>& callback,
112                       A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) {
113     task_runner->PostTask(from_here, base::Bind(callback, RebindForward(a1),
114         RebindForward(a2), RebindForward(a3), RebindForward(a4),
115         RebindForward(a5), RebindForward(a6)));
116   }
117 };
118
119 template <typename A1, typename A2, typename A3, typename A4, typename A5,
120     typename A6, typename A7>
121 struct RelayToTaskRunnerHelper<void(A1, A2, A3, A4, A5, A6, A7)> {
122   static void Run(base::TaskRunner* task_runner,
123                   const tracked_objects::Location& from_here,
124                   const base::Callback<void(A1, A2, A3, A4, A5, A6,
125                       A7)>& callback, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6,
126                       A7 a7) {
127     task_runner->PostTask(from_here, base::Bind(callback, RebindForward(a1),
128         RebindForward(a2), RebindForward(a3), RebindForward(a4),
129         RebindForward(a5), RebindForward(a6), RebindForward(a7)));
130   }
131 };
132
133 }  // namespace internal
134
135 template <typename T>
136 base::Callback<T> RelayCallbackToTaskRunner(
137     base::TaskRunner* task_runner,
138     const tracked_objects::Location& from_here,
139     const base::Callback<T>& callback) {
140   DCHECK(task_runner->RunsTasksOnCurrentThread());
141
142   if (callback.is_null())
143     return base::Callback<T>();
144
145   return base::Bind(&internal::RelayToTaskRunnerHelper<T>::Run,
146                     make_scoped_refptr(task_runner), from_here,
147                     callback);
148 }
149
150 template <typename T>
151 base::Callback<T> RelayCallbackToCurrentThread(
152     const tracked_objects::Location& from_here,
153     const base::Callback<T>& callback) {
154   return RelayCallbackToTaskRunner(
155       base::ThreadTaskRunnerHandle::Get(),
156       from_here, callback);
157 }
158
159 }  // namespace drive_backend
160 }  // namespace sync_file_system
161
162 #endif  // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_CALLBACK_HELPER_H_