| 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 "chrome/browser/media_galleries/fileapi/media_file_system_mount_point_p
rovider.h" | 5 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.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/message_loop_proxy.h" | 12 #include "base/message_loop/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 "base/threading/sequenced_worker_pool.h" | 15 #include "base/threading/sequenced_worker_pool.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 36 #if defined(OS_WIN) || defined(OS_MACOSX) | 36 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 37 #include "chrome/browser/media_galleries/fileapi/itunes_file_util.h" | 37 #include "chrome/browser/media_galleries/fileapi/itunes_file_util.h" |
| 38 #include "chrome/browser/media_galleries/fileapi/picasa/picasa_file_util.h" | 38 #include "chrome/browser/media_galleries/fileapi/picasa/picasa_file_util.h" |
| 39 #endif // defined(OS_WIN) || defined(OS_MACOSX) | 39 #endif // defined(OS_WIN) || defined(OS_MACOSX) |
| 40 | 40 |
| 41 using fileapi::FileSystemContext; | 41 using fileapi::FileSystemContext; |
| 42 using fileapi::FileSystemURL; | 42 using fileapi::FileSystemURL; |
| 43 | 43 |
| 44 namespace chrome { | 44 namespace chrome { |
| 45 | 45 |
| 46 const char MediaFileSystemMountPointProvider::kMediaTaskRunnerName[] = | 46 const char MediaFileSystemBackend::kMediaTaskRunnerName[] = |
| 47 "media-task-runner"; | 47 "media-task-runner"; |
| 48 const char MediaFileSystemMountPointProvider::kMediaPathFilterKey[] = | 48 const char MediaFileSystemBackend::kMediaPathFilterKey[] = |
| 49 "MediaPathFilterKey"; | 49 "MediaPathFilterKey"; |
| 50 const char MediaFileSystemMountPointProvider::kMTPDeviceDelegateURLKey[] = | 50 const char MediaFileSystemBackend::kMTPDeviceDelegateURLKey[] = |
| 51 "MTPDeviceDelegateKey"; | 51 "MTPDeviceDelegateKey"; |
| 52 | 52 |
| 53 MediaFileSystemMountPointProvider::MediaFileSystemMountPointProvider( | 53 MediaFileSystemBackend::MediaFileSystemBackend( |
| 54 const base::FilePath& profile_path, | 54 const base::FilePath& profile_path, |
| 55 base::SequencedTaskRunner* media_task_runner) | 55 base::SequencedTaskRunner* media_task_runner) |
| 56 : profile_path_(profile_path), | 56 : profile_path_(profile_path), |
| 57 media_task_runner_(media_task_runner), | 57 media_task_runner_(media_task_runner), |
| 58 media_path_filter_(new MediaPathFilter), | 58 media_path_filter_(new MediaPathFilter), |
| 59 media_copy_or_move_file_validator_factory_(new MediaFileValidatorFactory), | 59 media_copy_or_move_file_validator_factory_(new MediaFileValidatorFactory), |
| 60 native_media_file_util_(new NativeMediaFileUtil()), | 60 native_media_file_util_(new NativeMediaFileUtil()), |
| 61 device_media_async_file_util_( | 61 device_media_async_file_util_( |
| 62 DeviceMediaAsyncFileUtil::Create(profile_path_)) | 62 DeviceMediaAsyncFileUtil::Create(profile_path_)) |
| 63 #if defined(OS_WIN) || defined(OS_MACOSX) | 63 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 64 , | 64 , |
| 65 picasa_file_util_(new picasa::PicasaFileUtil()), | 65 picasa_file_util_(new picasa::PicasaFileUtil()), |
| 66 itunes_file_util_(new itunes::ItunesFileUtil()) | 66 itunes_file_util_(new itunes::ItunesFileUtil()) |
| 67 #endif // defined(OS_WIN) || defined(OS_MACOSX) | 67 #endif // defined(OS_WIN) || defined(OS_MACOSX) |
| 68 { | 68 { |
| 69 } | 69 } |
| 70 | 70 |
| 71 MediaFileSystemMountPointProvider::~MediaFileSystemMountPointProvider() { | 71 MediaFileSystemBackend::~MediaFileSystemBackend() { |
| 72 } | 72 } |
| 73 | 73 |
| 74 // static | 74 // static |
| 75 bool MediaFileSystemMountPointProvider::CurrentlyOnMediaTaskRunnerThread() { | 75 bool MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread() { |
| 76 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool(); | 76 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool(); |
| 77 base::SequencedWorkerPool::SequenceToken media_sequence_token = | 77 base::SequencedWorkerPool::SequenceToken media_sequence_token = |
| 78 pool->GetNamedSequenceToken(kMediaTaskRunnerName); | 78 pool->GetNamedSequenceToken(kMediaTaskRunnerName); |
| 79 return pool->IsRunningSequenceOnCurrentThread(media_sequence_token); | 79 return pool->IsRunningSequenceOnCurrentThread(media_sequence_token); |
| 80 } | 80 } |
| 81 | 81 |
| 82 // static | 82 // static |
| 83 scoped_refptr<base::SequencedTaskRunner> | 83 scoped_refptr<base::SequencedTaskRunner> |
| 84 MediaFileSystemMountPointProvider::MediaTaskRunner() { | 84 MediaFileSystemBackend::MediaTaskRunner() { |
| 85 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool(); | 85 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool(); |
| 86 base::SequencedWorkerPool::SequenceToken media_sequence_token = | 86 base::SequencedWorkerPool::SequenceToken media_sequence_token = |
| 87 pool->GetNamedSequenceToken(kMediaTaskRunnerName); | 87 pool->GetNamedSequenceToken(kMediaTaskRunnerName); |
| 88 return pool->GetSequencedTaskRunner(media_sequence_token); | 88 return pool->GetSequencedTaskRunner(media_sequence_token); |
| 89 } | 89 } |
| 90 | 90 |
| 91 bool MediaFileSystemMountPointProvider::CanHandleType( | 91 bool MediaFileSystemBackend::CanHandleType( |
| 92 fileapi::FileSystemType type) const { | 92 fileapi::FileSystemType type) const { |
| 93 switch (type) { | 93 switch (type) { |
| 94 case fileapi::kFileSystemTypeNativeMedia: | 94 case fileapi::kFileSystemTypeNativeMedia: |
| 95 case fileapi::kFileSystemTypeDeviceMedia: | 95 case fileapi::kFileSystemTypeDeviceMedia: |
| 96 #if defined(OS_WIN) || defined(OS_MACOSX) | 96 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 97 case fileapi::kFileSystemTypePicasa: | 97 case fileapi::kFileSystemTypePicasa: |
| 98 case fileapi::kFileSystemTypeItunes: | 98 case fileapi::kFileSystemTypeItunes: |
| 99 #endif // defined(OS_WIN) || defined(OS_MACOSX) | 99 #endif // defined(OS_WIN) || defined(OS_MACOSX) |
| 100 return true; | 100 return true; |
| 101 default: | 101 default: |
| 102 return false; | 102 return false; |
| 103 } | 103 } |
| 104 } | 104 } |
| 105 | 105 |
| 106 void MediaFileSystemMountPointProvider::OpenFileSystem( | 106 void MediaFileSystemBackend::OpenFileSystem( |
| 107 const GURL& origin_url, | 107 const GURL& origin_url, |
| 108 fileapi::FileSystemType type, | 108 fileapi::FileSystemType type, |
| 109 fileapi::OpenFileSystemMode mode, | 109 fileapi::OpenFileSystemMode mode, |
| 110 const OpenFileSystemCallback& callback) { | 110 const OpenFileSystemCallback& callback) { |
| 111 // We never allow opening a new isolated FileSystem via usual OpenFileSystem. | 111 // We never allow opening a new isolated FileSystem via usual OpenFileSystem. |
| 112 base::MessageLoopProxy::current()->PostTask( | 112 base::MessageLoopProxy::current()->PostTask( |
| 113 FROM_HERE, | 113 FROM_HERE, |
| 114 base::Bind(callback, base::PLATFORM_FILE_ERROR_SECURITY)); | 114 base::Bind(callback, base::PLATFORM_FILE_ERROR_SECURITY)); |
| 115 } | 115 } |
| 116 | 116 |
| 117 fileapi::FileSystemFileUtil* MediaFileSystemMountPointProvider::GetFileUtil( | 117 fileapi::FileSystemFileUtil* MediaFileSystemBackend::GetFileUtil( |
| 118 fileapi::FileSystemType type) { | 118 fileapi::FileSystemType type) { |
| 119 NOTREACHED(); | 119 NOTREACHED(); |
| 120 return NULL; | 120 return NULL; |
| 121 } | 121 } |
| 122 | 122 |
| 123 fileapi::AsyncFileUtil* MediaFileSystemMountPointProvider::GetAsyncFileUtil( | 123 fileapi::AsyncFileUtil* MediaFileSystemBackend::GetAsyncFileUtil( |
| 124 fileapi::FileSystemType type) { | 124 fileapi::FileSystemType type) { |
| 125 switch (type) { | 125 switch (type) { |
| 126 case fileapi::kFileSystemTypeNativeMedia: | 126 case fileapi::kFileSystemTypeNativeMedia: |
| 127 return native_media_file_util_.get(); | 127 return native_media_file_util_.get(); |
| 128 case fileapi::kFileSystemTypeDeviceMedia: | 128 case fileapi::kFileSystemTypeDeviceMedia: |
| 129 return device_media_async_file_util_.get(); | 129 return device_media_async_file_util_.get(); |
| 130 #if defined(OS_WIN) || defined(OS_MACOSX) | 130 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 131 case fileapi::kFileSystemTypeItunes: | 131 case fileapi::kFileSystemTypeItunes: |
| 132 return itunes_file_util_.get(); | 132 return itunes_file_util_.get(); |
| 133 case fileapi::kFileSystemTypePicasa: | 133 case fileapi::kFileSystemTypePicasa: |
| 134 return picasa_file_util_.get(); | 134 return picasa_file_util_.get(); |
| 135 #endif // defined(OS_WIN) || defined(OS_MACOSX) | 135 #endif // defined(OS_WIN) || defined(OS_MACOSX) |
| 136 default: | 136 default: |
| 137 NOTREACHED(); | 137 NOTREACHED(); |
| 138 } | 138 } |
| 139 return NULL; | 139 return NULL; |
| 140 } | 140 } |
| 141 | 141 |
| 142 fileapi::CopyOrMoveFileValidatorFactory* | 142 fileapi::CopyOrMoveFileValidatorFactory* |
| 143 MediaFileSystemMountPointProvider::GetCopyOrMoveFileValidatorFactory( | 143 MediaFileSystemBackend::GetCopyOrMoveFileValidatorFactory( |
| 144 fileapi::FileSystemType type, base::PlatformFileError* error_code) { | 144 fileapi::FileSystemType type, base::PlatformFileError* error_code) { |
| 145 DCHECK(error_code); | 145 DCHECK(error_code); |
| 146 *error_code = base::PLATFORM_FILE_OK; | 146 *error_code = base::PLATFORM_FILE_OK; |
| 147 switch (type) { | 147 switch (type) { |
| 148 case fileapi::kFileSystemTypeNativeMedia: | 148 case fileapi::kFileSystemTypeNativeMedia: |
| 149 case fileapi::kFileSystemTypeDeviceMedia: | 149 case fileapi::kFileSystemTypeDeviceMedia: |
| 150 case fileapi::kFileSystemTypeItunes: | 150 case fileapi::kFileSystemTypeItunes: |
| 151 if (!media_copy_or_move_file_validator_factory_) { | 151 if (!media_copy_or_move_file_validator_factory_) { |
| 152 *error_code = base::PLATFORM_FILE_ERROR_SECURITY; | 152 *error_code = base::PLATFORM_FILE_ERROR_SECURITY; |
| 153 return NULL; | 153 return NULL; |
| 154 } | 154 } |
| 155 return media_copy_or_move_file_validator_factory_.get(); | 155 return media_copy_or_move_file_validator_factory_.get(); |
| 156 default: | 156 default: |
| 157 NOTREACHED(); | 157 NOTREACHED(); |
| 158 } | 158 } |
| 159 return NULL; | 159 return NULL; |
| 160 } | 160 } |
| 161 | 161 |
| 162 fileapi::FileSystemOperation* | 162 fileapi::FileSystemOperation* |
| 163 MediaFileSystemMountPointProvider::CreateFileSystemOperation( | 163 MediaFileSystemBackend::CreateFileSystemOperation( |
| 164 const FileSystemURL& url, | 164 const FileSystemURL& url, |
| 165 FileSystemContext* context, | 165 FileSystemContext* context, |
| 166 base::PlatformFileError* error_code) const { | 166 base::PlatformFileError* error_code) const { |
| 167 scoped_ptr<fileapi::FileSystemOperationContext> operation_context( | 167 scoped_ptr<fileapi::FileSystemOperationContext> operation_context( |
| 168 new fileapi::FileSystemOperationContext( | 168 new fileapi::FileSystemOperationContext( |
| 169 context, media_task_runner_.get())); | 169 context, media_task_runner_.get())); |
| 170 | 170 |
| 171 operation_context->SetUserValue(kMediaPathFilterKey, | 171 operation_context->SetUserValue(kMediaPathFilterKey, |
| 172 media_path_filter_.get()); | 172 media_path_filter_.get()); |
| 173 if (url.type() == fileapi::kFileSystemTypeDeviceMedia) { | 173 if (url.type() == fileapi::kFileSystemTypeDeviceMedia) { |
| 174 operation_context->SetUserValue(kMTPDeviceDelegateURLKey, | 174 operation_context->SetUserValue(kMTPDeviceDelegateURLKey, |
| 175 url.filesystem_id()); | 175 url.filesystem_id()); |
| 176 } | 176 } |
| 177 | 177 |
| 178 return new fileapi::LocalFileSystemOperation(url, context, | 178 return new fileapi::LocalFileSystemOperation(url, context, |
| 179 operation_context.Pass()); | 179 operation_context.Pass()); |
| 180 } | 180 } |
| 181 | 181 |
| 182 scoped_ptr<webkit_blob::FileStreamReader> | 182 scoped_ptr<webkit_blob::FileStreamReader> |
| 183 MediaFileSystemMountPointProvider::CreateFileStreamReader( | 183 MediaFileSystemBackend::CreateFileStreamReader( |
| 184 const FileSystemURL& url, | 184 const FileSystemURL& url, |
| 185 int64 offset, | 185 int64 offset, |
| 186 const base::Time& expected_modification_time, | 186 const base::Time& expected_modification_time, |
| 187 FileSystemContext* context) const { | 187 FileSystemContext* context) const { |
| 188 return scoped_ptr<webkit_blob::FileStreamReader>( | 188 return scoped_ptr<webkit_blob::FileStreamReader>( |
| 189 new webkit_blob::LocalFileStreamReader( | 189 new webkit_blob::LocalFileStreamReader( |
| 190 context->task_runners()->file_task_runner(), | 190 context->task_runners()->file_task_runner(), |
| 191 url.path(), offset, expected_modification_time)); | 191 url.path(), offset, expected_modification_time)); |
| 192 } | 192 } |
| 193 | 193 |
| 194 scoped_ptr<fileapi::FileStreamWriter> | 194 scoped_ptr<fileapi::FileStreamWriter> |
| 195 MediaFileSystemMountPointProvider::CreateFileStreamWriter( | 195 MediaFileSystemBackend::CreateFileStreamWriter( |
| 196 const FileSystemURL& url, | 196 const FileSystemURL& url, |
| 197 int64 offset, | 197 int64 offset, |
| 198 FileSystemContext* context) const { | 198 FileSystemContext* context) const { |
| 199 return scoped_ptr<fileapi::FileStreamWriter>( | 199 return scoped_ptr<fileapi::FileStreamWriter>( |
| 200 new fileapi::LocalFileStreamWriter( | 200 new fileapi::LocalFileStreamWriter( |
| 201 context->task_runners()->file_task_runner(), | 201 context->task_runners()->file_task_runner(), |
| 202 url.path(), offset)); | 202 url.path(), offset)); |
| 203 } | 203 } |
| 204 | 204 |
| 205 fileapi::FileSystemQuotaUtil* | 205 fileapi::FileSystemQuotaUtil* |
| 206 MediaFileSystemMountPointProvider::GetQuotaUtil() { | 206 MediaFileSystemBackend::GetQuotaUtil() { |
| 207 // No quota support. | 207 // No quota support. |
| 208 return NULL; | 208 return NULL; |
| 209 } | 209 } |
| 210 | 210 |
| 211 } // namespace chrome | 211 } // namespace chrome |
| OLD | NEW |