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

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

Powered by Google App Engine
This is Rietveld 408576698