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

Side by Side Diff: chrome/browser/sync_file_system/sync_file_system_test_util.cc

Issue 24140003: [SyncFS] Add generic result reciever (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: reupload Created 7 years, 3 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
« no previous file with comments | « chrome/browser/sync_file_system/sync_file_system_test_util.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "chrome/browser/sync_file_system/sync_file_system_test_util.h" 5 #include "chrome/browser/sync_file_system/sync_file_system_test_util.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop_proxy.h" 8 #include "base/message_loop/message_loop_proxy.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
11 #include "base/threading/thread.h" 11 #include "base/threading/thread.h"
12 #include "chrome/browser/google_apis/gdata_errorcode.h"
13 #include "chrome/browser/sync_file_system/drive_backend/metadata_database.h"
12 #include "chrome/browser/sync_file_system/sync_status_code.h" 14 #include "chrome/browser/sync_file_system/sync_status_code.h"
13 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
14 #include "content/public/test/test_utils.h" 16 #include "content/public/test/test_utils.h"
17 #include "testing/gtest/include/gtest/gtest.h"
15 18
16 using content::BrowserThread; 19 using content::BrowserThread;
17 20
18 namespace sync_file_system { 21 namespace sync_file_system {
19 22
23 namespace drive_backend {
24 class MetadataDatabase;
25 } // drive_backend
26
20 template <typename R> 27 template <typename R>
21 void AssignAndQuit(base::RunLoop* run_loop, R* result_out, R result) { 28 void AssignAndQuit(base::RunLoop* run_loop, R* result_out, R result) {
22 DCHECK(result_out); 29 DCHECK(result_out);
23 DCHECK(run_loop); 30 DCHECK(run_loop);
24 *result_out = result; 31 *result_out = result;
25 run_loop->Quit(); 32 run_loop->Quit();
26 } 33 }
27 34
28 template <typename R> base::Callback<void(R)> 35 template <typename R> base::Callback<void(R)>
29 AssignAndQuitCallback(base::RunLoop* run_loop, R* result) { 36 AssignAndQuitCallback(base::RunLoop* run_loop, R* result) {
30 return base::Bind(&AssignAndQuit<R>, run_loop, base::Unretained(result)); 37 return base::Bind(&AssignAndQuit<R>, run_loop, base::Unretained(result));
31 } 38 }
32 39
40 template <typename Arg>
41 void ReceiveResult1(bool* done, Arg* arg_out, Arg arg) {
42 EXPECT_FALSE(*done);
43 *done = true;
44 *arg_out = base::internal::CallbackForward(arg);
45 }
46
47 template <typename Arg1, typename Arg2>
48 void ReceiveResult2(bool* done,
49 Arg1* arg1_out,
50 Arg2* arg2_out,
51 Arg1 arg1,
52 Arg2 arg2) {
53 EXPECT_FALSE(*done);
54 *done = true;
55 *arg1_out = base::internal::CallbackForward(arg1);
56 *arg2_out = base::internal::CallbackForward(arg2);
57 }
58
59 template <typename Arg>
60 base::Callback<void(Arg)> CreateResultReceiver(Arg* arg_out) {
61 return base::Bind(&ReceiveResult1<Arg>,
62 base::Owned(new bool(false)), arg_out);
63 }
64
65 template <typename Arg1, typename Arg2>
66 base::Callback<void(Arg1, Arg2)> CreateResultReceiver(Arg1* arg1_out,
67 Arg2* arg2_out) {
68 return base::Bind(&ReceiveResult2<Arg1, Arg2>,
69 base::Owned(new bool(false)),
70 arg1_out, arg2_out);
71 }
72
33 // Instantiate versions we know callers will need. 73 // Instantiate versions we know callers will need.
34 template base::Callback<void(SyncStatusCode)> 74 template base::Callback<void(SyncStatusCode)>
35 AssignAndQuitCallback(base::RunLoop*, SyncStatusCode*); 75 AssignAndQuitCallback(base::RunLoop*, SyncStatusCode*);
36 76
77 #define INSTANTIATE_RECEIVER(type) \
78 template base::Callback<void(type)> CreateResultReceiver(type*);
79 INSTANTIATE_RECEIVER(SyncStatusCode);
80 INSTANTIATE_RECEIVER(google_apis::GDataErrorCode);
81 #undef INSTANTIATE_RECEIVER
82
83 #define INSTANTIATE_RECEIVER(type1, type2) \
84 template base::Callback<void(type1, scoped_ptr<type2>)> \
85 CreateResultReceiver(type1*, scoped_ptr<type2>*)
86 INSTANTIATE_RECEIVER(SyncStatusCode, drive_backend::MetadataDatabase);
87 #undef INSTANTIATE_RECEIVER
88
37 } // namespace sync_file_system 89 } // namespace sync_file_system
OLDNEW
« no previous file with comments | « chrome/browser/sync_file_system/sync_file_system_test_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698