OLD | NEW |
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 "webkit/fileapi/local_file_system_operation.h" | 5 #include "webkit/fileapi/local_file_system_operation.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
9 #include "base/time.h" | 9 #include "base/time.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 base::Bind(&LocalFileSystemOperation::DidFileExists, | 186 base::Bind(&LocalFileSystemOperation::DidFileExists, |
187 base::Owned(this), callback)); | 187 base::Owned(this), callback)); |
188 } | 188 } |
189 | 189 |
190 void LocalFileSystemOperation::GetMetadata( | 190 void LocalFileSystemOperation::GetMetadata( |
191 const FileSystemURL& url, const GetMetadataCallback& callback) { | 191 const FileSystemURL& url, const GetMetadataCallback& callback) { |
192 DCHECK(SetPendingOperationType(kOperationGetMetadata)); | 192 DCHECK(SetPendingOperationType(kOperationGetMetadata)); |
193 | 193 |
194 base::PlatformFileError result = SetUp(url, SETUP_FOR_READ); | 194 base::PlatformFileError result = SetUp(url, SETUP_FOR_READ); |
195 if (result != base::PLATFORM_FILE_OK) { | 195 if (result != base::PLATFORM_FILE_OK) { |
196 callback.Run(result, base::PlatformFileInfo(), FilePath()); | 196 callback.Run(result, base::PlatformFileInfo(), base::FilePath()); |
197 delete this; | 197 delete this; |
198 return; | 198 return; |
199 } | 199 } |
200 | 200 |
201 async_file_util_->GetFileInfo( | 201 async_file_util_->GetFileInfo( |
202 operation_context(), url, | 202 operation_context(), url, |
203 base::Bind(&LocalFileSystemOperation::DidGetMetadata, | 203 base::Bind(&LocalFileSystemOperation::DidGetMetadata, |
204 base::Owned(this), callback)); | 204 base::Owned(this), callback)); |
205 } | 205 } |
206 | 206 |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 cancel_callback_ = cancel_callback; | 365 cancel_callback_ = cancel_callback; |
366 } | 366 } |
367 } | 367 } |
368 | 368 |
369 LocalFileSystemOperation* | 369 LocalFileSystemOperation* |
370 LocalFileSystemOperation::AsLocalFileSystemOperation() { | 370 LocalFileSystemOperation::AsLocalFileSystemOperation() { |
371 return this; | 371 return this; |
372 } | 372 } |
373 | 373 |
374 void LocalFileSystemOperation::SyncGetPlatformPath(const FileSystemURL& url, | 374 void LocalFileSystemOperation::SyncGetPlatformPath(const FileSystemURL& url, |
375 FilePath* platform_path) { | 375 base::FilePath* platform_path
) { |
376 DCHECK(SetPendingOperationType(kOperationGetLocalPath)); | 376 DCHECK(SetPendingOperationType(kOperationGetLocalPath)); |
377 | 377 |
378 base::PlatformFileError result = SetUp(url, SETUP_FOR_READ); | 378 base::PlatformFileError result = SetUp(url, SETUP_FOR_READ); |
379 if (result != base::PLATFORM_FILE_OK) { | 379 if (result != base::PLATFORM_FILE_OK) { |
380 delete this; | 380 delete this; |
381 return; | 381 return; |
382 } | 382 } |
383 | 383 |
384 FileSystemFileUtil* file_util = file_system_context()->GetFileUtil( | 384 FileSystemFileUtil* file_util = file_system_context()->GetFileUtil( |
385 url.type()); | 385 url.type()); |
386 DCHECK(file_util); | 386 DCHECK(file_util); |
387 file_util->GetLocalFilePath(operation_context(), url, platform_path); | 387 file_util->GetLocalFilePath(operation_context(), url, platform_path); |
388 | 388 |
389 delete this; | 389 delete this; |
390 } | 390 } |
391 | 391 |
392 void LocalFileSystemOperation::CreateSnapshotFile( | 392 void LocalFileSystemOperation::CreateSnapshotFile( |
393 const FileSystemURL& url, | 393 const FileSystemURL& url, |
394 const SnapshotFileCallback& callback) { | 394 const SnapshotFileCallback& callback) { |
395 DCHECK(SetPendingOperationType(kOperationCreateSnapshotFile)); | 395 DCHECK(SetPendingOperationType(kOperationCreateSnapshotFile)); |
396 | 396 |
397 base::PlatformFileError result = SetUp(url, SETUP_FOR_READ); | 397 base::PlatformFileError result = SetUp(url, SETUP_FOR_READ); |
398 if (result != base::PLATFORM_FILE_OK) { | 398 if (result != base::PLATFORM_FILE_OK) { |
399 callback.Run(result, base::PlatformFileInfo(), FilePath(), NULL); | 399 callback.Run(result, base::PlatformFileInfo(), base::FilePath(), NULL); |
400 delete this; | 400 delete this; |
401 return; | 401 return; |
402 } | 402 } |
403 | 403 |
404 async_file_util_->CreateSnapshotFile( | 404 async_file_util_->CreateSnapshotFile( |
405 operation_context(), url, | 405 operation_context(), url, |
406 base::Bind(&LocalFileSystemOperation::DidCreateSnapshotFile, | 406 base::Bind(&LocalFileSystemOperation::DidCreateSnapshotFile, |
407 base::Owned(this), callback)); | 407 base::Owned(this), callback)); |
408 } | 408 } |
409 | 409 |
410 void LocalFileSystemOperation::CopyInForeignFile( | 410 void LocalFileSystemOperation::CopyInForeignFile( |
411 const FilePath& src_local_disk_file_path, | 411 const base::FilePath& src_local_disk_file_path, |
412 const FileSystemURL& dest_url, | 412 const FileSystemURL& dest_url, |
413 const StatusCallback& callback) { | 413 const StatusCallback& callback) { |
414 DCHECK(SetPendingOperationType(kOperationCopyInForeignFile)); | 414 DCHECK(SetPendingOperationType(kOperationCopyInForeignFile)); |
415 | 415 |
416 base::PlatformFileError result = SetUp(dest_url, SETUP_FOR_CREATE); | 416 base::PlatformFileError result = SetUp(dest_url, SETUP_FOR_CREATE); |
417 if (result != base::PLATFORM_FILE_OK) { | 417 if (result != base::PLATFORM_FILE_OK) { |
418 callback.Run(result); | 418 callback.Run(result); |
419 delete this; | 419 delete this; |
420 return; | 420 return; |
421 } | 421 } |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
659 const FileSystemURL& src_url, | 659 const FileSystemURL& src_url, |
660 const FileSystemURL& dest_url, | 660 const FileSystemURL& dest_url, |
661 const StatusCallback& callback) { | 661 const StatusCallback& callback) { |
662 async_file_util_->MoveFileLocal( | 662 async_file_util_->MoveFileLocal( |
663 operation_context(), src_url, dest_url, | 663 operation_context(), src_url, dest_url, |
664 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation, | 664 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation, |
665 base::Owned(this), callback)); | 665 base::Owned(this), callback)); |
666 } | 666 } |
667 | 667 |
668 void LocalFileSystemOperation::DoCopyInForeignFile( | 668 void LocalFileSystemOperation::DoCopyInForeignFile( |
669 const FilePath& src_local_disk_file_path, | 669 const base::FilePath& src_local_disk_file_path, |
670 const FileSystemURL& dest_url, | 670 const FileSystemURL& dest_url, |
671 const StatusCallback& callback) { | 671 const StatusCallback& callback) { |
672 async_file_util_->CopyInForeignFile( | 672 async_file_util_->CopyInForeignFile( |
673 operation_context(), | 673 operation_context(), |
674 src_local_disk_file_path, dest_url, | 674 src_local_disk_file_path, dest_url, |
675 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation, | 675 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation, |
676 base::Owned(this), callback)); | 676 base::Owned(this), callback)); |
677 } | 677 } |
678 | 678 |
679 void LocalFileSystemOperation::DoTruncate(const FileSystemURL& url, | 679 void LocalFileSystemOperation::DoTruncate(const FileSystemURL& url, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
730 // The callback might be held by the delegate and Owned() may not work, | 730 // The callback might be held by the delegate and Owned() may not work, |
731 // so just explicitly delete this now. | 731 // so just explicitly delete this now. |
732 callback.Run(rv); | 732 callback.Run(rv); |
733 delete this; | 733 delete this; |
734 } | 734 } |
735 | 735 |
736 void LocalFileSystemOperation::DidDirectoryExists( | 736 void LocalFileSystemOperation::DidDirectoryExists( |
737 const StatusCallback& callback, | 737 const StatusCallback& callback, |
738 base::PlatformFileError rv, | 738 base::PlatformFileError rv, |
739 const base::PlatformFileInfo& file_info, | 739 const base::PlatformFileInfo& file_info, |
740 const FilePath& unused) { | 740 const base::FilePath& unused) { |
741 if (rv == base::PLATFORM_FILE_OK && !file_info.is_directory) | 741 if (rv == base::PLATFORM_FILE_OK && !file_info.is_directory) |
742 rv = base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY; | 742 rv = base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY; |
743 callback.Run(rv); | 743 callback.Run(rv); |
744 } | 744 } |
745 | 745 |
746 void LocalFileSystemOperation::DidFileExists( | 746 void LocalFileSystemOperation::DidFileExists( |
747 const StatusCallback& callback, | 747 const StatusCallback& callback, |
748 base::PlatformFileError rv, | 748 base::PlatformFileError rv, |
749 const base::PlatformFileInfo& file_info, | 749 const base::PlatformFileInfo& file_info, |
750 const FilePath& unused) { | 750 const base::FilePath& unused) { |
751 if (rv == base::PLATFORM_FILE_OK && file_info.is_directory) | 751 if (rv == base::PLATFORM_FILE_OK && file_info.is_directory) |
752 rv = base::PLATFORM_FILE_ERROR_NOT_A_FILE; | 752 rv = base::PLATFORM_FILE_ERROR_NOT_A_FILE; |
753 callback.Run(rv); | 753 callback.Run(rv); |
754 } | 754 } |
755 | 755 |
756 void LocalFileSystemOperation::DidGetMetadata( | 756 void LocalFileSystemOperation::DidGetMetadata( |
757 const GetMetadataCallback& callback, | 757 const GetMetadataCallback& callback, |
758 base::PlatformFileError rv, | 758 base::PlatformFileError rv, |
759 const base::PlatformFileInfo& file_info, | 759 const base::PlatformFileInfo& file_info, |
760 const FilePath& platform_path) { | 760 const base::FilePath& platform_path) { |
761 callback.Run(rv, file_info, platform_path); | 761 callback.Run(rv, file_info, platform_path); |
762 } | 762 } |
763 | 763 |
764 void LocalFileSystemOperation::DidReadDirectory( | 764 void LocalFileSystemOperation::DidReadDirectory( |
765 const ReadDirectoryCallback& callback, | 765 const ReadDirectoryCallback& callback, |
766 base::PlatformFileError rv, | 766 base::PlatformFileError rv, |
767 const std::vector<base::FileUtilProxy::Entry>& entries, | 767 const std::vector<base::FileUtilProxy::Entry>& entries, |
768 bool has_more) { | 768 bool has_more) { |
769 callback.Run(rv, entries, has_more); | 769 callback.Run(rv, entries, has_more); |
770 } | 770 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
805 bool unused) { | 805 bool unused) { |
806 if (rv == base::PLATFORM_FILE_OK) | 806 if (rv == base::PLATFORM_FILE_OK) |
807 CHECK_NE(base::kNullProcessHandle, peer_handle_); | 807 CHECK_NE(base::kNullProcessHandle, peer_handle_); |
808 callback.Run(rv, file.ReleaseValue(), peer_handle_); | 808 callback.Run(rv, file.ReleaseValue(), peer_handle_); |
809 } | 809 } |
810 | 810 |
811 void LocalFileSystemOperation::DidCreateSnapshotFile( | 811 void LocalFileSystemOperation::DidCreateSnapshotFile( |
812 const SnapshotFileCallback& callback, | 812 const SnapshotFileCallback& callback, |
813 base::PlatformFileError result, | 813 base::PlatformFileError result, |
814 const base::PlatformFileInfo& file_info, | 814 const base::PlatformFileInfo& file_info, |
815 const FilePath& platform_path, | 815 const base::FilePath& platform_path, |
816 SnapshotFilePolicy snapshot_policy) { | 816 SnapshotFilePolicy snapshot_policy) { |
817 scoped_refptr<ShareableFileReference> file_ref; | 817 scoped_refptr<ShareableFileReference> file_ref; |
818 if (result == base::PLATFORM_FILE_OK && | 818 if (result == base::PLATFORM_FILE_OK && |
819 snapshot_policy == kSnapshotFileTemporary) { | 819 snapshot_policy == kSnapshotFileTemporary) { |
820 file_ref = ShareableFileReference::GetOrCreate( | 820 file_ref = ShareableFileReference::GetOrCreate( |
821 platform_path, ShareableFileReference::DELETE_ON_FINAL_RELEASE, | 821 platform_path, ShareableFileReference::DELETE_ON_FINAL_RELEASE, |
822 file_system_context()->task_runners()->file_task_runner()); | 822 file_system_context()->task_runners()->file_task_runner()); |
823 } | 823 } |
824 callback.Run(result, file_info, platform_path, file_ref); | 824 callback.Run(result, file_info, platform_path, file_ref); |
825 } | 825 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
878 } | 878 } |
879 | 879 |
880 bool LocalFileSystemOperation::SetPendingOperationType(OperationType type) { | 880 bool LocalFileSystemOperation::SetPendingOperationType(OperationType type) { |
881 if (pending_operation_ != kOperationNone) | 881 if (pending_operation_ != kOperationNone) |
882 return false; | 882 return false; |
883 pending_operation_ = type; | 883 pending_operation_ = type; |
884 return true; | 884 return true; |
885 } | 885 } |
886 | 886 |
887 } // namespace fileapi | 887 } // namespace fileapi |
OLD | NEW |