[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "webkit/fileapi/isolated_mount_point_provider.h" |
| 6 | |
[email protected] | c671c8a | 2012-04-05 10:28:39 | [diff] [blame] | 7 | #include <string> |
| 8 | |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 9 | #include "base/bind.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 10 | #include "base/files/file_path.h" |
[email protected] | d269196 | 2013-05-16 14:19:27 | [diff] [blame^] | 11 | #include "base/files/file_util_proxy.h" |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 12 | #include "base/logging.h" |
| 13 | #include "base/message_loop_proxy.h" |
[email protected] | 2f9f5b49 | 2012-09-12 02:59:06 | [diff] [blame] | 14 | #include "base/platform_file.h" |
[email protected] | fb44196 | 2013-05-08 05:35:24 | [diff] [blame] | 15 | #include "base/sequenced_task_runner.h" |
[email protected] | c4ca3b45 | 2012-05-31 03:15:46 | [diff] [blame] | 16 | #include "webkit/blob/local_file_stream_reader.h" |
[email protected] | 25b69799 | 2013-01-29 07:10:05 | [diff] [blame] | 17 | #include "webkit/fileapi/async_file_util_adapter.h" |
[email protected] | 98407ee | 2013-04-04 08:52:17 | [diff] [blame] | 18 | #include "webkit/fileapi/copy_or_move_file_validator.h" |
[email protected] | bcbd98d | 2012-05-07 04:10:10 | [diff] [blame] | 19 | #include "webkit/fileapi/file_system_context.h" |
[email protected] | c4ca3b45 | 2012-05-31 03:15:46 | [diff] [blame] | 20 | #include "webkit/fileapi/file_system_file_stream_reader.h" |
[email protected] | 5f778268 | 2013-03-04 02:43:35 | [diff] [blame] | 21 | #include "webkit/fileapi/file_system_operation_context.h" |
[email protected] | dc57ec8 | 2012-08-07 03:50:10 | [diff] [blame] | 22 | #include "webkit/fileapi/file_system_task_runners.h" |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 23 | #include "webkit/fileapi/file_system_types.h" |
[email protected] | ad117b1 | 2012-04-19 05:40:19 | [diff] [blame] | 24 | #include "webkit/fileapi/file_system_util.h" |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 25 | #include "webkit/fileapi/isolated_context.h" |
| 26 | #include "webkit/fileapi/isolated_file_util.h" |
[email protected] | 7e836a3d | 2012-05-31 05:14:59 | [diff] [blame] | 27 | #include "webkit/fileapi/local_file_stream_writer.h" |
[email protected] | 02a6054 | 2012-07-24 20:05:33 | [diff] [blame] | 28 | #include "webkit/fileapi/local_file_system_operation.h" |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 29 | #include "webkit/fileapi/native_file_util.h" |
[email protected] | b258286 | 2013-05-14 08:50:18 | [diff] [blame] | 30 | #include "webkit/fileapi/transient_file_util.h" |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 31 | |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 32 | namespace fileapi { |
| 33 | |
[email protected] | c3d638b3 | 2013-04-22 02:18:49 | [diff] [blame] | 34 | IsolatedMountPointProvider::IsolatedMountPointProvider() |
| 35 | : isolated_file_util_(new AsyncFileUtilAdapter(new IsolatedFileUtil())), |
[email protected] | b258286 | 2013-05-14 08:50:18 | [diff] [blame] | 36 | dragged_file_util_(new AsyncFileUtilAdapter(new DraggedFileUtil())), |
| 37 | transient_file_util_(new AsyncFileUtilAdapter(new TransientFileUtil())) { |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | IsolatedMountPointProvider::~IsolatedMountPointProvider() { |
| 41 | } |
| 42 | |
[email protected] | 420fb56 | 2013-04-18 01:46:34 | [diff] [blame] | 43 | bool IsolatedMountPointProvider::CanHandleType(FileSystemType type) const { |
| 44 | switch (type) { |
| 45 | case kFileSystemTypeIsolated: |
| 46 | case kFileSystemTypeDragged: |
[email protected] | b258286 | 2013-05-14 08:50:18 | [diff] [blame] | 47 | case kFileSystemTypeForTransientFile: |
[email protected] | 420fb56 | 2013-04-18 01:46:34 | [diff] [blame] | 48 | return true; |
| 49 | #if !defined(OS_CHROMEOS) |
| 50 | case kFileSystemTypeNativeLocal: |
| 51 | case kFileSystemTypeNativeForPlatformApp: |
| 52 | return true; |
| 53 | #endif |
| 54 | default: |
| 55 | return false; |
| 56 | } |
| 57 | } |
| 58 | |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 59 | void IsolatedMountPointProvider::ValidateFileSystemRoot( |
| 60 | const GURL& origin_url, |
| 61 | FileSystemType type, |
| 62 | bool create, |
| 63 | const ValidateFileSystemCallback& callback) { |
| 64 | // We never allow opening a new isolated FileSystem via usual OpenFileSystem. |
| 65 | base::MessageLoopProxy::current()->PostTask( |
| 66 | FROM_HERE, |
| 67 | base::Bind(callback, base::PLATFORM_FILE_ERROR_SECURITY)); |
| 68 | } |
| 69 | |
[email protected] | a3ef483 | 2013-02-02 05:12:33 | [diff] [blame] | 70 | base::FilePath IsolatedMountPointProvider::GetFileSystemRootPathOnFileThread( |
[email protected] | 199263e | 2012-12-14 07:14:20 | [diff] [blame] | 71 | const FileSystemURL& url, |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 72 | bool create) { |
[email protected] | d6afd11 | 2012-07-25 22:55:04 | [diff] [blame] | 73 | // This is not supposed to be used. |
| 74 | NOTREACHED(); |
[email protected] | a3ef483 | 2013-02-02 05:12:33 | [diff] [blame] | 75 | return base::FilePath(); |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 76 | } |
| 77 | |
[email protected] | d6afd11 | 2012-07-25 22:55:04 | [diff] [blame] | 78 | FileSystemFileUtil* IsolatedMountPointProvider::GetFileUtil( |
| 79 | FileSystemType type) { |
[email protected] | 6ef35d6 | 2012-08-02 02:55:28 | [diff] [blame] | 80 | switch (type) { |
[email protected] | 9fb9294a | 2012-08-21 14:55:37 | [diff] [blame] | 81 | case kFileSystemTypeNativeLocal: |
[email protected] | 25b69799 | 2013-01-29 07:10:05 | [diff] [blame] | 82 | return isolated_file_util_->sync_file_util(); |
| 83 | case kFileSystemTypeDragged: |
| 84 | return dragged_file_util_->sync_file_util(); |
[email protected] | b258286 | 2013-05-14 08:50:18 | [diff] [blame] | 85 | case kFileSystemTypeForTransientFile: |
| 86 | return transient_file_util_->sync_file_util(); |
[email protected] | 25b69799 | 2013-01-29 07:10:05 | [diff] [blame] | 87 | default: |
| 88 | NOTREACHED(); |
| 89 | } |
| 90 | return NULL; |
| 91 | } |
| 92 | |
| 93 | AsyncFileUtil* IsolatedMountPointProvider::GetAsyncFileUtil( |
| 94 | FileSystemType type) { |
| 95 | switch (type) { |
| 96 | case kFileSystemTypeNativeLocal: |
[email protected] | 6ef35d6 | 2012-08-02 02:55:28 | [diff] [blame] | 97 | return isolated_file_util_.get(); |
| 98 | case kFileSystemTypeDragged: |
| 99 | return dragged_file_util_.get(); |
[email protected] | b258286 | 2013-05-14 08:50:18 | [diff] [blame] | 100 | case kFileSystemTypeForTransientFile: |
| 101 | return transient_file_util_.get(); |
[email protected] | 9fb9294a | 2012-08-21 14:55:37 | [diff] [blame] | 102 | default: |
[email protected] | 6ef35d6 | 2012-08-02 02:55:28 | [diff] [blame] | 103 | NOTREACHED(); |
| 104 | } |
| 105 | return NULL; |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 106 | } |
| 107 | |
[email protected] | 98407ee | 2013-04-04 08:52:17 | [diff] [blame] | 108 | CopyOrMoveFileValidatorFactory* |
| 109 | IsolatedMountPointProvider::GetCopyOrMoveFileValidatorFactory( |
| 110 | FileSystemType type, base::PlatformFileError* error_code) { |
| 111 | DCHECK(error_code); |
| 112 | *error_code = base::PLATFORM_FILE_OK; |
[email protected] | 98407ee | 2013-04-04 08:52:17 | [diff] [blame] | 113 | return NULL; |
| 114 | } |
| 115 | |
| 116 | void IsolatedMountPointProvider::InitializeCopyOrMoveFileValidatorFactory( |
| 117 | FileSystemType type, |
| 118 | scoped_ptr<CopyOrMoveFileValidatorFactory> factory) { |
[email protected] | c3d638b3 | 2013-04-22 02:18:49 | [diff] [blame] | 119 | DCHECK(!factory); |
[email protected] | 98407ee | 2013-04-04 08:52:17 | [diff] [blame] | 120 | } |
| 121 | |
[email protected] | b40ffe7 | 2013-01-10 04:05:31 | [diff] [blame] | 122 | FilePermissionPolicy IsolatedMountPointProvider::GetPermissionPolicy( |
| 123 | const FileSystemURL& url, int permissions) const { |
| 124 | if (url.type() == kFileSystemTypeDragged && url.path().empty()) { |
| 125 | // The root directory of the dragged filesystem must be always read-only. |
[email protected] | 4d03859 | 2013-02-18 16:50:23 | [diff] [blame] | 126 | if (permissions & ~fileapi::kReadFilePermissions) |
[email protected] | b40ffe7 | 2013-01-10 04:05:31 | [diff] [blame] | 127 | return FILE_PERMISSION_ALWAYS_DENY; |
| 128 | } |
| 129 | // Access to isolated file systems should be checked using per-filesystem |
| 130 | // access permission. |
| 131 | return FILE_PERMISSION_USE_FILESYSTEM_PERMISSION; |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 132 | } |
| 133 | |
[email protected] | 8e3bc3e | 2012-08-24 13:12:53 | [diff] [blame] | 134 | FileSystemOperation* IsolatedMountPointProvider::CreateFileSystemOperation( |
[email protected] | 949f25a | 2012-06-27 01:53:09 | [diff] [blame] | 135 | const FileSystemURL& url, |
[email protected] | d23a00cc | 2012-09-11 17:38:13 | [diff] [blame] | 136 | FileSystemContext* context, |
| 137 | base::PlatformFileError* error_code) const { |
[email protected] | c3d638b3 | 2013-04-22 02:18:49 | [diff] [blame] | 138 | return new LocalFileSystemOperation( |
| 139 | context, make_scoped_ptr(new FileSystemOperationContext(context))); |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 140 | } |
| 141 | |
[email protected] | 3ee9eb0 | 2013-04-10 09:17:05 | [diff] [blame] | 142 | scoped_ptr<webkit_blob::FileStreamReader> |
[email protected] | c4ca3b45 | 2012-05-31 03:15:46 | [diff] [blame] | 143 | IsolatedMountPointProvider::CreateFileStreamReader( |
[email protected] | 949f25a | 2012-06-27 01:53:09 | [diff] [blame] | 144 | const FileSystemURL& url, |
[email protected] | ad117b1 | 2012-04-19 05:40:19 | [diff] [blame] | 145 | int64 offset, |
[email protected] | a105783 | 2012-10-15 13:28:06 | [diff] [blame] | 146 | const base::Time& expected_modification_time, |
[email protected] | ad117b1 | 2012-04-19 05:40:19 | [diff] [blame] | 147 | FileSystemContext* context) const { |
[email protected] | 3ee9eb0 | 2013-04-10 09:17:05 | [diff] [blame] | 148 | return scoped_ptr<webkit_blob::FileStreamReader>( |
| 149 | new webkit_blob::LocalFileStreamReader( |
| 150 | context->task_runners()->file_task_runner(), |
| 151 | url.path(), offset, expected_modification_time)); |
[email protected] | ad117b1 | 2012-04-19 05:40:19 | [diff] [blame] | 152 | } |
| 153 | |
[email protected] | 3ee9eb0 | 2013-04-10 09:17:05 | [diff] [blame] | 154 | scoped_ptr<FileStreamWriter> IsolatedMountPointProvider::CreateFileStreamWriter( |
[email protected] | 949f25a | 2012-06-27 01:53:09 | [diff] [blame] | 155 | const FileSystemURL& url, |
[email protected] | 7e84b91 | 2012-05-16 04:42:01 | [diff] [blame] | 156 | int64 offset, |
| 157 | FileSystemContext* context) const { |
[email protected] | 3ee9eb0 | 2013-04-10 09:17:05 | [diff] [blame] | 158 | return scoped_ptr<FileStreamWriter>( |
| 159 | new LocalFileStreamWriter(url.path(), offset)); |
[email protected] | 7e84b91 | 2012-05-16 04:42:01 | [diff] [blame] | 160 | } |
| 161 | |
[email protected] | 6faad82 | 2012-05-11 12:58:29 | [diff] [blame] | 162 | FileSystemQuotaUtil* IsolatedMountPointProvider::GetQuotaUtil() { |
| 163 | // No quota support. |
| 164 | return NULL; |
| 165 | } |
| 166 | |
[email protected] | d5e0855 | 2012-08-02 21:43:40 | [diff] [blame] | 167 | void IsolatedMountPointProvider::DeleteFileSystem( |
| 168 | const GURL& origin_url, |
| 169 | FileSystemType type, |
| 170 | FileSystemContext* context, |
| 171 | const DeleteFileSystemCallback& callback) { |
| 172 | NOTREACHED(); |
| 173 | callback.Run(base::PLATFORM_FILE_ERROR_INVALID_OPERATION); |
| 174 | } |
| 175 | |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 176 | } // namespace fileapi |