callback_helper.h revision 5c02ac1a9c1b504631c0a3d2b6e737b5d738bae1
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 20namespace sync_file_system { 21namespace drive_backend { 22 23namespace internal { 24 25template <typename T> 26typename base::enable_if< 27 base::internal::IsMoveOnlyType<T>::value, 28 base::internal::PassedWrapper<T> >::type 29RebindForward(T& t) { 30 return base::Passed(&t); 31} 32 33template <typename T> 34typename base::enable_if< 35 !base::internal::IsMoveOnlyType<T>::value, 36 T&>::type 37RebindForward(T& t) { 38 return t; 39} 40 41template <typename> 42struct RelayToTaskRunnerHelper; 43 44template <> 45struct 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 53template <typename A1> 54struct 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 62template <typename A1, typename A2> 63struct 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 72template <typename A1, typename A2, typename A3> 73struct 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 83template <typename A1, typename A2, typename A3, typename A4> 84struct 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 94template <typename A1, typename A2, typename A3, typename A4, typename A5> 95struct 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 106template <typename A1, typename A2, typename A3, typename A4, typename A5, 107 typename A6> 108struct 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 119template <typename A1, typename A2, typename A3, typename A4, typename A5, 120 typename A6, typename A7> 121struct 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 135template <typename T> 136base::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 return base::Bind(&internal::RelayToTaskRunnerHelper<T>::Run, 142 make_scoped_refptr(task_runner), from_here, 143 callback); 144} 145 146template <typename T> 147base::Callback<T> RelayCallbackToCurrentThread( 148 const tracked_objects::Location& from_here, 149 const base::Callback<T>& callback) { 150 return RelayCallbackToTaskRunner( 151 base::ThreadTaskRunnerHandle::Get(), 152 from_here, callback); 153} 154 155} // namespace drive_backend 156} // namespace sync_file_system 157 158#endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_CALLBACK_HELPER_H_ 159