blob: af99b0aaca51a5e76a4aceb134eb14779d0a9906 [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]bcbd98d2012-05-07 04:10:1013#include "base/sequenced_task_runner.h"
[email protected]c4ca3b452012-05-31 03:15:4614#include "webkit/blob/local_file_stream_reader.h"
[email protected]6fe69652012-04-02 09:35:0515#include "webkit/fileapi/file_system_callback_dispatcher.h"
[email protected]bcbd98d2012-05-07 04:10:1016#include "webkit/fileapi/file_system_context.h"
[email protected]c4ca3b452012-05-31 03:15:4617#include "webkit/fileapi/file_system_file_stream_reader.h"
[email protected]dc57ec82012-08-07 03:50:1018#include "webkit/fileapi/file_system_task_runners.h"
[email protected]6fe69652012-04-02 09:35:0519#include "webkit/fileapi/file_system_types.h"
[email protected]ad117b12012-04-19 05:40:1920#include "webkit/fileapi/file_system_util.h"
[email protected]6fe69652012-04-02 09:35:0521#include "webkit/fileapi/isolated_context.h"
22#include "webkit/fileapi/isolated_file_util.h"
[email protected]7e836a3d2012-05-31 05:14:5923#include "webkit/fileapi/local_file_stream_writer.h"
[email protected]02a60542012-07-24 20:05:3324#include "webkit/fileapi/local_file_system_operation.h"
[email protected]cf4b6d62012-08-03 07:31:1225#include "webkit/fileapi/media/media_file_system_config.h"
[email protected]6ef35d62012-08-02 02:55:2826#include "webkit/fileapi/media/media_path_filter.h"
27#include "webkit/fileapi/media/native_media_file_util.h"
[email protected]6fe69652012-04-02 09:35:0528#include "webkit/fileapi/native_file_util.h"
29
[email protected]cf4b6d62012-08-03 07:31:1230#if defined(SUPPORT_MEDIA_FILESYSTEM)
31#include "webkit/fileapi/media/device_media_file_util.h"
32#include "webkit/fileapi/media/media_device_map_service.h"
33#endif
34
[email protected]6fe69652012-04-02 09:35:0535namespace fileapi {
36
[email protected]74698902012-06-12 12:16:3837namespace {
38
39IsolatedContext* isolated_context() {
40 return IsolatedContext::GetInstance();
41}
42
[email protected]cf4b6d62012-08-03 07:31:1243#if defined(SUPPORT_MEDIA_FILESYSTEM)
44MediaDeviceInterfaceImpl* GetDeviceForUrl(const FileSystemURL& url,
45 FileSystemContext* context) {
46 return MediaDeviceMapService::GetInstance()->CreateOrGetMediaDevice(
[email protected]dc57ec82012-08-07 03:50:1047 url.filesystem_id(), context->task_runners()->media_task_runner());
[email protected]cf4b6d62012-08-03 07:31:1248}
49#endif
50
[email protected]74698902012-06-12 12:16:3851} // namespace
52
[email protected]cf4b6d62012-08-03 07:31:1253IsolatedMountPointProvider::IsolatedMountPointProvider(
54 const FilePath& profile_path)
55 : profile_path_(profile_path),
56 media_path_filter_(new MediaPathFilter()),
[email protected]6ef35d62012-08-02 02:55:2857 isolated_file_util_(new IsolatedFileUtil()),
58 dragged_file_util_(new DraggedFileUtil()),
59 native_media_file_util_(new NativeMediaFileUtil()) {
[email protected]cf4b6d62012-08-03 07:31:1260 // TODO(kmadhusu): Initialize device_media_file_util_ in initialization list.
61#if defined(SUPPORT_MEDIA_FILESYSTEM)
62 device_media_file_util_.reset(new DeviceMediaFileUtil(profile_path_));
63#endif
[email protected]6fe69652012-04-02 09:35:0564}
65
66IsolatedMountPointProvider::~IsolatedMountPointProvider() {
67}
68
69void IsolatedMountPointProvider::ValidateFileSystemRoot(
70 const GURL& origin_url,
71 FileSystemType type,
72 bool create,
73 const ValidateFileSystemCallback& callback) {
74 // We never allow opening a new isolated FileSystem via usual OpenFileSystem.
75 base::MessageLoopProxy::current()->PostTask(
76 FROM_HERE,
77 base::Bind(callback, base::PLATFORM_FILE_ERROR_SECURITY));
78}
79
80FilePath IsolatedMountPointProvider::GetFileSystemRootPathOnFileThread(
81 const GURL& origin_url,
82 FileSystemType type,
83 const FilePath& virtual_path,
84 bool create) {
[email protected]d6afd112012-07-25 22:55:0485 // This is not supposed to be used.
86 NOTREACHED();
87 return FilePath();
[email protected]6fe69652012-04-02 09:35:0588}
89
[email protected]5aeeb7c62012-08-27 11:34:1390bool IsolatedMountPointProvider::IsAccessAllowed(const FileSystemURL& url) {
[email protected]d6afd112012-07-25 22:55:0491 return true;
[email protected]6fe69652012-04-02 09:35:0592}
93
94bool IsolatedMountPointProvider::IsRestrictedFileName(
95 const FilePath& filename) const {
[email protected]d6afd112012-07-25 22:55:0496 // TODO(kinuko): We need to check platform-specific restricted file names
97 // before we actually start allowing file creation in isolated file systems.
[email protected]6fe69652012-04-02 09:35:0598 return false;
99}
100
[email protected]d6afd112012-07-25 22:55:04101FileSystemFileUtil* IsolatedMountPointProvider::GetFileUtil(
102 FileSystemType type) {
[email protected]6ef35d62012-08-02 02:55:28103 switch (type) {
[email protected]9fb9294a2012-08-21 14:55:37104 case kFileSystemTypeNativeLocal:
[email protected]6ef35d62012-08-02 02:55:28105 return isolated_file_util_.get();
106 case kFileSystemTypeDragged:
107 return dragged_file_util_.get();
108 case kFileSystemTypeNativeMedia:
109 return native_media_file_util_.get();
[email protected]6ef35d62012-08-02 02:55:28110 case kFileSystemTypeDeviceMedia:
[email protected]cf4b6d62012-08-03 07:31:12111#if defined(SUPPORT_MEDIA_FILESYSTEM)
112 return device_media_file_util_.get();
113#endif
114
[email protected]9fb9294a2012-08-21 14:55:37115 default:
[email protected]6ef35d62012-08-02 02:55:28116 NOTREACHED();
117 }
118 return NULL;
[email protected]6fe69652012-04-02 09:35:05119}
120
121FilePath IsolatedMountPointProvider::GetPathForPermissionsCheck(
122 const FilePath& virtual_path) const {
[email protected]d6afd112012-07-25 22:55:04123 // For isolated filesystems we only check per-filesystem permissions.
[email protected]9fb9294a2012-08-21 14:55:37124 return FilePath();
[email protected]6fe69652012-04-02 09:35:05125}
126
[email protected]8e3bc3e2012-08-24 13:12:53127FileSystemOperation* IsolatedMountPointProvider::CreateFileSystemOperation(
[email protected]949f25a2012-06-27 01:53:09128 const FileSystemURL& url,
[email protected]d23a00cc2012-09-11 17:38:13129 FileSystemContext* context,
130 base::PlatformFileError* error_code) const {
[email protected]75af1a42012-07-26 04:06:20131 scoped_ptr<FileSystemOperationContext> operation_context(
132 new FileSystemOperationContext(context));
[email protected]6ef35d62012-08-02 02:55:28133 if (url.type() == kFileSystemTypeNativeMedia ||
[email protected]dc57ec82012-08-07 03:50:10134 url.type() == kFileSystemTypeDeviceMedia) {
[email protected]6ef35d62012-08-02 02:55:28135 operation_context->set_media_path_filter(media_path_filter_.get());
[email protected]dc57ec82012-08-07 03:50:10136 operation_context->set_task_runner(
137 context->task_runners()->media_task_runner());
138 }
[email protected]cf4b6d62012-08-03 07:31:12139
140#if defined(SUPPORT_MEDIA_FILESYSTEM)
141 if (url.type() == kFileSystemTypeDeviceMedia) {
142 // GetDeviceForUrl can return NULL. We will handle in DeviceMediaFileUtil.
143 operation_context->set_media_device(GetDeviceForUrl(url, context));
144 }
145#endif
146
[email protected]75af1a42012-07-26 04:06:20147 return new LocalFileSystemOperation(context, operation_context.Pass());
[email protected]6fe69652012-04-02 09:35:05148}
149
[email protected]c4ca3b452012-05-31 03:15:46150webkit_blob::FileStreamReader*
151IsolatedMountPointProvider::CreateFileStreamReader(
[email protected]949f25a2012-06-27 01:53:09152 const FileSystemURL& url,
[email protected]ad117b12012-04-19 05:40:19153 int64 offset,
[email protected]ad117b12012-04-19 05:40:19154 FileSystemContext* context) const {
[email protected]d6afd112012-07-25 22:55:04155 return new webkit_blob::LocalFileStreamReader(
[email protected]dc57ec82012-08-07 03:50:10156 context->task_runners()->file_task_runner(),
157 url.path(), offset, base::Time());
[email protected]ad117b12012-04-19 05:40:19158}
159
[email protected]7e836a3d2012-05-31 05:14:59160FileStreamWriter* IsolatedMountPointProvider::CreateFileStreamWriter(
[email protected]949f25a2012-06-27 01:53:09161 const FileSystemURL& url,
[email protected]7e84b912012-05-16 04:42:01162 int64 offset,
163 FileSystemContext* context) const {
[email protected]d6afd112012-07-25 22:55:04164 return new LocalFileStreamWriter(url.path(), offset);
[email protected]7e84b912012-05-16 04:42:01165}
166
[email protected]6faad822012-05-11 12:58:29167FileSystemQuotaUtil* IsolatedMountPointProvider::GetQuotaUtil() {
168 // No quota support.
169 return NULL;
170}
171
[email protected]d5e08552012-08-02 21:43:40172void IsolatedMountPointProvider::DeleteFileSystem(
173 const GURL& origin_url,
174 FileSystemType type,
175 FileSystemContext* context,
176 const DeleteFileSystemCallback& callback) {
177 NOTREACHED();
178 callback.Run(base::PLATFORM_FILE_ERROR_INVALID_OPERATION);
179}
180
[email protected]6fe69652012-04-02 09:35:05181} // namespace fileapi