blob: 7cba7370414205181cd314da9f28ffcdd2e18dd6 [file] [log] [blame]
[email protected]6fe69652012-04-02 09:35:051// 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]c671c8a2012-04-05 10:28:397#include <string>
8
[email protected]6fe69652012-04-02 09:35:059#include "base/bind.h"
[email protected]57999812013-02-24 05:40:5210#include "base/files/file_path.h"
[email protected]d2691962013-05-16 14:19:2711#include "base/files/file_util_proxy.h"
[email protected]6fe69652012-04-02 09:35:0512#include "base/logging.h"
13#include "base/message_loop_proxy.h"
[email protected]2f9f5b492012-09-12 02:59:0614#include "base/platform_file.h"
[email protected]fb441962013-05-08 05:35:2415#include "base/sequenced_task_runner.h"
[email protected]c4ca3b452012-05-31 03:15:4616#include "webkit/blob/local_file_stream_reader.h"
[email protected]25b697992013-01-29 07:10:0517#include "webkit/fileapi/async_file_util_adapter.h"
[email protected]98407ee2013-04-04 08:52:1718#include "webkit/fileapi/copy_or_move_file_validator.h"
[email protected]bcbd98d2012-05-07 04:10:1019#include "webkit/fileapi/file_system_context.h"
[email protected]c4ca3b452012-05-31 03:15:4620#include "webkit/fileapi/file_system_file_stream_reader.h"
[email protected]5f7782682013-03-04 02:43:3521#include "webkit/fileapi/file_system_operation_context.h"
[email protected]dc57ec82012-08-07 03:50:1022#include "webkit/fileapi/file_system_task_runners.h"
[email protected]6fe69652012-04-02 09:35:0523#include "webkit/fileapi/file_system_types.h"
[email protected]ad117b12012-04-19 05:40:1924#include "webkit/fileapi/file_system_util.h"
[email protected]6fe69652012-04-02 09:35:0525#include "webkit/fileapi/isolated_context.h"
26#include "webkit/fileapi/isolated_file_util.h"
[email protected]7e836a3d2012-05-31 05:14:5927#include "webkit/fileapi/local_file_stream_writer.h"
[email protected]02a60542012-07-24 20:05:3328#include "webkit/fileapi/local_file_system_operation.h"
[email protected]6fe69652012-04-02 09:35:0529#include "webkit/fileapi/native_file_util.h"
[email protected]b2582862013-05-14 08:50:1830#include "webkit/fileapi/transient_file_util.h"
[email protected]6fe69652012-04-02 09:35:0531
[email protected]6fe69652012-04-02 09:35:0532namespace fileapi {
33
[email protected]c3d638b32013-04-22 02:18:4934IsolatedMountPointProvider::IsolatedMountPointProvider()
35 : isolated_file_util_(new AsyncFileUtilAdapter(new IsolatedFileUtil())),
[email protected]b2582862013-05-14 08:50:1836 dragged_file_util_(new AsyncFileUtilAdapter(new DraggedFileUtil())),
37 transient_file_util_(new AsyncFileUtilAdapter(new TransientFileUtil())) {
[email protected]6fe69652012-04-02 09:35:0538}
39
40IsolatedMountPointProvider::~IsolatedMountPointProvider() {
41}
42
[email protected]420fb562013-04-18 01:46:3443bool IsolatedMountPointProvider::CanHandleType(FileSystemType type) const {
44 switch (type) {
45 case kFileSystemTypeIsolated:
46 case kFileSystemTypeDragged:
[email protected]b2582862013-05-14 08:50:1847 case kFileSystemTypeForTransientFile:
[email protected]420fb562013-04-18 01:46:3448 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]6fe69652012-04-02 09:35:0559void 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]a3ef4832013-02-02 05:12:3370base::FilePath IsolatedMountPointProvider::GetFileSystemRootPathOnFileThread(
[email protected]199263e2012-12-14 07:14:2071 const FileSystemURL& url,
[email protected]6fe69652012-04-02 09:35:0572 bool create) {
[email protected]d6afd112012-07-25 22:55:0473 // This is not supposed to be used.
74 NOTREACHED();
[email protected]a3ef4832013-02-02 05:12:3375 return base::FilePath();
[email protected]6fe69652012-04-02 09:35:0576}
77
[email protected]d6afd112012-07-25 22:55:0478FileSystemFileUtil* IsolatedMountPointProvider::GetFileUtil(
79 FileSystemType type) {
[email protected]6ef35d62012-08-02 02:55:2880 switch (type) {
[email protected]9fb9294a2012-08-21 14:55:3781 case kFileSystemTypeNativeLocal:
[email protected]25b697992013-01-29 07:10:0582 return isolated_file_util_->sync_file_util();
83 case kFileSystemTypeDragged:
84 return dragged_file_util_->sync_file_util();
[email protected]b2582862013-05-14 08:50:1885 case kFileSystemTypeForTransientFile:
86 return transient_file_util_->sync_file_util();
[email protected]25b697992013-01-29 07:10:0587 default:
88 NOTREACHED();
89 }
90 return NULL;
91}
92
93AsyncFileUtil* IsolatedMountPointProvider::GetAsyncFileUtil(
94 FileSystemType type) {
95 switch (type) {
96 case kFileSystemTypeNativeLocal:
[email protected]6ef35d62012-08-02 02:55:2897 return isolated_file_util_.get();
98 case kFileSystemTypeDragged:
99 return dragged_file_util_.get();
[email protected]b2582862013-05-14 08:50:18100 case kFileSystemTypeForTransientFile:
101 return transient_file_util_.get();
[email protected]9fb9294a2012-08-21 14:55:37102 default:
[email protected]6ef35d62012-08-02 02:55:28103 NOTREACHED();
104 }
105 return NULL;
[email protected]6fe69652012-04-02 09:35:05106}
107
[email protected]98407ee2013-04-04 08:52:17108CopyOrMoveFileValidatorFactory*
109IsolatedMountPointProvider::GetCopyOrMoveFileValidatorFactory(
110 FileSystemType type, base::PlatformFileError* error_code) {
111 DCHECK(error_code);
112 *error_code = base::PLATFORM_FILE_OK;
[email protected]98407ee2013-04-04 08:52:17113 return NULL;
114}
115
116void IsolatedMountPointProvider::InitializeCopyOrMoveFileValidatorFactory(
117 FileSystemType type,
118 scoped_ptr<CopyOrMoveFileValidatorFactory> factory) {
[email protected]c3d638b32013-04-22 02:18:49119 DCHECK(!factory);
[email protected]98407ee2013-04-04 08:52:17120}
121
[email protected]b40ffe72013-01-10 04:05:31122FilePermissionPolicy 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]4d038592013-02-18 16:50:23126 if (permissions & ~fileapi::kReadFilePermissions)
[email protected]b40ffe72013-01-10 04:05:31127 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]6fe69652012-04-02 09:35:05132}
133
[email protected]8e3bc3e2012-08-24 13:12:53134FileSystemOperation* IsolatedMountPointProvider::CreateFileSystemOperation(
[email protected]949f25a2012-06-27 01:53:09135 const FileSystemURL& url,
[email protected]d23a00cc2012-09-11 17:38:13136 FileSystemContext* context,
137 base::PlatformFileError* error_code) const {
[email protected]c3d638b32013-04-22 02:18:49138 return new LocalFileSystemOperation(
139 context, make_scoped_ptr(new FileSystemOperationContext(context)));
[email protected]6fe69652012-04-02 09:35:05140}
141
[email protected]3ee9eb02013-04-10 09:17:05142scoped_ptr<webkit_blob::FileStreamReader>
[email protected]c4ca3b452012-05-31 03:15:46143IsolatedMountPointProvider::CreateFileStreamReader(
[email protected]949f25a2012-06-27 01:53:09144 const FileSystemURL& url,
[email protected]ad117b12012-04-19 05:40:19145 int64 offset,
[email protected]a1057832012-10-15 13:28:06146 const base::Time& expected_modification_time,
[email protected]ad117b12012-04-19 05:40:19147 FileSystemContext* context) const {
[email protected]3ee9eb02013-04-10 09:17:05148 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]ad117b12012-04-19 05:40:19152}
153
[email protected]3ee9eb02013-04-10 09:17:05154scoped_ptr<FileStreamWriter> IsolatedMountPointProvider::CreateFileStreamWriter(
[email protected]949f25a2012-06-27 01:53:09155 const FileSystemURL& url,
[email protected]7e84b912012-05-16 04:42:01156 int64 offset,
157 FileSystemContext* context) const {
[email protected]3ee9eb02013-04-10 09:17:05158 return scoped_ptr<FileStreamWriter>(
159 new LocalFileStreamWriter(url.path(), offset));
[email protected]7e84b912012-05-16 04:42:01160}
161
[email protected]6faad822012-05-11 12:58:29162FileSystemQuotaUtil* IsolatedMountPointProvider::GetQuotaUtil() {
163 // No quota support.
164 return NULL;
165}
166
[email protected]d5e08552012-08-02 21:43:40167void 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]6fe69652012-04-02 09:35:05176} // namespace fileapi