[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 | |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 5 | #include "webkit/browser/fileapi/isolated_file_system_backend.h" |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 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" |
[email protected] | 7ccb707 | 2013-06-10 20:56:28 | [diff] [blame] | 13 | #include "base/message_loop/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] | b76b556d | 2013-05-29 03:09:43 | [diff] [blame] | 16 | #include "webkit/browser/blob/local_file_stream_reader.h" |
[email protected] | c6f9203a | 2013-05-28 02:08:07 | [diff] [blame] | 17 | #include "webkit/browser/fileapi/async_file_util_adapter.h" |
[email protected] | 20c2df6 | 2013-05-21 08:26:36 | [diff] [blame] | 18 | #include "webkit/browser/fileapi/copy_or_move_file_validator.h" |
[email protected] | c6f9203a | 2013-05-28 02:08:07 | [diff] [blame] | 19 | #include "webkit/browser/fileapi/file_system_context.h" |
| 20 | #include "webkit/browser/fileapi/file_system_file_stream_reader.h" |
| 21 | #include "webkit/browser/fileapi/file_system_operation_context.h" |
[email protected] | 61b48e0 | 2013-08-01 15:00:10 | [diff] [blame] | 22 | #include "webkit/browser/fileapi/file_system_operation_impl.h" |
[email protected] | f25e113 | 2013-05-24 13:58:04 | [diff] [blame] | 23 | #include "webkit/browser/fileapi/isolated_context.h" |
[email protected] | 5a20d04 | 2013-05-22 12:54:18 | [diff] [blame] | 24 | #include "webkit/browser/fileapi/isolated_file_util.h" |
[email protected] | c6f9203a | 2013-05-28 02:08:07 | [diff] [blame] | 25 | #include "webkit/browser/fileapi/local_file_stream_writer.h" |
[email protected] | 5a20d04 | 2013-05-22 12:54:18 | [diff] [blame] | 26 | #include "webkit/browser/fileapi/native_file_util.h" |
| 27 | #include "webkit/browser/fileapi/transient_file_util.h" |
[email protected] | 61d271f3 | 2013-05-28 04:59:23 | [diff] [blame] | 28 | #include "webkit/common/fileapi/file_system_types.h" |
| 29 | #include "webkit/common/fileapi/file_system_util.h" |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 30 | |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 31 | namespace fileapi { |
| 32 | |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 33 | IsolatedFileSystemBackend::IsolatedFileSystemBackend() |
[email protected] | c3d638b3 | 2013-04-22 02:18:49 | [diff] [blame] | 34 | : isolated_file_util_(new AsyncFileUtilAdapter(new IsolatedFileUtil())), |
[email protected] | b258286 | 2013-05-14 08:50:18 | [diff] [blame] | 35 | dragged_file_util_(new AsyncFileUtilAdapter(new DraggedFileUtil())), |
| 36 | transient_file_util_(new AsyncFileUtilAdapter(new TransientFileUtil())) { |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 37 | } |
| 38 | |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 39 | IsolatedFileSystemBackend::~IsolatedFileSystemBackend() { |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 40 | } |
| 41 | |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 42 | bool IsolatedFileSystemBackend::CanHandleType(FileSystemType type) const { |
[email protected] | 420fb56 | 2013-04-18 01:46:34 | [diff] [blame] | 43 | switch (type) { |
| 44 | case kFileSystemTypeIsolated: |
| 45 | case kFileSystemTypeDragged: |
[email protected] | b258286 | 2013-05-14 08:50:18 | [diff] [blame] | 46 | case kFileSystemTypeForTransientFile: |
[email protected] | 420fb56 | 2013-04-18 01:46:34 | [diff] [blame] | 47 | return true; |
| 48 | #if !defined(OS_CHROMEOS) |
| 49 | case kFileSystemTypeNativeLocal: |
| 50 | case kFileSystemTypeNativeForPlatformApp: |
| 51 | return true; |
| 52 | #endif |
| 53 | default: |
| 54 | return false; |
| 55 | } |
| 56 | } |
| 57 | |
[email protected] | 3fc17aed | 2013-07-24 10:01:50 | [diff] [blame] | 58 | void IsolatedFileSystemBackend::Initialize(FileSystemContext* context) { |
| 59 | } |
| 60 | |
| 61 | void IsolatedFileSystemBackend::OpenFileSystem( |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 62 | const GURL& origin_url, |
| 63 | FileSystemType type, |
[email protected] | 22dea52c | 2013-05-29 07:44:40 | [diff] [blame] | 64 | OpenFileSystemMode mode, |
[email protected] | 3fc17aed | 2013-07-24 10:01:50 | [diff] [blame] | 65 | const OpenFileSystemCallback& callback) { |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 66 | // We never allow opening a new isolated FileSystem via usual OpenFileSystem. |
| 67 | base::MessageLoopProxy::current()->PostTask( |
| 68 | FROM_HERE, |
[email protected] | a836883d | 2013-07-12 03:50:02 | [diff] [blame] | 69 | base::Bind(callback, |
| 70 | GetFileSystemRootURI(origin_url, type), |
| 71 | GetFileSystemName(origin_url, type), |
| 72 | base::PLATFORM_FILE_ERROR_SECURITY)); |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 73 | } |
| 74 | |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 75 | FileSystemFileUtil* IsolatedFileSystemBackend::GetFileUtil( |
[email protected] | d6afd11 | 2012-07-25 22:55:04 | [diff] [blame] | 76 | FileSystemType type) { |
[email protected] | 6ef35d6 | 2012-08-02 02:55:28 | [diff] [blame] | 77 | switch (type) { |
[email protected] | 9fb9294a | 2012-08-21 14:55:37 | [diff] [blame] | 78 | case kFileSystemTypeNativeLocal: |
[email protected] | 25b69799 | 2013-01-29 07:10:05 | [diff] [blame] | 79 | return isolated_file_util_->sync_file_util(); |
| 80 | case kFileSystemTypeDragged: |
| 81 | return dragged_file_util_->sync_file_util(); |
[email protected] | b258286 | 2013-05-14 08:50:18 | [diff] [blame] | 82 | case kFileSystemTypeForTransientFile: |
| 83 | return transient_file_util_->sync_file_util(); |
[email protected] | 25b69799 | 2013-01-29 07:10:05 | [diff] [blame] | 84 | default: |
| 85 | NOTREACHED(); |
| 86 | } |
| 87 | return NULL; |
| 88 | } |
| 89 | |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 90 | AsyncFileUtil* IsolatedFileSystemBackend::GetAsyncFileUtil( |
[email protected] | 25b69799 | 2013-01-29 07:10:05 | [diff] [blame] | 91 | FileSystemType type) { |
| 92 | switch (type) { |
| 93 | case kFileSystemTypeNativeLocal: |
[email protected] | 6ef35d6 | 2012-08-02 02:55:28 | [diff] [blame] | 94 | return isolated_file_util_.get(); |
| 95 | case kFileSystemTypeDragged: |
| 96 | return dragged_file_util_.get(); |
[email protected] | b258286 | 2013-05-14 08:50:18 | [diff] [blame] | 97 | case kFileSystemTypeForTransientFile: |
| 98 | return transient_file_util_.get(); |
[email protected] | 9fb9294a | 2012-08-21 14:55:37 | [diff] [blame] | 99 | default: |
[email protected] | 6ef35d6 | 2012-08-02 02:55:28 | [diff] [blame] | 100 | NOTREACHED(); |
| 101 | } |
| 102 | return NULL; |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 103 | } |
| 104 | |
[email protected] | 98407ee | 2013-04-04 08:52:17 | [diff] [blame] | 105 | CopyOrMoveFileValidatorFactory* |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 106 | IsolatedFileSystemBackend::GetCopyOrMoveFileValidatorFactory( |
[email protected] | 98407ee | 2013-04-04 08:52:17 | [diff] [blame] | 107 | FileSystemType type, base::PlatformFileError* error_code) { |
| 108 | DCHECK(error_code); |
| 109 | *error_code = base::PLATFORM_FILE_OK; |
[email protected] | 98407ee | 2013-04-04 08:52:17 | [diff] [blame] | 110 | return NULL; |
| 111 | } |
| 112 | |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 113 | FileSystemOperation* IsolatedFileSystemBackend::CreateFileSystemOperation( |
[email protected] | 949f25a | 2012-06-27 01:53:09 | [diff] [blame] | 114 | const FileSystemURL& url, |
[email protected] | d23a00cc | 2012-09-11 17:38:13 | [diff] [blame] | 115 | FileSystemContext* context, |
| 116 | base::PlatformFileError* error_code) const { |
[email protected] | 61b48e0 | 2013-08-01 15:00:10 | [diff] [blame] | 117 | return new FileSystemOperationImpl( |
[email protected] | 5dfa47c | 2013-06-10 04:57:15 | [diff] [blame] | 118 | url, context, make_scoped_ptr(new FileSystemOperationContext(context))); |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 119 | } |
| 120 | |
[email protected] | 3ee9eb0 | 2013-04-10 09:17:05 | [diff] [blame] | 121 | scoped_ptr<webkit_blob::FileStreamReader> |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 122 | IsolatedFileSystemBackend::CreateFileStreamReader( |
[email protected] | 949f25a | 2012-06-27 01:53:09 | [diff] [blame] | 123 | const FileSystemURL& url, |
[email protected] | ad117b1 | 2012-04-19 05:40:19 | [diff] [blame] | 124 | int64 offset, |
[email protected] | a105783 | 2012-10-15 13:28:06 | [diff] [blame] | 125 | const base::Time& expected_modification_time, |
[email protected] | ad117b1 | 2012-04-19 05:40:19 | [diff] [blame] | 126 | FileSystemContext* context) const { |
[email protected] | 3ee9eb0 | 2013-04-10 09:17:05 | [diff] [blame] | 127 | return scoped_ptr<webkit_blob::FileStreamReader>( |
| 128 | new webkit_blob::LocalFileStreamReader( |
[email protected] | 8dd68f8 | 2013-08-04 08:02:44 | [diff] [blame^] | 129 | context->default_file_task_runner(), |
[email protected] | 3ee9eb0 | 2013-04-10 09:17:05 | [diff] [blame] | 130 | url.path(), offset, expected_modification_time)); |
[email protected] | ad117b1 | 2012-04-19 05:40:19 | [diff] [blame] | 131 | } |
| 132 | |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 133 | scoped_ptr<FileStreamWriter> IsolatedFileSystemBackend::CreateFileStreamWriter( |
[email protected] | 949f25a | 2012-06-27 01:53:09 | [diff] [blame] | 134 | const FileSystemURL& url, |
[email protected] | 7e84b91 | 2012-05-16 04:42:01 | [diff] [blame] | 135 | int64 offset, |
| 136 | FileSystemContext* context) const { |
[email protected] | b3d9012 | 2013-06-20 22:55:02 | [diff] [blame] | 137 | return scoped_ptr<FileStreamWriter>(new LocalFileStreamWriter( |
[email protected] | 8dd68f8 | 2013-08-04 08:02:44 | [diff] [blame^] | 138 | context->default_file_task_runner(), url.path(), offset)); |
[email protected] | 7e84b91 | 2012-05-16 04:42:01 | [diff] [blame] | 139 | } |
| 140 | |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 141 | FileSystemQuotaUtil* IsolatedFileSystemBackend::GetQuotaUtil() { |
[email protected] | 6faad82 | 2012-05-11 12:58:29 | [diff] [blame] | 142 | // No quota support. |
| 143 | return NULL; |
| 144 | } |
| 145 | |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 146 | } // namespace fileapi |