| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/media/media_file_system_mount_point_provider.h" | 5 #include "chrome/browser/media_galleries/fileapi/media_file_system_mount_point_p
rovider.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/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/platform_file.h" | 13 #include "base/platform_file.h" |
| 14 #include "base/sequenced_task_runner.h" | 14 #include "base/sequenced_task_runner.h" |
| 15 #include "chrome/browser/media_galleries/fileapi/media_path_filter.h" |
| 16 #include "chrome/browser/media_galleries/fileapi/native_media_file_util.h" |
| 15 #include "webkit/blob/local_file_stream_reader.h" | 17 #include "webkit/blob/local_file_stream_reader.h" |
| 16 #include "webkit/fileapi/async_file_util_adapter.h" | 18 #include "webkit/fileapi/async_file_util_adapter.h" |
| 17 #include "webkit/fileapi/copy_or_move_file_validator.h" | 19 #include "webkit/fileapi/copy_or_move_file_validator.h" |
| 18 #include "webkit/fileapi/file_system_callback_dispatcher.h" | 20 #include "webkit/fileapi/file_system_callback_dispatcher.h" |
| 19 #include "webkit/fileapi/file_system_context.h" | 21 #include "webkit/fileapi/file_system_context.h" |
| 20 #include "webkit/fileapi/file_system_file_stream_reader.h" | 22 #include "webkit/fileapi/file_system_file_stream_reader.h" |
| 21 #include "webkit/fileapi/file_system_operation_context.h" | 23 #include "webkit/fileapi/file_system_operation_context.h" |
| 22 #include "webkit/fileapi/file_system_task_runners.h" | 24 #include "webkit/fileapi/file_system_task_runners.h" |
| 23 #include "webkit/fileapi/file_system_types.h" | 25 #include "webkit/fileapi/file_system_types.h" |
| 24 #include "webkit/fileapi/file_system_util.h" | 26 #include "webkit/fileapi/file_system_util.h" |
| 25 #include "webkit/fileapi/isolated_context.h" | 27 #include "webkit/fileapi/isolated_context.h" |
| 26 #include "webkit/fileapi/isolated_file_util.h" | 28 #include "webkit/fileapi/isolated_file_util.h" |
| 27 #include "webkit/fileapi/local_file_stream_writer.h" | 29 #include "webkit/fileapi/local_file_stream_writer.h" |
| 28 #include "webkit/fileapi/local_file_system_operation.h" | 30 #include "webkit/fileapi/local_file_system_operation.h" |
| 29 #include "webkit/fileapi/media/media_path_filter.h" | |
| 30 #include "webkit/fileapi/media/native_media_file_util.h" | |
| 31 #include "webkit/fileapi/native_file_util.h" | 31 #include "webkit/fileapi/native_file_util.h" |
| 32 | 32 |
| 33 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) | 33 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) |
| 34 #include "webkit/fileapi/media/device_media_async_file_util.h" | 34 #include "chrome/browser/media_galleries/fileapi/device_media_async_file_util.h" |
| 35 #endif | 35 #endif |
| 36 | 36 |
| 37 namespace fileapi { | 37 using fileapi::FileSystemContext; |
| 38 using fileapi::FileSystemType; |
| 39 using fileapi::FileSystemURL; |
| 40 |
| 41 namespace chrome { |
| 38 | 42 |
| 39 const char MediaFileSystemMountPointProvider::kMediaPathFilterKey[] = | 43 const char MediaFileSystemMountPointProvider::kMediaPathFilterKey[] = |
| 40 "MediaPathFilterKey"; | 44 "MediaPathFilterKey"; |
| 41 const char MediaFileSystemMountPointProvider::kMTPDeviceDelegateURLKey[] = | 45 const char MediaFileSystemMountPointProvider::kMTPDeviceDelegateURLKey[] = |
| 42 "MTPDeviceDelegateKey"; | 46 "MTPDeviceDelegateKey"; |
| 43 | 47 |
| 44 MediaFileSystemMountPointProvider::MediaFileSystemMountPointProvider( | 48 MediaFileSystemMountPointProvider::MediaFileSystemMountPointProvider( |
| 45 const base::FilePath& profile_path) | 49 const base::FilePath& profile_path) |
| 46 : profile_path_(profile_path), | 50 : profile_path_(profile_path), |
| 47 media_path_filter_(new MediaPathFilter()), | 51 media_path_filter_(new MediaPathFilter()), |
| 48 native_media_file_util_( | 52 native_media_file_util_( |
| 49 new AsyncFileUtilAdapter(new NativeMediaFileUtil())) { | 53 new fileapi::AsyncFileUtilAdapter(new NativeMediaFileUtil())) { |
| 50 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) | 54 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) |
| 51 // TODO(kmadhusu): Initialize |device_media_file_util_| in | 55 // TODO(kmadhusu): Initialize |device_media_file_util_| in |
| 52 // initialization list. | 56 // initialization list. |
| 53 device_media_async_file_util_.reset( | 57 device_media_async_file_util_.reset( |
| 54 DeviceMediaAsyncFileUtil::Create(profile_path_)); | 58 DeviceMediaAsyncFileUtil::Create(profile_path_)); |
| 55 #endif | 59 #endif |
| 56 } | 60 } |
| 57 | 61 |
| 58 MediaFileSystemMountPointProvider::~MediaFileSystemMountPointProvider() { | 62 MediaFileSystemMountPointProvider::~MediaFileSystemMountPointProvider() { |
| 59 } | 63 } |
| 60 | 64 |
| 61 bool MediaFileSystemMountPointProvider::CanHandleType( | 65 bool MediaFileSystemMountPointProvider::CanHandleType( |
| 62 FileSystemType type) const { | 66 FileSystemType type) const { |
| 63 switch (type) { | 67 switch (type) { |
| 64 case kFileSystemTypeNativeMedia: | 68 case fileapi::kFileSystemTypeNativeMedia: |
| 65 case kFileSystemTypeDeviceMedia: | 69 case fileapi::kFileSystemTypeDeviceMedia: |
| 66 return true; | 70 return true; |
| 67 default: | 71 default: |
| 68 return false; | 72 return false; |
| 69 } | 73 } |
| 70 } | 74 } |
| 71 | 75 |
| 72 void MediaFileSystemMountPointProvider::ValidateFileSystemRoot( | 76 void MediaFileSystemMountPointProvider::ValidateFileSystemRoot( |
| 73 const GURL& origin_url, | 77 const GURL& origin_url, |
| 74 FileSystemType type, | 78 FileSystemType type, |
| 75 bool create, | 79 bool create, |
| 76 const ValidateFileSystemCallback& callback) { | 80 const ValidateFileSystemCallback& callback) { |
| 77 // We never allow opening a new isolated FileSystem via usual OpenFileSystem. | 81 // We never allow opening a new isolated FileSystem via usual OpenFileSystem. |
| 78 base::MessageLoopProxy::current()->PostTask( | 82 base::MessageLoopProxy::current()->PostTask( |
| 79 FROM_HERE, | 83 FROM_HERE, |
| 80 base::Bind(callback, base::PLATFORM_FILE_ERROR_SECURITY)); | 84 base::Bind(callback, base::PLATFORM_FILE_ERROR_SECURITY)); |
| 81 } | 85 } |
| 82 | 86 |
| 83 base::FilePath | 87 base::FilePath |
| 84 MediaFileSystemMountPointProvider::GetFileSystemRootPathOnFileThread( | 88 MediaFileSystemMountPointProvider::GetFileSystemRootPathOnFileThread( |
| 85 const FileSystemURL& url, | 89 const FileSystemURL& url, |
| 86 bool create) { | 90 bool create) { |
| 87 // This is not supposed to be used. | 91 // This is not supposed to be used. |
| 88 NOTREACHED(); | 92 NOTREACHED(); |
| 89 return base::FilePath(); | 93 return base::FilePath(); |
| 90 } | 94 } |
| 91 | 95 |
| 92 FileSystemFileUtil* MediaFileSystemMountPointProvider::GetFileUtil( | 96 fileapi::FileSystemFileUtil* MediaFileSystemMountPointProvider::GetFileUtil( |
| 93 FileSystemType type) { | 97 FileSystemType type) { |
| 94 switch (type) { | 98 switch (type) { |
| 95 case kFileSystemTypeNativeMedia: | 99 case fileapi::kFileSystemTypeNativeMedia: |
| 96 return native_media_file_util_->sync_file_util(); | 100 return native_media_file_util_->sync_file_util(); |
| 97 default: | 101 default: |
| 98 NOTREACHED(); | 102 NOTREACHED(); |
| 99 } | 103 } |
| 100 return NULL; | 104 return NULL; |
| 101 } | 105 } |
| 102 | 106 |
| 103 AsyncFileUtil* MediaFileSystemMountPointProvider::GetAsyncFileUtil( | 107 fileapi::AsyncFileUtil* MediaFileSystemMountPointProvider::GetAsyncFileUtil( |
| 104 FileSystemType type) { | 108 FileSystemType type) { |
| 105 switch (type) { | 109 switch (type) { |
| 106 case kFileSystemTypeNativeMedia: | 110 case fileapi::kFileSystemTypeNativeMedia: |
| 107 return native_media_file_util_.get(); | 111 return native_media_file_util_.get(); |
| 108 case kFileSystemTypeDeviceMedia: | 112 case fileapi::kFileSystemTypeDeviceMedia: |
| 109 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) | 113 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) |
| 110 return device_media_async_file_util_.get(); | 114 return device_media_async_file_util_.get(); |
| 111 #endif | 115 #endif |
| 112 default: | 116 default: |
| 113 NOTREACHED(); | 117 NOTREACHED(); |
| 114 } | 118 } |
| 115 return NULL; | 119 return NULL; |
| 116 } | 120 } |
| 117 | 121 |
| 118 CopyOrMoveFileValidatorFactory* | 122 fileapi::CopyOrMoveFileValidatorFactory* |
| 119 MediaFileSystemMountPointProvider::GetCopyOrMoveFileValidatorFactory( | 123 MediaFileSystemMountPointProvider::GetCopyOrMoveFileValidatorFactory( |
| 120 FileSystemType type, base::PlatformFileError* error_code) { | 124 FileSystemType type, base::PlatformFileError* error_code) { |
| 121 DCHECK(error_code); | 125 DCHECK(error_code); |
| 122 *error_code = base::PLATFORM_FILE_OK; | 126 *error_code = base::PLATFORM_FILE_OK; |
| 123 switch (type) { | 127 switch (type) { |
| 124 case kFileSystemTypeNativeMedia: | 128 case fileapi::kFileSystemTypeNativeMedia: |
| 125 case kFileSystemTypeDeviceMedia: | 129 case fileapi::kFileSystemTypeDeviceMedia: |
| 126 if (!media_copy_or_move_file_validator_factory_) { | 130 if (!media_copy_or_move_file_validator_factory_) { |
| 127 *error_code = base::PLATFORM_FILE_ERROR_SECURITY; | 131 *error_code = base::PLATFORM_FILE_ERROR_SECURITY; |
| 128 return NULL; | 132 return NULL; |
| 129 } | 133 } |
| 130 return media_copy_or_move_file_validator_factory_.get(); | 134 return media_copy_or_move_file_validator_factory_.get(); |
| 131 default: | 135 default: |
| 132 NOTREACHED(); | 136 NOTREACHED(); |
| 133 } | 137 } |
| 134 return NULL; | 138 return NULL; |
| 135 } | 139 } |
| 136 | 140 |
| 137 void | 141 void |
| 138 MediaFileSystemMountPointProvider::InitializeCopyOrMoveFileValidatorFactory( | 142 MediaFileSystemMountPointProvider::InitializeCopyOrMoveFileValidatorFactory( |
| 139 FileSystemType type, | 143 FileSystemType type, |
| 140 scoped_ptr<CopyOrMoveFileValidatorFactory> factory) { | 144 scoped_ptr<fileapi::CopyOrMoveFileValidatorFactory> factory) { |
| 141 switch (type) { | 145 switch (type) { |
| 142 case kFileSystemTypeNativeMedia: | 146 case fileapi::kFileSystemTypeNativeMedia: |
| 143 case kFileSystemTypeDeviceMedia: | 147 case fileapi::kFileSystemTypeDeviceMedia: |
| 144 if (!media_copy_or_move_file_validator_factory_) | 148 if (!media_copy_or_move_file_validator_factory_) |
| 145 media_copy_or_move_file_validator_factory_.reset(factory.release()); | 149 media_copy_or_move_file_validator_factory_.reset(factory.release()); |
| 146 break; | 150 break; |
| 147 default: | 151 default: |
| 148 NOTREACHED(); | 152 NOTREACHED(); |
| 149 } | 153 } |
| 150 } | 154 } |
| 151 | 155 |
| 152 FilePermissionPolicy MediaFileSystemMountPointProvider::GetPermissionPolicy( | 156 fileapi::FilePermissionPolicy |
| 157 MediaFileSystemMountPointProvider::GetPermissionPolicy( |
| 153 const FileSystemURL& url, int permissions) const { | 158 const FileSystemURL& url, int permissions) const { |
| 154 // Access to media file systems should be checked using per-filesystem | 159 // Access to media file systems should be checked using per-filesystem |
| 155 // access permission. | 160 // access permission. |
| 156 return FILE_PERMISSION_USE_FILESYSTEM_PERMISSION; | 161 return fileapi::FILE_PERMISSION_USE_FILESYSTEM_PERMISSION; |
| 157 } | 162 } |
| 158 | 163 |
| 159 FileSystemOperation* | 164 fileapi::FileSystemOperation* |
| 160 MediaFileSystemMountPointProvider::CreateFileSystemOperation( | 165 MediaFileSystemMountPointProvider::CreateFileSystemOperation( |
| 161 const FileSystemURL& url, | 166 const FileSystemURL& url, |
| 162 FileSystemContext* context, | 167 FileSystemContext* context, |
| 163 base::PlatformFileError* error_code) const { | 168 base::PlatformFileError* error_code) const { |
| 164 scoped_ptr<FileSystemOperationContext> operation_context( | 169 scoped_ptr<fileapi::FileSystemOperationContext> operation_context( |
| 165 new FileSystemOperationContext( | 170 new fileapi::FileSystemOperationContext( |
| 166 context, context->task_runners()->media_task_runner())); | 171 context, context->task_runners()->media_task_runner())); |
| 167 | 172 |
| 168 operation_context->SetUserValue(kMediaPathFilterKey, | 173 operation_context->SetUserValue(kMediaPathFilterKey, |
| 169 media_path_filter_.get()); | 174 media_path_filter_.get()); |
| 170 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) | 175 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) |
| 171 if (url.type() == kFileSystemTypeDeviceMedia) { | 176 if (url.type() == fileapi::kFileSystemTypeDeviceMedia) { |
| 172 operation_context->SetUserValue(kMTPDeviceDelegateURLKey, | 177 operation_context->SetUserValue(kMTPDeviceDelegateURLKey, |
| 173 url.filesystem_id()); | 178 url.filesystem_id()); |
| 174 } | 179 } |
| 175 #endif | 180 #endif |
| 176 | 181 |
| 177 return new LocalFileSystemOperation(context, operation_context.Pass()); | 182 return new fileapi::LocalFileSystemOperation(context, |
| 183 operation_context.Pass()); |
| 178 } | 184 } |
| 179 | 185 |
| 180 scoped_ptr<webkit_blob::FileStreamReader> | 186 scoped_ptr<webkit_blob::FileStreamReader> |
| 181 MediaFileSystemMountPointProvider::CreateFileStreamReader( | 187 MediaFileSystemMountPointProvider::CreateFileStreamReader( |
| 182 const FileSystemURL& url, | 188 const FileSystemURL& url, |
| 183 int64 offset, | 189 int64 offset, |
| 184 const base::Time& expected_modification_time, | 190 const base::Time& expected_modification_time, |
| 185 FileSystemContext* context) const { | 191 FileSystemContext* context) const { |
| 186 return scoped_ptr<webkit_blob::FileStreamReader>( | 192 return scoped_ptr<webkit_blob::FileStreamReader>( |
| 187 new webkit_blob::LocalFileStreamReader( | 193 new webkit_blob::LocalFileStreamReader( |
| 188 context->task_runners()->file_task_runner(), | 194 context->task_runners()->file_task_runner(), |
| 189 url.path(), offset, expected_modification_time)); | 195 url.path(), offset, expected_modification_time)); |
| 190 } | 196 } |
| 191 | 197 |
| 192 scoped_ptr<FileStreamWriter> | 198 scoped_ptr<fileapi::FileStreamWriter> |
| 193 MediaFileSystemMountPointProvider::CreateFileStreamWriter( | 199 MediaFileSystemMountPointProvider::CreateFileStreamWriter( |
| 194 const FileSystemURL& url, | 200 const FileSystemURL& url, |
| 195 int64 offset, | 201 int64 offset, |
| 196 FileSystemContext* context) const { | 202 FileSystemContext* context) const { |
| 197 return scoped_ptr<FileStreamWriter>( | 203 return scoped_ptr<fileapi::FileStreamWriter>( |
| 198 new LocalFileStreamWriter(url.path(), offset)); | 204 new fileapi::LocalFileStreamWriter(url.path(), offset)); |
| 199 } | 205 } |
| 200 | 206 |
| 201 FileSystemQuotaUtil* MediaFileSystemMountPointProvider::GetQuotaUtil() { | 207 fileapi::FileSystemQuotaUtil* |
| 208 MediaFileSystemMountPointProvider::GetQuotaUtil() { |
| 202 // No quota support. | 209 // No quota support. |
| 203 return NULL; | 210 return NULL; |
| 204 } | 211 } |
| 205 | 212 |
| 206 void MediaFileSystemMountPointProvider::DeleteFileSystem( | 213 void MediaFileSystemMountPointProvider::DeleteFileSystem( |
| 207 const GURL& origin_url, | 214 const GURL& origin_url, |
| 208 FileSystemType type, | 215 FileSystemType type, |
| 209 FileSystemContext* context, | 216 FileSystemContext* context, |
| 210 const DeleteFileSystemCallback& callback) { | 217 const DeleteFileSystemCallback& callback) { |
| 211 NOTREACHED(); | 218 NOTREACHED(); |
| 212 callback.Run(base::PLATFORM_FILE_ERROR_INVALID_OPERATION); | 219 callback.Run(base::PLATFORM_FILE_ERROR_INVALID_OPERATION); |
| 213 } | 220 } |
| 214 | 221 |
| 215 } // namespace fileapi | 222 } // namespace chrome |
| OLD | NEW |