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

Side by Side Diff: chrome/browser/media_galleries/fileapi/async_file_util_test_helper.cc

Issue 15653004: Picasa import: Make NativeMediaFileUtil an AsyncFileUtil (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Restore a test Created 7 years, 6 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
OLDNEW
(Empty)
1 // Copyright 2013 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 #include "chrome/browser/media_galleries/fileapi/async_file_util_test_helper.h"
6
7 #include "base/bind.h"
8 #include "base/files/file_path.h"
9 #include "base/platform_file.h"
10 #include "base/run_loop.h"
11 #include "webkit/common/blob/scoped_file.h"
12 #include "webkit/common/blob/shareable_file_reference.h"
13
14 using fileapi::AsyncFileUtil;
15 using fileapi::FileSystemOperationContext;
16 using fileapi::FileSystemURL;
17
18 namespace chrome {
19
20 namespace {
21
22 // Needed as base::Bind only supports functions of up to arity 7.
23 struct CreateSnapshotResults {
24 scoped_refptr<webkit_blob::ShareableFileReference>* file_ref;
25 base::PlatformFileError* error;
26 base::PlatformFileInfo* file_info;
27 base::FilePath* platform_path;
28 };
29
30 void CreateOrOpenTestCallback(
31 base::RunLoop* run_loop,
32 base::PlatformFileError* error_result,
33 base::PlatformFile* platform_file_result,
34 bool* created_result,
35 base::PlatformFileError error,
36 base::PassPlatformFile pass_platform_file,
37 bool created) {
38 DCHECK(error_result);
39 DCHECK(platform_file_result);
40 DCHECK(created_result);
41 *error_result = error;
42 *platform_file_result = pass_platform_file.ReleaseValue();
43 *created_result = created;
44 run_loop->Quit();
45 }
46
47 void CreateSnapshotTestCallback(
48 base::RunLoop* run_loop,
49 CreateSnapshotResults* results,
50 base::PlatformFileError error,
51 const base::PlatformFileInfo& file_info,
52 const base::FilePath& platform_path,
53 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) {
54 DCHECK(results->file_ref);
55 DCHECK(results->error);
56 DCHECK(results->file_info);
57 DCHECK(results->platform_path);
58 *(results->error) = error;
59 *(results->file_info) = file_info;
60 *(results->platform_path) = platform_path;
61 *(results->file_ref) = file_ref;
62 run_loop->Quit();
63 }
64
65 void EnsureFileExistsTestCallback(
66 base::RunLoop* run_loop,
67 base::PlatformFileError* error_result,
68 bool* created_result,
69 base::PlatformFileError error,
70 bool created) {
71 DCHECK(error_result);
72 DCHECK(created_result);
73 *error_result = error;
74 *created_result = created;
75 run_loop->Quit();
76 }
77
78 void GetFileInfoTestCallback(
79 base::RunLoop* run_loop,
80 base::PlatformFileError* error_result,
81 base::PlatformFileInfo* file_info_result,
82 base::FilePath* platform_path_result,
83 base::PlatformFileError error,
84 const base::PlatformFileInfo& file_info,
85 const base::FilePath& platform_path) {
86 DCHECK(error_result);
87 DCHECK(file_info_result);
88 DCHECK(platform_path_result);
89 *error_result = error;
90 *file_info_result = file_info;
91 *platform_path_result = platform_path;
92 run_loop->Quit();
93 }
94
95 void ReadDirectoryTestCallback(
96 base::RunLoop* run_loop,
97 base::PlatformFileError* error_result,
98 AsyncFileUtil::EntryList* file_list_result,
99 bool* has_more_result,
100 base::PlatformFileError error,
101 const AsyncFileUtil::EntryList& file_list,
102 bool has_more) {
103 DCHECK(error_result);
104 DCHECK(file_list_result);
105 DCHECK(has_more_result);
106 *error_result = error;
107 *file_list_result = file_list;
108 *has_more_result = has_more;
109 run_loop->Quit();
110 }
111
112 void StatusTestCallback(
113 base::RunLoop* run_loop,
114 base::PlatformFileError* error_result,
115 base::PlatformFileError error) {
116 DCHECK(error_result);
117 *error_result = error;
118 run_loop->Quit();
119 }
120
121 } // namespace
122
123 AsyncFileUtilTestHelper::AsyncFileUtilTestHelper(AsyncFileUtil* async_file_util)
124 : async_file_util_(async_file_util) {
125 }
126
127 AsyncFileUtilTestHelper::~AsyncFileUtilTestHelper() {}
128
129 base::PlatformFileError AsyncFileUtilTestHelper::CreateOrOpen(
130 FileSystemOperationContext* context,
131 const FileSystemURL& url,
132 int file_flags,
133 base::PlatformFile* file_handle,
134 bool* created) {
135 DCHECK(context);
136 base::PlatformFileError result;
137 base::RunLoop run_loop;
138 async_file_util_->CreateOrOpen(
139 context,
140 url,
141 file_flags,
142 base::Bind(
143 &CreateOrOpenTestCallback,
144 &run_loop,
145 &result,
146 file_handle,
147 created));
148 run_loop.Run();
149 return result;
150 }
151
152 base::PlatformFileError AsyncFileUtilTestHelper::EnsureFileExists(
153 FileSystemOperationContext* context,
154 const FileSystemURL& url,
155 bool* created) {
156 DCHECK(context);
157 base::PlatformFileError result;
158 base::RunLoop run_loop;
159 async_file_util_->EnsureFileExists(
160 context,
161 url,
162 base::Bind(&EnsureFileExistsTestCallback, &run_loop, &result, created));
163 run_loop.Run();
164 return result;
165 }
166
167 base::PlatformFileError AsyncFileUtilTestHelper::CreateDirectory(
168 FileSystemOperationContext* context,
169 const FileSystemURL& url,
170 bool exclusive,
171 bool recursive) {
172 DCHECK(context);
173 base::PlatformFileError result;
174 base::RunLoop run_loop;
175 async_file_util_->CreateDirectory(context, url, exclusive, recursive,
176 base::Bind(&StatusTestCallback,
177 &run_loop, &result));
178 run_loop.Run();
179 return result;
180 }
181
182 base::PlatformFileError AsyncFileUtilTestHelper::GetFileInfo(
183 FileSystemOperationContext* context,
184 const FileSystemURL& url,
185 base::PlatformFileInfo* file_info,
186 base::FilePath* platform_path) {
187 DCHECK(context);
188 base::PlatformFileError result;
189 base::RunLoop run_loop;
190 async_file_util_->GetFileInfo(
191 context,
192 url,
193 base::Bind(&GetFileInfoTestCallback, &run_loop, &result, file_info,
194 platform_path));
195 run_loop.Run();
196 return result;
197 }
198
199 base::PlatformFileError AsyncFileUtilTestHelper::Touch(
200 FileSystemOperationContext* context,
201 const FileSystemURL& url,
202 const base::Time& last_access_time,
203 const base::Time& last_modified_time) {
204 DCHECK(context);
205 base::PlatformFileError result;
206 base::RunLoop run_loop;
207 async_file_util_->Touch(context, url, last_access_time, last_modified_time,
208 base::Bind(&StatusTestCallback, &run_loop, &result));
209 run_loop.Run();
210 return result;
211 }
212
213 base::PlatformFileError AsyncFileUtilTestHelper::Truncate(
214 FileSystemOperationContext* context,
215 const FileSystemURL& url,
216 int64 length) {
217 DCHECK(context);
218 base::PlatformFileError result;
219 base::RunLoop run_loop;
220 async_file_util_->Truncate(context, url, length,
221 base::Bind(&StatusTestCallback, &run_loop,
222 &result));
223 run_loop.Run();
224 return result;
225 }
226
227 base::PlatformFileError AsyncFileUtilTestHelper::CopyOrMoveFile(
228 FileSystemOperationContext* context,
229 const FileSystemURL& src_url,
230 const FileSystemURL& dest_url,
231 bool copy) {
232 DCHECK(context);
233 base::PlatformFileError result;
234 base::RunLoop run_loop;
235 if (copy) {
236 async_file_util_->CopyFileLocal(context, src_url, dest_url,
237 base::Bind(&StatusTestCallback, &run_loop,
238 &result));
239 } else {
240 async_file_util_->MoveFileLocal(context, src_url, dest_url,
241 base::Bind(&StatusTestCallback, &run_loop,
242 &result));
243 }
244 run_loop.Run();
245 return result;
246 }
247
248 base::PlatformFileError AsyncFileUtilTestHelper::CopyInForeignFile(
249 FileSystemOperationContext* context,
250 const base::FilePath& src_file_path,
251 const FileSystemURL& dest_url) {
252 DCHECK(context);
253 base::PlatformFileError result;
254 base::RunLoop run_loop;
255 async_file_util_->CopyInForeignFile(context, src_file_path, dest_url,
256 base::Bind(&StatusTestCallback, &run_loop,
257 &result));
258 run_loop.Run();
259 return result;
260 }
261
262 base::PlatformFileError AsyncFileUtilTestHelper::ReadDirectorySync(
263 FileSystemOperationContext* context,
264 const FileSystemURL& url,
265 AsyncFileUtil::EntryList* file_list,
266 bool* has_more) {
267 DCHECK(context);
268 base::PlatformFileError result;
269 base::RunLoop run_loop;
270 async_file_util_->ReadDirectory(
271 context,
272 url,
273 base::Bind(&ReadDirectoryTestCallback, &run_loop, &result, file_list,
274 has_more));
275 run_loop.Run();
276 return result;
277 }
278
279 scoped_refptr<webkit_blob::ShareableFileReference>
280 AsyncFileUtilTestHelper::CreateSnapshotFileSharable(
281 FileSystemOperationContext* context,
282 const FileSystemURL& url,
283 base::PlatformFileError* error,
284 base::PlatformFileInfo* file_info,
285 base::FilePath* platform_path) {
286 DCHECK(context);
287 scoped_refptr<webkit_blob::ShareableFileReference> file_ref_result;
288 CreateSnapshotResults results =
289 { &file_ref_result, error, file_info, platform_path };
290 base::RunLoop run_loop;
291 async_file_util_->CreateSnapshotFile(
292 context,
293 url,
294 base::Bind(&CreateSnapshotTestCallback, &run_loop, &results));
295 run_loop.Run();
296 return file_ref_result;
297 }
298
299 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698