| 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/sequenced_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" |
| 11 #include "net/base/escape.h" | 11 #include "net/base/escape.h" |
| 12 #include "net/url_request/url_request_context.h" | 12 #include "net/url_request/url_request_context.h" |
| 13 #include "webkit/blob/shareable_file_reference.h" | 13 #include "webkit/blob/shareable_file_reference.h" |
| 14 #include "webkit/fileapi/file_system_context.h" | 14 #include "webkit/fileapi/file_system_context.h" |
| 15 #include "webkit/fileapi/file_system_file_util_proxy.h" | 15 #include "webkit/fileapi/file_system_file_util_proxy.h" |
| 16 #include "webkit/fileapi/file_system_mount_point_provider.h" | 16 #include "webkit/fileapi/file_system_mount_point_provider.h" |
| 17 #include "webkit/fileapi/file_system_operation_context.h" | 17 #include "webkit/fileapi/file_system_operation_context.h" |
| 18 #include "webkit/fileapi/file_system_quota_util.h" | 18 #include "webkit/fileapi/file_system_quota_util.h" |
| 19 #include "webkit/fileapi/file_system_task_runners.h" |
| 19 #include "webkit/fileapi/file_system_types.h" | 20 #include "webkit/fileapi/file_system_types.h" |
| 20 #include "webkit/fileapi/file_system_url.h" | 21 #include "webkit/fileapi/file_system_url.h" |
| 21 #include "webkit/fileapi/file_system_util.h" | 22 #include "webkit/fileapi/file_system_util.h" |
| 22 #include "webkit/fileapi/file_writer_delegate.h" | 23 #include "webkit/fileapi/file_writer_delegate.h" |
| 23 #include "webkit/fileapi/sandbox_file_stream_writer.h" | 24 #include "webkit/fileapi/sandbox_file_stream_writer.h" |
| 24 #include "webkit/quota/quota_manager.h" | 25 #include "webkit/quota/quota_manager.h" |
| 25 #include "webkit/quota/quota_types.h" | 26 #include "webkit/quota/quota_types.h" |
| 26 | 27 |
| 27 using webkit_blob::ShareableFileReference; | 28 using webkit_blob::ShareableFileReference; |
| 28 | 29 |
| 29 namespace fileapi { | 30 namespace fileapi { |
| 30 | 31 |
| 32 namespace { |
| 33 |
| 34 bool IsMediaFileSystemType(FileSystemType type) { |
| 35 return type == kFileSystemTypeNativeMedia || |
| 36 type == kFileSystemTypeDeviceMedia; |
| 37 } |
| 38 |
| 39 bool IsCrossOperationAllowed(FileSystemType src_type, |
| 40 FileSystemType dest_type) { |
| 41 // If two types are supposed to run on different task runners we should not |
| 42 // allow cross FileUtil operations at this layer. |
| 43 return IsMediaFileSystemType(src_type) == IsMediaFileSystemType(dest_type); |
| 44 } |
| 45 |
| 46 } // namespace |
| 47 |
| 31 class LocalFileSystemOperation::ScopedQuotaNotifier { | 48 class LocalFileSystemOperation::ScopedQuotaNotifier { |
| 32 public: | 49 public: |
| 33 ScopedQuotaNotifier(FileSystemContext* context, | 50 ScopedQuotaNotifier(FileSystemContext* context, |
| 34 const GURL& origin_url, | 51 const GURL& origin_url, |
| 35 FileSystemType type); | 52 FileSystemType type); |
| 36 ~ScopedQuotaNotifier(); | 53 ~ScopedQuotaNotifier(); |
| 37 | 54 |
| 38 private: | 55 private: |
| 39 // Not owned; owned by the owner of this instance | 56 // Not owned; owned by the owner of this instance |
| 40 // (i.e. LocalFileSystemOperation). | 57 // (i.e. LocalFileSystemOperation). |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 } | 128 } |
| 112 | 129 |
| 113 void LocalFileSystemOperation::Copy(const FileSystemURL& src_url, | 130 void LocalFileSystemOperation::Copy(const FileSystemURL& src_url, |
| 114 const FileSystemURL& dest_url, | 131 const FileSystemURL& dest_url, |
| 115 const StatusCallback& callback) { | 132 const StatusCallback& callback) { |
| 116 DCHECK(SetPendingOperationType(kOperationCopy)); | 133 DCHECK(SetPendingOperationType(kOperationCopy)); |
| 117 | 134 |
| 118 base::PlatformFileError result = SetUp(src_url, &src_util_, SETUP_FOR_READ); | 135 base::PlatformFileError result = SetUp(src_url, &src_util_, SETUP_FOR_READ); |
| 119 if (result == base::PLATFORM_FILE_OK) | 136 if (result == base::PLATFORM_FILE_OK) |
| 120 result = SetUp(dest_url, &dest_util_, SETUP_FOR_CREATE); | 137 result = SetUp(dest_url, &dest_util_, SETUP_FOR_CREATE); |
| 138 if (result == base::PLATFORM_FILE_OK) { |
| 139 if (!IsCrossOperationAllowed(src_url.type(), dest_url.type())) |
| 140 result = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; |
| 141 } |
| 121 if (result != base::PLATFORM_FILE_OK) { | 142 if (result != base::PLATFORM_FILE_OK) { |
| 122 callback.Run(result); | 143 callback.Run(result); |
| 123 delete this; | 144 delete this; |
| 124 return; | 145 return; |
| 125 } | 146 } |
| 126 | 147 |
| 127 GetUsageAndQuotaThenRunTask( | 148 GetUsageAndQuotaThenRunTask( |
| 128 dest_url, | 149 dest_url, |
| 129 base::Bind(&LocalFileSystemOperation::DoCopy, | 150 base::Bind(&LocalFileSystemOperation::DoCopy, |
| 130 base::Unretained(this), src_url, dest_url, callback), | 151 base::Unretained(this), src_url, dest_url, callback), |
| 131 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED)); | 152 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED)); |
| 132 } | 153 } |
| 133 | 154 |
| 134 void LocalFileSystemOperation::Move(const FileSystemURL& src_url, | 155 void LocalFileSystemOperation::Move(const FileSystemURL& src_url, |
| 135 const FileSystemURL& dest_url, | 156 const FileSystemURL& dest_url, |
| 136 const StatusCallback& callback) { | 157 const StatusCallback& callback) { |
| 137 DCHECK(SetPendingOperationType(kOperationMove)); | 158 DCHECK(SetPendingOperationType(kOperationMove)); |
| 138 scoped_ptr<LocalFileSystemOperation> deleter(this); | 159 scoped_ptr<LocalFileSystemOperation> deleter(this); |
| 139 | 160 |
| 140 base::PlatformFileError result = SetUp(src_url, &src_util_, SETUP_FOR_WRITE); | 161 base::PlatformFileError result = SetUp(src_url, &src_util_, SETUP_FOR_WRITE); |
| 141 if (result == base::PLATFORM_FILE_OK) | 162 if (result == base::PLATFORM_FILE_OK) |
| 142 result = SetUp(dest_url, &dest_util_, SETUP_FOR_CREATE); | 163 result = SetUp(dest_url, &dest_util_, SETUP_FOR_CREATE); |
| 164 if (result == base::PLATFORM_FILE_OK) { |
| 165 if (!IsCrossOperationAllowed(src_url.type(), dest_url.type())) |
| 166 result = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; |
| 167 } |
| 143 if (result != base::PLATFORM_FILE_OK) { | 168 if (result != base::PLATFORM_FILE_OK) { |
| 144 callback.Run(result); | 169 callback.Run(result); |
| 145 return; | 170 return; |
| 146 } | 171 } |
| 147 | 172 |
| 148 // Temporarily disables cross-filesystem move for sandbox filesystems. | 173 // Temporarily disables cross-filesystem move for sandbox filesystems. |
| 149 // TODO(kinuko,tzik,kinaba): This special handling must be removed once | 174 // TODO(kinuko,tzik,kinaba): This special handling must be removed once |
| 150 // we support saner cross-filesystem operation. | 175 // we support saner cross-filesystem operation. |
| 151 // (See http://crbug.com/130055) | 176 // (See http://crbug.com/130055) |
| 152 if (src_url.type() != dest_url.type() && | 177 if (src_url.type() != dest_url.type() && |
| (...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 const SnapshotFileCallback& callback, | 702 const SnapshotFileCallback& callback, |
| 678 base::PlatformFileError result, | 703 base::PlatformFileError result, |
| 679 const base::PlatformFileInfo& file_info, | 704 const base::PlatformFileInfo& file_info, |
| 680 const FilePath& platform_path, | 705 const FilePath& platform_path, |
| 681 FileSystemFileUtil::SnapshotFilePolicy snapshot_policy) { | 706 FileSystemFileUtil::SnapshotFilePolicy snapshot_policy) { |
| 682 scoped_refptr<ShareableFileReference> file_ref; | 707 scoped_refptr<ShareableFileReference> file_ref; |
| 683 if (result == base::PLATFORM_FILE_OK && | 708 if (result == base::PLATFORM_FILE_OK && |
| 684 snapshot_policy == FileSystemFileUtil::kSnapshotFileTemporary) { | 709 snapshot_policy == FileSystemFileUtil::kSnapshotFileTemporary) { |
| 685 file_ref = ShareableFileReference::GetOrCreate( | 710 file_ref = ShareableFileReference::GetOrCreate( |
| 686 platform_path, ShareableFileReference::DELETE_ON_FINAL_RELEASE, | 711 platform_path, ShareableFileReference::DELETE_ON_FINAL_RELEASE, |
| 687 file_system_context()->file_task_runner()); | 712 file_system_context()->task_runners()->file_task_runner()); |
| 688 } | 713 } |
| 689 callback.Run(result, file_info, platform_path, file_ref); | 714 callback.Run(result, file_info, platform_path, file_ref); |
| 690 } | 715 } |
| 691 | 716 |
| 692 base::PlatformFileError LocalFileSystemOperation::SetUp( | 717 base::PlatformFileError LocalFileSystemOperation::SetUp( |
| 693 const FileSystemURL& url, | 718 const FileSystemURL& url, |
| 694 FileSystemFileUtil** file_util, | 719 FileSystemFileUtil** file_util, |
| 695 SetUpMode mode) { | 720 SetUpMode mode) { |
| 696 if (!url.is_valid()) | 721 if (!url.is_valid()) |
| 697 return base::PLATFORM_FILE_ERROR_INVALID_URL; | 722 return base::PLATFORM_FILE_ERROR_INVALID_URL; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 741 } | 766 } |
| 742 | 767 |
| 743 bool LocalFileSystemOperation::SetPendingOperationType(OperationType type) { | 768 bool LocalFileSystemOperation::SetPendingOperationType(OperationType type) { |
| 744 if (pending_operation_ != kOperationNone) | 769 if (pending_operation_ != kOperationNone) |
| 745 return false; | 770 return false; |
| 746 pending_operation_ = type; | 771 pending_operation_ = type; |
| 747 return true; | 772 return true; |
| 748 } | 773 } |
| 749 | 774 |
| 750 } // namespace fileapi | 775 } // namespace fileapi |
| OLD | NEW |