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