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