OLD | NEW |
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 GOOGLE_APIS_DRIVE_TASK_UTIL_H_ | 5 #ifndef GOOGLE_APIS_DRIVE_TASK_UTIL_H_ |
6 #define GOOGLE_APIS_DRIVE_TASK_UTIL_H_ | 6 #define GOOGLE_APIS_DRIVE_TASK_UTIL_H_ |
7 | 7 |
| 8 #include <memory> |
| 9 |
8 #include "base/bind.h" | 10 #include "base/bind.h" |
9 #include "base/memory/scoped_ptr.h" | |
10 #include "base/thread_task_runner_handle.h" | 11 #include "base/thread_task_runner_handle.h" |
11 | 12 |
12 namespace google_apis { | 13 namespace google_apis { |
13 | 14 |
14 // Runs the task with the task runner. | 15 // Runs the task with the task runner. |
15 void RunTaskWithTaskRunner(scoped_refptr<base::TaskRunner> task_runner, | 16 void RunTaskWithTaskRunner(scoped_refptr<base::TaskRunner> task_runner, |
16 const base::Closure& task); | 17 const base::Closure& task); |
17 | 18 |
18 namespace internal { | 19 namespace internal { |
19 | 20 |
(...skipping 26 matching lines...) Expand all Loading... |
46 struct ComposedCallback<void(T1, T2)> { | 47 struct ComposedCallback<void(T1, T2)> { |
47 static void Run( | 48 static void Run( |
48 const base::Callback<void(const base::Closure&)>& runner, | 49 const base::Callback<void(const base::Closure&)>& runner, |
49 const base::Callback<void(T1, T2)>& callback, | 50 const base::Callback<void(T1, T2)>& callback, |
50 T1 arg1, T2 arg2) { | 51 T1 arg1, T2 arg2) { |
51 runner.Run(base::Bind(callback, arg1, arg2)); | 52 runner.Run(base::Bind(callback, arg1, arg2)); |
52 } | 53 } |
53 }; | 54 }; |
54 | 55 |
55 // ComposedCallback with two arguments, and the last one is scoped_ptr. | 56 // ComposedCallback with two arguments, and the last one is scoped_ptr. |
56 template<typename T1, typename T2, typename D2> | 57 template <typename T1, typename T2, typename D2> |
57 struct ComposedCallback<void(T1, scoped_ptr<T2, D2>)> { | 58 struct ComposedCallback<void(T1, std::unique_ptr<T2, D2>)> { |
58 static void Run( | 59 static void Run( |
59 const base::Callback<void(const base::Closure&)>& runner, | 60 const base::Callback<void(const base::Closure&)>& runner, |
60 const base::Callback<void(T1, scoped_ptr<T2, D2>)>& callback, | 61 const base::Callback<void(T1, std::unique_ptr<T2, D2>)>& callback, |
61 T1 arg1, scoped_ptr<T2, D2> arg2) { | 62 T1 arg1, |
| 63 std::unique_ptr<T2, D2> arg2) { |
62 runner.Run(base::Bind(callback, arg1, base::Passed(&arg2))); | 64 runner.Run(base::Bind(callback, arg1, base::Passed(&arg2))); |
63 } | 65 } |
64 }; | 66 }; |
65 | 67 |
66 // ComposedCallback with three arguments. | 68 // ComposedCallback with three arguments. |
67 template<typename T1, typename T2, typename T3> | 69 template<typename T1, typename T2, typename T3> |
68 struct ComposedCallback<void(T1, T2, T3)> { | 70 struct ComposedCallback<void(T1, T2, T3)> { |
69 static void Run( | 71 static void Run( |
70 const base::Callback<void(const base::Closure&)>& runner, | 72 const base::Callback<void(const base::Closure&)>& runner, |
71 const base::Callback<void(T1, T2, T3)>& callback, | 73 const base::Callback<void(T1, T2, T3)>& callback, |
72 T1 arg1, T2 arg2, T3 arg3) { | 74 T1 arg1, T2 arg2, T3 arg3) { |
73 runner.Run(base::Bind(callback, arg1, arg2, arg3)); | 75 runner.Run(base::Bind(callback, arg1, arg2, arg3)); |
74 } | 76 } |
75 }; | 77 }; |
76 | 78 |
77 // ComposedCallback with three arguments, and the last one is scoped_ptr. | 79 // ComposedCallback with three arguments, and the last one is scoped_ptr. |
78 template<typename T1, typename T2, typename T3, typename D3> | 80 template <typename T1, typename T2, typename T3, typename D3> |
79 struct ComposedCallback<void(T1, T2, scoped_ptr<T3, D3>)> { | 81 struct ComposedCallback<void(T1, T2, std::unique_ptr<T3, D3>)> { |
80 static void Run( | 82 static void Run( |
81 const base::Callback<void(const base::Closure&)>& runner, | 83 const base::Callback<void(const base::Closure&)>& runner, |
82 const base::Callback<void(T1, T2, scoped_ptr<T3, D3>)>& callback, | 84 const base::Callback<void(T1, T2, std::unique_ptr<T3, D3>)>& callback, |
83 T1 arg1, T2 arg2, scoped_ptr<T3, D3> arg3) { | 85 T1 arg1, |
| 86 T2 arg2, |
| 87 std::unique_ptr<T3, D3> arg3) { |
84 runner.Run(base::Bind(callback, arg1, arg2, base::Passed(&arg3))); | 88 runner.Run(base::Bind(callback, arg1, arg2, base::Passed(&arg3))); |
85 } | 89 } |
86 }; | 90 }; |
87 | 91 |
88 // ComposedCallback with four arguments. | 92 // ComposedCallback with four arguments. |
89 template<typename T1, typename T2, typename T3, typename T4> | 93 template<typename T1, typename T2, typename T3, typename T4> |
90 struct ComposedCallback<void(T1, T2, T3, T4)> { | 94 struct ComposedCallback<void(T1, T2, T3, T4)> { |
91 static void Run( | 95 static void Run( |
92 const base::Callback<void(const base::Closure&)>& runner, | 96 const base::Callback<void(const base::Closure&)>& runner, |
93 const base::Callback<void(T1, T2, T3, T4)>& callback, | 97 const base::Callback<void(T1, T2, T3, T4)>& callback, |
(...skipping 23 matching lines...) Expand all Loading... |
117 template<typename CallbackType> | 121 template<typename CallbackType> |
118 CallbackType CreateRelayCallback(const CallbackType& callback) { | 122 CallbackType CreateRelayCallback(const CallbackType& callback) { |
119 return CreateComposedCallback( | 123 return CreateComposedCallback( |
120 base::Bind(&RunTaskWithTaskRunner, base::ThreadTaskRunnerHandle::Get()), | 124 base::Bind(&RunTaskWithTaskRunner, base::ThreadTaskRunnerHandle::Get()), |
121 callback); | 125 callback); |
122 } | 126 } |
123 | 127 |
124 } // namespace google_apis | 128 } // namespace google_apis |
125 | 129 |
126 #endif // GOOGLE_APIS_DRIVE_TASK_UTIL_H_ | 130 #endif // GOOGLE_APIS_DRIVE_TASK_UTIL_H_ |
OLD | NEW |