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

Side by Side Diff: webkit/fileapi/file_system_file_util_proxy.cc

Issue 8424007: Bind: Merge FileUtilProxy and FileSystemFileUtilProxy: Delete/Touch/Truncate/Copy/Move (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased2 Created 9 years, 1 month 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
« no previous file with comments | « webkit/fileapi/file_system_file_util_proxy.h ('k') | webkit/fileapi/file_system_operation.h » ('j') | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "webkit/fileapi/file_system_file_util_proxy.h" 5 #include "webkit/fileapi/file_system_file_util_proxy.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop_proxy.h" 8 #include "base/message_loop_proxy.h"
9 #include "webkit/fileapi/file_system_context.h" 9 #include "webkit/fileapi/file_system_context.h"
10 #include "webkit/fileapi/file_system_file_util.h" 10 #include "webkit/fileapi/file_system_file_util.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 origin_message_loop_proxy_->PostTask( 64 origin_message_loop_proxy_->PostTask(
65 FROM_HERE, base::Bind(&MessageLoopRelay::RunCallback, this)); 65 FROM_HERE, base::Bind(&MessageLoopRelay::RunCallback, this));
66 } 66 }
67 67
68 scoped_refptr<base::MessageLoopProxy> origin_message_loop_proxy_; 68 scoped_refptr<base::MessageLoopProxy> origin_message_loop_proxy_;
69 base::PlatformFileError error_code_; 69 base::PlatformFileError error_code_;
70 fileapi::FileSystemOperationContext context_; 70 fileapi::FileSystemOperationContext context_;
71 fileapi::FileSystemFileUtil* file_util_; 71 fileapi::FileSystemFileUtil* file_util_;
72 }; 72 };
73 73
74 class RelayCreateOrOpen : public MessageLoopRelay {
75 public:
76 RelayCreateOrOpen(
77 const fileapi::FileSystemOperationContext& context,
78 scoped_refptr<base::MessageLoopProxy> message_loop_proxy,
79 const FilePath& file_path,
80 int file_flags,
81 const fileapi::FileSystemFileUtilProxy::CreateOrOpenCallback& callback)
82 : MessageLoopRelay(context),
83 message_loop_proxy_(message_loop_proxy),
84 file_path_(file_path),
85 file_flags_(file_flags),
86 callback_(callback),
87 file_handle_(base::kInvalidPlatformFileValue),
88 created_(false) {
89 DCHECK_EQ(false, callback.is_null());
90 }
91
92 protected:
93 virtual ~RelayCreateOrOpen() {
94 if (file_handle_ != base::kInvalidPlatformFileValue)
95 fileapi::FileSystemFileUtilProxy::Close(
96 *context(), message_loop_proxy_, file_handle_,
97 fileapi::FileSystemFileUtilProxy::StatusCallback());
98 }
99
100 virtual void RunWork() {
101 set_error_code(file_util()->CreateOrOpen(
102 context(), file_path_, file_flags_, &file_handle_, &created_));
103 }
104
105 virtual void RunCallback() {
106 callback_.Run(error_code(), base::PassPlatformFile(&file_handle_),
107 created_);
108 }
109
110 private:
111 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
112 FilePath file_path_;
113 int file_flags_;
114 fileapi::FileSystemFileUtilProxy::CreateOrOpenCallback callback_;
115 base::PlatformFile file_handle_;
116 bool created_;
117 };
118
119 class RelayWithStatusCallback : public MessageLoopRelay {
120 public:
121 RelayWithStatusCallback(
122 const fileapi::FileSystemOperationContext& context,
123 const fileapi::FileSystemFileUtilProxy::StatusCallback& callback)
124 : MessageLoopRelay(context),
125 callback_(callback) {
126 // It is OK for callback to be NULL.
127 }
128
129 protected:
130 virtual void RunCallback() {
131 // The caller may not have been interested in the result.
132 if (!callback_.is_null())
133 callback_.Run(error_code());
134 }
135
136 private:
137 fileapi::FileSystemFileUtilProxy::StatusCallback callback_;
138 };
139
140 class RelayClose : public RelayWithStatusCallback {
141 public:
142 RelayClose(const fileapi::FileSystemOperationContext& context,
143 base::PlatformFile file_handle,
144 const fileapi::FileSystemFileUtilProxy::StatusCallback& callback)
145 : RelayWithStatusCallback(context, callback),
146 file_handle_(file_handle) {
147 }
148
149 protected:
150 virtual void RunWork() {
151 set_error_code(file_util()->Close(context(), file_handle_));
152 }
153
154 private:
155 base::PlatformFile file_handle_;
156 };
157
158 class RelayEnsureFileExists : public MessageLoopRelay { 74 class RelayEnsureFileExists : public MessageLoopRelay {
159 public: 75 public:
160 RelayEnsureFileExists( 76 RelayEnsureFileExists(
161 const fileapi::FileSystemOperationContext& context, 77 const fileapi::FileSystemOperationContext& context,
162 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, 78 scoped_refptr<base::MessageLoopProxy> message_loop_proxy,
163 const FilePath& file_path, 79 const FilePath& file_path,
164 const fileapi::FileSystemFileUtilProxy::EnsureFileExistsCallback& 80 const fileapi::FileSystemFileUtilProxy::EnsureFileExistsCallback&
165 callback) 81 callback)
166 : MessageLoopRelay(context), 82 : MessageLoopRelay(context),
167 message_loop_proxy_(message_loop_proxy), 83 message_loop_proxy_(message_loop_proxy),
(...skipping 14 matching lines...) Expand all
182 } 98 }
183 99
184 private: 100 private:
185 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; 101 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
186 FilePath file_path_; 102 FilePath file_path_;
187 fileapi::FileSystemFileUtilProxy::EnsureFileExistsCallback callback_; 103 fileapi::FileSystemFileUtilProxy::EnsureFileExistsCallback callback_;
188 bool created_; 104 bool created_;
189 }; 105 };
190 106
191 107
192 class RelayGetLocalPath : public MessageLoopRelay {
193 public:
194 RelayGetLocalPath(
195 const fileapi::FileSystemOperationContext& context,
196 const FilePath& virtual_path,
197 fileapi::FileSystemFileUtilProxy::GetLocalPathCallback* callback)
198 : MessageLoopRelay(context),
199 callback_(callback),
200 virtual_path_(virtual_path) {
201 DCHECK(callback);
202 }
203
204 protected:
205 virtual void RunWork() {
206 set_error_code(file_util()->GetLocalFilePath(
207 context(), virtual_path_, &local_path_));
208 }
209
210 virtual void RunCallback() {
211 callback_->Run(error_code(), local_path_);
212 delete callback_;
213 }
214
215 private:
216 fileapi::FileSystemFileUtilProxy::GetLocalPathCallback* callback_;
217 FilePath virtual_path_;
218 FilePath local_path_;
219 };
220
221 class RelayGetFileInfo : public MessageLoopRelay { 108 class RelayGetFileInfo : public MessageLoopRelay {
222 public: 109 public:
223 RelayGetFileInfo( 110 RelayGetFileInfo(
224 const fileapi::FileSystemOperationContext& context, 111 const fileapi::FileSystemOperationContext& context,
225 const FilePath& file_path, 112 const FilePath& file_path,
226 const fileapi::FileSystemFileUtilProxy::GetFileInfoCallback& callback) 113 const fileapi::FileSystemFileUtilProxy::GetFileInfoCallback& callback)
227 : MessageLoopRelay(context), 114 : MessageLoopRelay(context),
228 callback_(callback), 115 callback_(callback),
229 file_path_(file_path) { 116 file_path_(file_path) {
230 DCHECK_EQ(false, callback.is_null()); 117 DCHECK_EQ(false, callback.is_null());
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 virtual void RunCallback() { 155 virtual void RunCallback() {
269 callback_.Run(error_code(), entries_); 156 callback_.Run(error_code(), entries_);
270 } 157 }
271 158
272 private: 159 private:
273 fileapi::FileSystemFileUtilProxy::ReadDirectoryCallback callback_; 160 fileapi::FileSystemFileUtilProxy::ReadDirectoryCallback callback_;
274 FilePath file_path_; 161 FilePath file_path_;
275 std::vector<base::FileUtilProxy::Entry> entries_; 162 std::vector<base::FileUtilProxy::Entry> entries_;
276 }; 163 };
277 164
278 class RelayCreateDirectory : public RelayWithStatusCallback {
279 public:
280 RelayCreateDirectory(
281 const fileapi::FileSystemOperationContext& context,
282 const FilePath& file_path,
283 bool exclusive,
284 bool recursive,
285 const fileapi::FileSystemFileUtilProxy::StatusCallback& callback)
286 : RelayWithStatusCallback(context, callback),
287 file_path_(file_path),
288 exclusive_(exclusive),
289 recursive_(recursive) {
290 }
291
292 protected:
293 virtual void RunWork() {
294 set_error_code(file_util()->CreateDirectory(
295 context(), file_path_, exclusive_, recursive_));
296 }
297
298 private:
299 FilePath file_path_;
300 bool exclusive_;
301 bool recursive_;
302 };
303
304 class RelayCopy : public RelayWithStatusCallback {
305 public:
306 RelayCopy(const fileapi::FileSystemOperationContext& context,
307 const FilePath& src_file_path,
308 const FilePath& dest_file_path,
309 const fileapi::FileSystemFileUtilProxy::StatusCallback& callback)
310 : RelayWithStatusCallback(context, callback),
311 src_file_path_(src_file_path),
312 dest_file_path_(dest_file_path) {
313 }
314
315 protected:
316 virtual void RunWork() {
317 set_error_code(file_util()->Copy(
318 context(), src_file_path_, dest_file_path_));
319 }
320
321 private:
322 FilePath src_file_path_;
323 FilePath dest_file_path_;
324 };
325
326 class RelayMove : public RelayWithStatusCallback {
327 public:
328 RelayMove(const fileapi::FileSystemOperationContext& context,
329 const FilePath& src_file_path,
330 const FilePath& dest_file_path,
331 const fileapi::FileSystemFileUtilProxy::StatusCallback& callback)
332 : RelayWithStatusCallback(context, callback),
333 src_file_path_(src_file_path),
334 dest_file_path_(dest_file_path) {
335 }
336
337 protected:
338 virtual void RunWork() {
339 set_error_code(file_util()->Move(
340 context(), src_file_path_, dest_file_path_));
341 }
342
343 private:
344 FilePath src_file_path_;
345 FilePath dest_file_path_;
346 };
347
348 class RelayDelete : public RelayWithStatusCallback {
349 public:
350 RelayDelete(const fileapi::FileSystemOperationContext& context,
351 const FilePath& file_path,
352 bool recursive,
353 const fileapi::FileSystemFileUtilProxy::StatusCallback& callback)
354 : RelayWithStatusCallback(context, callback),
355 file_path_(file_path),
356 recursive_(recursive) {
357 }
358
359 protected:
360 virtual void RunWork() {
361 set_error_code(file_util()->Delete(context(), file_path_, recursive_));
362 }
363
364 private:
365 FilePath file_path_;
366 bool recursive_;
367 };
368
369 class RelayTouchFilePath : public RelayWithStatusCallback {
370 public:
371 RelayTouchFilePath(
372 const fileapi::FileSystemOperationContext& context,
373 const FilePath& file_path,
374 const base::Time& last_access_time,
375 const base::Time& last_modified_time,
376 const fileapi::FileSystemFileUtilProxy::StatusCallback& callback)
377 : RelayWithStatusCallback(context, callback),
378 file_path_(file_path),
379 last_access_time_(last_access_time),
380 last_modified_time_(last_modified_time) {
381 }
382
383 protected:
384 virtual void RunWork() {
385 set_error_code(file_util()->Touch(
386 context(), file_path_, last_access_time_, last_modified_time_));
387 }
388
389 private:
390 FilePath file_path_;
391 base::Time last_access_time_;
392 base::Time last_modified_time_;
393 };
394
395 class RelayTruncate : public RelayWithStatusCallback {
396 public:
397 RelayTruncate(
398 const fileapi::FileSystemOperationContext& context,
399 const FilePath& file_path,
400 int64 length,
401 const fileapi::FileSystemFileUtilProxy::StatusCallback& callback)
402 : RelayWithStatusCallback(context, callback),
403 file_path_(file_path),
404 length_(length) {
405 }
406
407 protected:
408 virtual void RunWork() {
409 set_error_code(file_util()->Truncate(context(), file_path_, length_));
410 }
411
412 private:
413 FilePath file_path_;
414 int64 length_;
415 };
416
417 bool Start(const tracked_objects::Location& from_here, 165 bool Start(const tracked_objects::Location& from_here,
418 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, 166 scoped_refptr<base::MessageLoopProxy> message_loop_proxy,
419 scoped_refptr<MessageLoopRelay> relay) { 167 scoped_refptr<MessageLoopRelay> relay) {
420 return relay->Start(message_loop_proxy, from_here); 168 return relay->Start(message_loop_proxy, from_here);
421 } 169 }
422 170
423 } // namespace 171 } // namespace
424 172
425 namespace fileapi { 173 namespace fileapi {
426 174
427 // static 175 // static
428 bool FileSystemFileUtilProxy::CreateOrOpen(
429 const FileSystemOperationContext& context,
430 scoped_refptr<MessageLoopProxy> message_loop_proxy,
431 const FilePath& file_path, int file_flags,
432 const CreateOrOpenCallback& callback) {
433 return Start(FROM_HERE, message_loop_proxy, new RelayCreateOrOpen(context,
434 message_loop_proxy, file_path, file_flags, callback));
435 }
436
437 // static
438 bool FileSystemFileUtilProxy::Close(
439 const FileSystemOperationContext& context,
440 scoped_refptr<MessageLoopProxy> message_loop_proxy,
441 base::PlatformFile file_handle,
442 const StatusCallback& callback) {
443 return Start(FROM_HERE, message_loop_proxy,
444 new RelayClose(context, file_handle, callback));
445 }
446
447 // static
448 bool FileSystemFileUtilProxy::EnsureFileExists( 176 bool FileSystemFileUtilProxy::EnsureFileExists(
449 const FileSystemOperationContext& context, 177 const FileSystemOperationContext& context,
450 scoped_refptr<MessageLoopProxy> message_loop_proxy, 178 scoped_refptr<MessageLoopProxy> message_loop_proxy,
451 const FilePath& file_path, 179 const FilePath& file_path,
452 const EnsureFileExistsCallback& callback) { 180 const EnsureFileExistsCallback& callback) {
453 return Start(FROM_HERE, message_loop_proxy, new RelayEnsureFileExists( 181 return Start(FROM_HERE, message_loop_proxy, new RelayEnsureFileExists(
454 context, message_loop_proxy, file_path, callback)); 182 context, message_loop_proxy, file_path, callback));
455 } 183 }
456 184
457 // static 185 // static
458 bool FileSystemFileUtilProxy::GetLocalPath(
459 const FileSystemOperationContext& context,
460 scoped_refptr<MessageLoopProxy> message_loop_proxy,
461 const FilePath& virtual_path,
462 GetLocalPathCallback* callback) {
463 return Start(FROM_HERE, message_loop_proxy,
464 new RelayGetLocalPath(context, virtual_path, callback));
465 }
466
467 // static
468 bool FileSystemFileUtilProxy::GetFileInfo( 186 bool FileSystemFileUtilProxy::GetFileInfo(
469 const FileSystemOperationContext& context, 187 const FileSystemOperationContext& context,
470 scoped_refptr<MessageLoopProxy> message_loop_proxy, 188 scoped_refptr<MessageLoopProxy> message_loop_proxy,
471 const FilePath& file_path, 189 const FilePath& file_path,
472 const GetFileInfoCallback& callback) { 190 const GetFileInfoCallback& callback) {
473 return Start(FROM_HERE, message_loop_proxy, new RelayGetFileInfo(context, 191 return Start(FROM_HERE, message_loop_proxy, new RelayGetFileInfo(context,
474 file_path, callback)); 192 file_path, callback));
475 } 193 }
476 194
477 // static 195 // static
478 bool FileSystemFileUtilProxy::ReadDirectory( 196 bool FileSystemFileUtilProxy::ReadDirectory(
479 const FileSystemOperationContext& context, 197 const FileSystemOperationContext& context,
480 scoped_refptr<MessageLoopProxy> message_loop_proxy, 198 scoped_refptr<MessageLoopProxy> message_loop_proxy,
481 const FilePath& file_path, 199 const FilePath& file_path,
482 const ReadDirectoryCallback& callback) { 200 const ReadDirectoryCallback& callback) {
483 return Start(FROM_HERE, message_loop_proxy, new RelayReadDirectory(context, 201 return Start(FROM_HERE, message_loop_proxy, new RelayReadDirectory(context,
484 file_path, callback)); 202 file_path, callback));
485 } 203 }
486 204
487 // static
488 bool FileSystemFileUtilProxy::CreateDirectory(
489 const FileSystemOperationContext& context,
490 scoped_refptr<MessageLoopProxy> message_loop_proxy,
491 const FilePath& file_path,
492 bool exclusive,
493 bool recursive,
494 const StatusCallback& callback) {
495 return Start(FROM_HERE, message_loop_proxy, new RelayCreateDirectory(
496 context, file_path, exclusive, recursive, callback));
497 }
498
499 // static
500 bool FileSystemFileUtilProxy::Copy(
501 const FileSystemOperationContext& context,
502 scoped_refptr<MessageLoopProxy> message_loop_proxy,
503 const FilePath& src_file_path,
504 const FilePath& dest_file_path,
505 const StatusCallback& callback) {
506 return Start(FROM_HERE, message_loop_proxy,
507 new RelayCopy(context, src_file_path, dest_file_path,
508 callback));
509 }
510
511 // static
512 bool FileSystemFileUtilProxy::Move(
513 const FileSystemOperationContext& context,
514 scoped_refptr<MessageLoopProxy> message_loop_proxy,
515 const FilePath& src_file_path,
516 const FilePath& dest_file_path,
517 const StatusCallback& callback) {
518 return Start(FROM_HERE, message_loop_proxy,
519 new RelayMove(context, src_file_path, dest_file_path,
520 callback));
521 }
522
523 // static
524 bool FileSystemFileUtilProxy::Delete(
525 const FileSystemOperationContext& context,
526 scoped_refptr<MessageLoopProxy> message_loop_proxy,
527 const FilePath& file_path,
528 bool recursive,
529 const StatusCallback& callback) {
530 return Start(FROM_HERE, message_loop_proxy,
531 new RelayDelete(context, file_path, recursive, callback));
532 }
533
534 // static
535 bool FileSystemFileUtilProxy::Touch(
536 const FileSystemOperationContext& context,
537 scoped_refptr<MessageLoopProxy> message_loop_proxy,
538 const FilePath& file_path,
539 const base::Time& last_access_time,
540 const base::Time& last_modified_time,
541 const StatusCallback& callback) {
542 return Start(FROM_HERE, message_loop_proxy,
543 new RelayTouchFilePath(context, file_path, last_access_time,
544 last_modified_time, callback));
545 }
546
547 // static
548 bool FileSystemFileUtilProxy::Truncate(
549 const FileSystemOperationContext& context,
550 scoped_refptr<MessageLoopProxy> message_loop_proxy,
551 const FilePath& path,
552 int64 length,
553 const StatusCallback& callback) {
554 return Start(FROM_HERE, message_loop_proxy,
555 new RelayTruncate(context, path, length, callback));
556 }
557
558 } // namespace fileapi 205 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/file_system_file_util_proxy.h ('k') | webkit/fileapi/file_system_operation.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698