blob: 8c5542cee353b2cc5a340039ecd71d059b6e5136 [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"
10#include "base/file_path.h"
11#include "base/logging.h"
12#include "base/message_loop_proxy.h"
[email protected]2f9f5b492012-09-12 02:59:0613#include "base/platform_file.h"
[email protected]bcbd98d2012-05-07 04:10:1014#include "base/sequenced_task_runner.h"
[email protected]c4ca3b452012-05-31 03:15:4615#include "webkit/blob/local_file_stream_reader.h"
[email protected]6fe69652012-04-02 09:35:0516#include "webkit/fileapi/file_system_callback_dispatcher.h"
[email protected]bcbd98d2012-05-07 04:10:1017#include "webkit/fileapi/file_system_context.h"
[email protected]c4ca3b452012-05-31 03:15:4618#include "webkit/fileapi/file_system_file_stream_reader.h"
[email protected]dc57ec82012-08-07 03:50:1019#include "webkit/fileapi/file_system_task_runners.h"
[email protected]6fe69652012-04-02 09:35:0520#include "webkit/fileapi/file_system_types.h"
[email protected]ad117b12012-04-19 05:40:1921#include "webkit/fileapi/file_system_util.h"
[email protected]6fe69652012-04-02 09:35:0522#include "webkit/fileapi/isolated_context.h"
23#include "webkit/fileapi/isolated_file_util.h"
[email protected]7e836a3d2012-05-31 05:14:5924#include "webkit/fileapi/local_file_stream_writer.h"
[email protected]02a60542012-07-24 20:05:3325#include "webkit/fileapi/local_file_system_operation.h"
[email protected]cf4b6d62012-08-03 07:31:1226#include "webkit/fileapi/media/media_file_system_config.h"
[email protected]6ef35d62012-08-02 02:55:2827#include "webkit/fileapi/media/media_path_filter.h"
28#include "webkit/fileapi/media/native_media_file_util.h"
[email protected]6fe69652012-04-02 09:35:0529#include "webkit/fileapi/native_file_util.h"
30
[email protected]cf4b6d62012-08-03 07:31:1231#if defined(SUPPORT_MEDIA_FILESYSTEM)
32#include "webkit/fileapi/media/device_media_file_util.h"
33#include "webkit/fileapi/media/media_device_map_service.h"
34#endif
35
[email protected]6fe69652012-04-02 09:35:0536namespace fileapi {
37
[email protected]74698902012-06-12 12:16:3838namespace {
39
40IsolatedContext* isolated_context() {
41 return IsolatedContext::GetInstance();
42}
43
[email protected]74698902012-06-12 12:16:3844} // namespace
45
[email protected]cf4b6d62012-08-03 07:31:1246IsolatedMountPointProvider::IsolatedMountPointProvider(
47 const FilePath& profile_path)
48 : profile_path_(profile_path),
49 media_path_filter_(new MediaPathFilter()),
[email protected]6ef35d62012-08-02 02:55:2850 isolated_file_util_(new IsolatedFileUtil()),
51 dragged_file_util_(new DraggedFileUtil()),
52 native_media_file_util_(new NativeMediaFileUtil()) {
[email protected]cf4b6d62012-08-03 07:31:1253#if defined(SUPPORT_MEDIA_FILESYSTEM)
[email protected]2f9f5b492012-09-12 02:59:0654 // TODO(kmadhusu): Initialize |device_media_file_util_| in
55 // initialization list.
[email protected]cf4b6d62012-08-03 07:31:1256 device_media_file_util_.reset(new DeviceMediaFileUtil(profile_path_));
57#endif
[email protected]6fe69652012-04-02 09:35:0558}
59
60IsolatedMountPointProvider::~IsolatedMountPointProvider() {
61}
62
63void IsolatedMountPointProvider::ValidateFileSystemRoot(
64 const GURL& origin_url,
65 FileSystemType type,
66 bool create,
67 const ValidateFileSystemCallback& callback) {
68 // We never allow opening a new isolated FileSystem via usual OpenFileSystem.
69 base::MessageLoopProxy::current()->PostTask(
70 FROM_HERE,
71 base::Bind(callback, base::PLATFORM_FILE_ERROR_SECURITY));
72}
73
74FilePath IsolatedMountPointProvider::GetFileSystemRootPathOnFileThread(
75 const GURL& origin_url,
76 FileSystemType type,
77 const FilePath& virtual_path,
78 bool create) {
[email protected]d6afd112012-07-25 22:55:0479 // This is not supposed to be used.
80 NOTREACHED();
81 return FilePath();
[email protected]6fe69652012-04-02 09:35:0582}
83
[email protected]5aeeb7c62012-08-27 11:34:1384bool IsolatedMountPointProvider::IsAccessAllowed(const FileSystemURL& url) {
[email protected]d6afd112012-07-25 22:55:0485 return true;
[email protected]6fe69652012-04-02 09:35:0586}
87
88bool IsolatedMountPointProvider::IsRestrictedFileName(
89 const FilePath& filename) const {
[email protected]d6afd112012-07-25 22:55:0490 // TODO(kinuko): We need to check platform-specific restricted file names
91 // before we actually start allowing file creation in isolated file systems.
[email protected]6fe69652012-04-02 09:35:0592 return false;
93}
94
[email protected]d6afd112012-07-25 22:55:0495FileSystemFileUtil* IsolatedMountPointProvider::GetFileUtil(
96 FileSystemType type) {
[email protected]6ef35d62012-08-02 02:55:2897 switch (type) {
[email protected]9fb9294a2012-08-21 14:55:3798 case kFileSystemTypeNativeLocal:
[email protected]6ef35d62012-08-02 02:55:2899 return isolated_file_util_.get();
100 case kFileSystemTypeDragged:
101 return dragged_file_util_.get();
102 case kFileSystemTypeNativeMedia:
103 return native_media_file_util_.get();
[email protected]6ef35d62012-08-02 02:55:28104 case kFileSystemTypeDeviceMedia:
[email protected]cf4b6d62012-08-03 07:31:12105#if defined(SUPPORT_MEDIA_FILESYSTEM)
106 return device_media_file_util_.get();
107#endif
108
[email protected]9fb9294a2012-08-21 14:55:37109 default:
[email protected]6ef35d62012-08-02 02:55:28110 NOTREACHED();
111 }
112 return NULL;
[email protected]6fe69652012-04-02 09:35:05113}
114
115FilePath IsolatedMountPointProvider::GetPathForPermissionsCheck(
116 const FilePath& virtual_path) const {
[email protected]d6afd112012-07-25 22:55:04117 // For isolated filesystems we only check per-filesystem permissions.
[email protected]9fb9294a2012-08-21 14:55:37118 return FilePath();
[email protected]6fe69652012-04-02 09:35:05119}
120
[email protected]8e3bc3e2012-08-24 13:12:53121FileSystemOperation* IsolatedMountPointProvider::CreateFileSystemOperation(
[email protected]949f25a2012-06-27 01:53:09122 const FileSystemURL& url,
[email protected]d23a00cc2012-09-11 17:38:13123 FileSystemContext* context,
124 base::PlatformFileError* error_code) const {
[email protected]75af1a42012-07-26 04:06:20125 scoped_ptr<FileSystemOperationContext> operation_context(
126 new FileSystemOperationContext(context));
[email protected]2f9f5b492012-09-12 02:59:06127 if (url.type() == kFileSystemTypeNativeMedia) {
[email protected]6ef35d62012-08-02 02:55:28128 operation_context->set_media_path_filter(media_path_filter_.get());
[email protected]dc57ec82012-08-07 03:50:10129 operation_context->set_task_runner(
130 context->task_runners()->media_task_runner());
131 }
[email protected]cf4b6d62012-08-03 07:31:12132
133#if defined(SUPPORT_MEDIA_FILESYSTEM)
134 if (url.type() == kFileSystemTypeDeviceMedia) {
[email protected]2f9f5b492012-09-12 02:59:06135 MediaDeviceMapService* map_service = MediaDeviceMapService::GetInstance();
136 MediaDeviceDelegate* device_delegate =
137 map_service->GetMediaDeviceDelegate(url.filesystem_id());
138 if (!device_delegate) {
139 if (error_code)
140 *error_code = base::PLATFORM_FILE_ERROR_NOT_FOUND;
141 return NULL;
142 }
143 operation_context->set_media_device_delegate(device_delegate);
144 operation_context->set_task_runner(device_delegate->media_task_runner());
145 operation_context->set_media_path_filter(media_path_filter_.get());
[email protected]cf4b6d62012-08-03 07:31:12146 }
147#endif
148
[email protected]75af1a42012-07-26 04:06:20149 return new LocalFileSystemOperation(context, operation_context.Pass());
[email protected]6fe69652012-04-02 09:35:05150}
151
[email protected]c4ca3b452012-05-31 03:15:46152webkit_blob::FileStreamReader*
153IsolatedMountPointProvider::CreateFileStreamReader(
[email protected]949f25a2012-06-27 01:53:09154 const FileSystemURL& url,
[email protected]ad117b12012-04-19 05:40:19155 int64 offset,
[email protected]ad117b12012-04-19 05:40:19156 FileSystemContext* context) const {
[email protected]d6afd112012-07-25 22:55:04157 return new webkit_blob::LocalFileStreamReader(
[email protected]dc57ec82012-08-07 03:50:10158 context->task_runners()->file_task_runner(),
159 url.path(), offset, base::Time());
[email protected]ad117b12012-04-19 05:40:19160}
161
[email protected]7e836a3d2012-05-31 05:14:59162FileStreamWriter* IsolatedMountPointProvider::CreateFileStreamWriter(
[email protected]949f25a2012-06-27 01:53:09163 const FileSystemURL& url,
[email protected]7e84b912012-05-16 04:42:01164 int64 offset,
165 FileSystemContext* context) const {
[email protected]d6afd112012-07-25 22:55:04166 return new LocalFileStreamWriter(url.path(), offset);
[email protected]7e84b912012-05-16 04:42:01167}
168
[email protected]6faad822012-05-11 12:58:29169FileSystemQuotaUtil* IsolatedMountPointProvider::GetQuotaUtil() {
170 // No quota support.
171 return NULL;
172}
173
[email protected]d5e08552012-08-02 21:43:40174void IsolatedMountPointProvider::DeleteFileSystem(
175 const GURL& origin_url,
176 FileSystemType type,
177 FileSystemContext* context,
178 const DeleteFileSystemCallback& callback) {
179 NOTREACHED();
180 callback.Run(base::PLATFORM_FILE_ERROR_INVALID_OPERATION);
181}
182
[email protected]6fe69652012-04-02 09:35:05183} // namespace fileapi