| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "webkit/fileapi/isolated_mount_point_provider.h" | 5 #include "webkit/fileapi/isolated_mount_point_provider.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/message_loop_proxy.h" | 12 #include "base/message_loop_proxy.h" |
| 13 #include "base/sequenced_task_runner.h" | 13 #include "base/sequenced_task_runner.h" |
| 14 #include "webkit/blob/local_file_stream_reader.h" | 14 #include "webkit/blob/local_file_stream_reader.h" |
| 15 #include "webkit/fileapi/file_system_callback_dispatcher.h" | 15 #include "webkit/fileapi/file_system_callback_dispatcher.h" |
| 16 #include "webkit/fileapi/file_system_context.h" | 16 #include "webkit/fileapi/file_system_context.h" |
| 17 #include "webkit/fileapi/file_system_file_stream_reader.h" | 17 #include "webkit/fileapi/file_system_file_stream_reader.h" |
| 18 #include "webkit/fileapi/file_system_types.h" | 18 #include "webkit/fileapi/file_system_types.h" |
| 19 #include "webkit/fileapi/file_system_util.h" | 19 #include "webkit/fileapi/file_system_util.h" |
| 20 #include "webkit/fileapi/isolated_context.h" | 20 #include "webkit/fileapi/isolated_context.h" |
| 21 #include "webkit/fileapi/isolated_file_util.h" | 21 #include "webkit/fileapi/isolated_file_util.h" |
| 22 #include "webkit/fileapi/local_file_stream_writer.h" | 22 #include "webkit/fileapi/local_file_stream_writer.h" |
| 23 #include "webkit/fileapi/local_file_system_operation.h" | 23 #include "webkit/fileapi/local_file_system_operation.h" |
| 24 #include "webkit/fileapi/media/media_file_system_config.h" |
| 24 #include "webkit/fileapi/native_file_util.h" | 25 #include "webkit/fileapi/native_file_util.h" |
| 25 | 26 |
| 27 #if defined(SUPPORT_MEDIA_FILESYSTEM) |
| 28 #include "webkit/fileapi/media/device_media_file_util.h" |
| 29 #include "webkit/fileapi/media/media_device_map_service.h" |
| 30 #endif |
| 31 |
| 26 namespace fileapi { | 32 namespace fileapi { |
| 27 | 33 |
| 28 namespace { | 34 namespace { |
| 29 | 35 |
| 30 IsolatedContext* isolated_context() { | 36 IsolatedContext* isolated_context() { |
| 31 return IsolatedContext::GetInstance(); | 37 return IsolatedContext::GetInstance(); |
| 32 } | 38 } |
| 33 | 39 |
| 40 #if defined(SUPPORT_MEDIA_FILESYSTEM) |
| 41 bool GetDeviceForUrl(const FileSystemURL& url, |
| 42 FileSystemContext* context, |
| 43 scoped_refptr<MediaDeviceInterfaceImpl>* device) { |
| 44 |
| 45 FilePath root_path; |
| 46 if (!isolated_context()->GetRegisteredPath(url.filesystem_id(), &root_path)) |
| 47 return false; |
| 48 |
| 49 // Add the media device if required. |
| 50 MediaDeviceMapService::GetInstance()->AddMediaDevice( |
| 51 root_path.value(), context->file_task_runner()); |
| 52 |
| 53 return MediaDeviceMapService::GetInstance()->GetMediaDevice(root_path.value(), |
| 54 device); |
| 55 } |
| 56 #endif |
| 57 |
| 34 } // namespace | 58 } // namespace |
| 35 | 59 |
| 36 IsolatedMountPointProvider::IsolatedMountPointProvider() | 60 IsolatedMountPointProvider::IsolatedMountPointProvider() |
| 37 : isolated_file_util_(new IsolatedFileUtil()), | 61 : isolated_file_util_(new IsolatedFileUtil()), |
| 38 dragged_file_util_(new DraggedFileUtil()) { | 62 dragged_file_util_(new DraggedFileUtil()) { |
| 63 // TODO(kmadhusu): Initialize device_media_file_util_ in initialization list. |
| 64 #if defined(SUPPORT_MEDIA_FILESYSTEM) |
| 65 device_media_file_util_.reset(new DeviceMediaFileUtil); |
| 66 #endif |
| 39 } | 67 } |
| 40 | 68 |
| 41 IsolatedMountPointProvider::~IsolatedMountPointProvider() { | 69 IsolatedMountPointProvider::~IsolatedMountPointProvider() { |
| 42 } | 70 } |
| 43 | 71 |
| 44 void IsolatedMountPointProvider::ValidateFileSystemRoot( | 72 void IsolatedMountPointProvider::ValidateFileSystemRoot( |
| 45 const GURL& origin_url, | 73 const GURL& origin_url, |
| 46 FileSystemType type, | 74 FileSystemType type, |
| 47 bool create, | 75 bool create, |
| 48 const ValidateFileSystemCallback& callback) { | 76 const ValidateFileSystemCallback& callback) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 71 const FilePath& filename) const { | 99 const FilePath& filename) const { |
| 72 // TODO(kinuko): We need to check platform-specific restricted file names | 100 // TODO(kinuko): We need to check platform-specific restricted file names |
| 73 // before we actually start allowing file creation in isolated file systems. | 101 // before we actually start allowing file creation in isolated file systems. |
| 74 return false; | 102 return false; |
| 75 } | 103 } |
| 76 | 104 |
| 77 FileSystemFileUtil* IsolatedMountPointProvider::GetFileUtil( | 105 FileSystemFileUtil* IsolatedMountPointProvider::GetFileUtil( |
| 78 FileSystemType type) { | 106 FileSystemType type) { |
| 79 if (type == kFileSystemTypeDragged) | 107 if (type == kFileSystemTypeDragged) |
| 80 return dragged_file_util_.get(); | 108 return dragged_file_util_.get(); |
| 109 #if defined(SUPPORT_MEDIA_FILESYSTEM) |
| 110 else if (type == kFileSystemTypeDeviceMedia) |
| 111 return device_media_file_util_.get(); |
| 112 #endif |
| 81 else | 113 else |
| 82 return isolated_file_util_.get(); | 114 return isolated_file_util_.get(); |
| 83 } | 115 } |
| 84 | 116 |
| 85 FilePath IsolatedMountPointProvider::GetPathForPermissionsCheck( | 117 FilePath IsolatedMountPointProvider::GetPathForPermissionsCheck( |
| 86 const FilePath& virtual_path) const { | 118 const FilePath& virtual_path) const { |
| 87 // For isolated filesystems we only check per-filesystem permissions. | 119 // For isolated filesystems we only check per-filesystem permissions. |
| 88 NOTREACHED(); | 120 NOTREACHED(); |
| 89 return virtual_path; | 121 return virtual_path; |
| 90 } | 122 } |
| 91 | 123 |
| 92 FileSystemOperationInterface* | 124 FileSystemOperationInterface* |
| 93 IsolatedMountPointProvider::CreateFileSystemOperation( | 125 IsolatedMountPointProvider::CreateFileSystemOperation( |
| 94 const FileSystemURL& url, | 126 const FileSystemURL& url, |
| 95 FileSystemContext* context) const { | 127 FileSystemContext* context) const { |
| 96 scoped_ptr<FileSystemOperationContext> operation_context( | 128 scoped_ptr<FileSystemOperationContext> operation_context( |
| 97 new FileSystemOperationContext(context)); | 129 new FileSystemOperationContext(context)); |
| 130 |
| 131 #if defined(SUPPORT_MEDIA_FILESYSTEM) |
| 132 if (url.type() == kFileSystemTypeDeviceMedia) { |
| 133 scoped_refptr<MediaDeviceInterfaceImpl> device; |
| 134 if (GetDeviceForUrl(url, context, &device)) |
| 135 operation_context->set_media_device(device); |
| 136 } |
| 137 #endif |
| 138 |
| 98 return new LocalFileSystemOperation(context, operation_context.Pass()); | 139 return new LocalFileSystemOperation(context, operation_context.Pass()); |
| 99 } | 140 } |
| 100 | 141 |
| 101 webkit_blob::FileStreamReader* | 142 webkit_blob::FileStreamReader* |
| 102 IsolatedMountPointProvider::CreateFileStreamReader( | 143 IsolatedMountPointProvider::CreateFileStreamReader( |
| 103 const FileSystemURL& url, | 144 const FileSystemURL& url, |
| 104 int64 offset, | 145 int64 offset, |
| 105 FileSystemContext* context) const { | 146 FileSystemContext* context) const { |
| 106 return new webkit_blob::LocalFileStreamReader( | 147 return new webkit_blob::LocalFileStreamReader( |
| 107 context->file_task_runner(), url.path(), offset, base::Time()); | 148 context->file_task_runner(), url.path(), offset, base::Time()); |
| 108 } | 149 } |
| 109 | 150 |
| 110 FileStreamWriter* IsolatedMountPointProvider::CreateFileStreamWriter( | 151 FileStreamWriter* IsolatedMountPointProvider::CreateFileStreamWriter( |
| 111 const FileSystemURL& url, | 152 const FileSystemURL& url, |
| 112 int64 offset, | 153 int64 offset, |
| 113 FileSystemContext* context) const { | 154 FileSystemContext* context) const { |
| 114 return new LocalFileStreamWriter(url.path(), offset); | 155 return new LocalFileStreamWriter(url.path(), offset); |
| 115 } | 156 } |
| 116 | 157 |
| 117 FileSystemQuotaUtil* IsolatedMountPointProvider::GetQuotaUtil() { | 158 FileSystemQuotaUtil* IsolatedMountPointProvider::GetQuotaUtil() { |
| 118 // No quota support. | 159 // No quota support. |
| 119 return NULL; | 160 return NULL; |
| 120 } | 161 } |
| 121 | 162 |
| 122 } // namespace fileapi | 163 } // namespace fileapi |
| OLD | NEW |