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

Side by Side Diff: chrome/browser/chromeos/gdata/task_util.h

Issue 10825459: gdata: Move task related functions like RunTaskOnUIThread from gdata_file_system.cc to task_util.cc (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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 // 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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_TASK_UTIL_H_
6 #define CHROME_BROWSER_CHROMEOS_GDATA_TASK_UTIL_H_
7
8 #include "base/bind.h"
9 #include "base/message_loop_proxy.h"
10
11 namespace gdata {
12
13 // Runs task on the thread to which |relay_proxy| belongs.
14 void RunTaskOnThread(scoped_refptr<base::MessageLoopProxy> relay_proxy,
15 const base::Closure& task);
16
17 // Runs task on UI thread.
18 void RunTaskOnUIThread(const base::Closure& task);
19
20 namespace internal {
21
22 // RelayCallback relays arguments for callback running on the given thread.
23 template<typename CallbackType>
24 struct RelayCallback;
25
26 // RelayCallback for callback with one argument.
27 template<typename T1>
28 struct RelayCallback<base::Callback<void(T1)> > {
29 static void Run(scoped_refptr<base::MessageLoopProxy> relay_proxy,
30 const base::Callback<void(T1)>& callback,
31 T1 arg1) {
32 if (callback.is_null())
33 return;
34 RunTaskOnThread(relay_proxy, base::Bind(callback, arg1));
35 }
36 };
37
38 // RelayCallback for callback with two arguments.
39 template<typename T1, typename T2>
40 struct RelayCallback<base::Callback<void(T1, T2)> > {
41 static void Run(scoped_refptr<base::MessageLoopProxy> relay_proxy,
42 const base::Callback<void(T1, T2)>& callback,
43 T1 arg1,
44 T2 arg2) {
45 if (callback.is_null())
46 return;
47 RunTaskOnThread(relay_proxy, base::Bind(callback, arg1, arg2));
48 }
49 };
50
51 // RelayCallback for callback with two arguments, the last one is scoped_ptr.
52 template<typename T1, typename T2>
53 struct RelayCallback<base::Callback<void(T1, scoped_ptr<T2>)> > {
54 static void Run(scoped_refptr<base::MessageLoopProxy> relay_proxy,
55 const base::Callback<void(T1, scoped_ptr<T2>)>& callback,
56 T1 arg1,
57 scoped_ptr<T2> arg2) {
58 if (callback.is_null())
59 return;
60 RunTaskOnThread(relay_proxy,
61 base::Bind(callback, arg1, base::Passed(&arg2)));
62 }
63 };
64
65 // RelayCallback for callback with three arguments.
66 template<typename T1, typename T2, typename T3>
67 struct RelayCallback<base::Callback<void(T1, T2, T3)> > {
68 static void Run(scoped_refptr<base::MessageLoopProxy> relay_proxy,
69 const base::Callback<void(T1, T2, T3)>& callback,
70 T1 arg1,
71 T2 arg2,
72 T3 arg3) {
73 if (callback.is_null())
74 return;
75 RunTaskOnThread(relay_proxy, base::Bind(callback, arg1, arg2, arg3));
76 }
77 };
78
79 // RelayCallback for callback with three arguments, the last one is scoped_ptr.
80 template<typename T1, typename T2, typename T3>
81 struct RelayCallback<base::Callback<void(T1, T2, scoped_ptr<T3>)> > {
82 static void Run(scoped_refptr<base::MessageLoopProxy> relay_proxy,
83 const base::Callback<void(T1, T2, scoped_ptr<T3>)>& callback,
84 T1 arg1,
85 T2 arg2,
86 scoped_ptr<T3> arg3) {
87 if (callback.is_null())
88 return;
89 RunTaskOnThread(relay_proxy,
90 base::Bind(callback, arg1, arg2, base::Passed(&arg3)));
91 }
92 };
93
94 // RelayCallback for callback with four arguments.
95 template<typename T1, typename T2, typename T3, typename T4>
96 struct RelayCallback<base::Callback<void(T1, T2, T3, T4)> > {
97 static void Run(scoped_refptr<base::MessageLoopProxy> relay_proxy,
98 const base::Callback<void(T1, T2, T3, T4)>& callback,
99 T1 arg1,
100 T2 arg2,
101 T3 arg3,
102 T4 arg4) {
103 if (callback.is_null())
104 return;
105 RunTaskOnThread(relay_proxy, base::Bind(callback, arg1, arg2, arg3, arg4));
106 }
107 };
108
109 } // namespace internal
110
111 // Returns callback which runs the given |callback| on the current thread.
112 template<typename CallbackType>
113 CallbackType CreateRelayCallback(const CallbackType& callback) {
114 return base::Bind(&internal::RelayCallback<CallbackType>::Run,
115 base::MessageLoopProxy::current(),
116 callback);
117 }
118
119 } // namespace gdata
120
121 #endif // CHROME_BROWSER_CHROMEOS_GDATA_TASK_UTIL_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_file_system.cc ('k') | chrome/browser/chromeos/gdata/task_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698