Chromium Code Reviews| 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/device_media_async_file_util.h" | 5 #include "chrome/browser/media_galleries/fileapi/device_media_async_file_util.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/task_runner_util.h" | 10 #include "base/task_runner_util.h" |
| 11 #include "chrome/browser/media_galleries/fileapi/media_path_filter.h" | 11 #include "chrome/browser/media_galleries/fileapi/media_path_filter.h" |
| 12 #include "chrome/browser/media_galleries/fileapi/mtp_device_async_delegate.h" | 12 #include "chrome/browser/media_galleries/fileapi/mtp_device_async_delegate.h" |
| 13 #include "chrome/browser/media_galleries/fileapi/mtp_device_map_service.h" | 13 #include "chrome/browser/media_galleries/fileapi/mtp_device_map_service.h" |
| 14 #include "chrome/browser/media_galleries/fileapi/mtp_file_stream_reader.h" | 14 #include "chrome/browser/media_galleries/fileapi/mtp_file_stream_reader.h" |
| 15 #include "chrome/browser/media_galleries/fileapi/native_media_file_util.h" | 15 #include "chrome/browser/media_galleries/fileapi/native_media_file_util.h" |
| 16 #include "chrome/browser/media_galleries/fileapi/readahead_file_stream_reader.h" | 16 #include "chrome/browser/media_galleries/fileapi/readahead_file_stream_reader.h" |
| 17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 18 #include "webkit/browser/blob/file_stream_reader.h" | 18 #include "webkit/browser/blob/file_stream_reader.h" |
| 19 #include "webkit/browser/fileapi/file_system_context.h" | 19 #include "webkit/browser/fileapi/file_system_context.h" |
| 20 #include "webkit/browser/fileapi/file_system_operation_context.h" | 20 #include "webkit/browser/fileapi/file_system_operation_context.h" |
| 21 #include "webkit/browser/fileapi/file_system_url.h" | 21 #include "webkit/browser/fileapi/file_system_url.h" |
| 22 #include "webkit/browser/fileapi/native_file_util.h" | 22 #include "webkit/browser/fileapi/native_file_util.h" |
| 23 #include "webkit/common/blob/shareable_file_reference.h" | 23 #include "webkit/common/blob/shareable_file_reference.h" |
| 24 | 24 |
| 25 using fileapi::AsyncFileUtil; | |
| 25 using fileapi::FileSystemOperationContext; | 26 using fileapi::FileSystemOperationContext; |
| 26 using fileapi::FileSystemURL; | 27 using fileapi::FileSystemURL; |
| 27 using webkit_blob::ShareableFileReference; | 28 using webkit_blob::ShareableFileReference; |
| 28 | 29 |
| 29 namespace { | 30 namespace { |
| 30 | 31 |
| 31 const char kDeviceMediaAsyncFileUtilTempDir[] = "DeviceMediaFileSystem"; | 32 const char kDeviceMediaAsyncFileUtilTempDir[] = "DeviceMediaFileSystem"; |
| 32 | 33 |
| 33 // Called on the IO thread. | |
| 34 MTPDeviceAsyncDelegate* GetMTPDeviceDelegate(const FileSystemURL& url) { | 34 MTPDeviceAsyncDelegate* GetMTPDeviceDelegate(const FileSystemURL& url) { |
| 35 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 35 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 36 return MTPDeviceMapService::GetInstance()->GetMTPDeviceAsyncDelegate( | 36 return MTPDeviceMapService::GetInstance()->GetMTPDeviceAsyncDelegate( |
| 37 url.filesystem_id()); | 37 url.filesystem_id()); |
| 38 } | 38 } |
| 39 | 39 |
| 40 // Called when GetFileInfo method call failed to get the details of file | |
| 41 // specified by the requested url. |callback| is invoked to notify the | |
| 42 // caller about the file |error|. | |
| 43 void OnGetFileInfoError(const AsyncFileUtil::GetFileInfoCallback& callback, | |
| 44 base::File::Error error) { | |
| 45 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
| 46 callback.Run(error, base::File::Info()); | |
| 47 } | |
| 48 | |
| 49 // Called when ReadDirectory method call failed to enumerate the directory | |
| 50 // objects. |callback| is invoked to notify the caller about the |error| | |
| 51 // that occured while reading the directory objects. | |
| 52 void OnReadDirectoryError(const AsyncFileUtil::ReadDirectoryCallback& callback, | |
| 53 base::File::Error error) { | |
| 54 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
| 55 callback.Run(error, AsyncFileUtil::EntryList(), false /*no more*/); | |
| 56 } | |
| 57 | |
| 40 // Called on a blocking pool thread to create a snapshot file to hold the | 58 // Called on a blocking pool thread to create a snapshot file to hold the |
| 41 // contents of |device_file_path|. The snapshot file is created in the | 59 // contents of |device_file_path|. The snapshot file is created in the |
| 42 // "profile_path/kDeviceMediaAsyncFileUtilTempDir" directory. Return the | 60 // "profile_path/kDeviceMediaAsyncFileUtilTempDir" directory. Return the |
| 43 // snapshot file path or an empty path on failure. | 61 // snapshot file path or an empty path on failure. |
| 44 base::FilePath CreateSnapshotFileOnBlockingPool( | 62 base::FilePath CreateSnapshotFileOnBlockingPool( |
| 45 const base::FilePath& device_file_path, | 63 const base::FilePath& device_file_path, |
| 46 const base::FilePath& profile_path) { | 64 const base::FilePath& profile_path) { |
| 47 base::FilePath snapshot_file_path; | 65 base::FilePath snapshot_file_path; |
| 48 base::FilePath media_file_system_dir_path = | 66 base::FilePath media_file_system_dir_path = |
| 49 profile_path.AppendASCII(kDeviceMediaAsyncFileUtilTempDir); | 67 profile_path.AppendASCII(kDeviceMediaAsyncFileUtilTempDir); |
| 50 if (!base::CreateDirectory(media_file_system_dir_path) || | 68 if (!base::CreateDirectory(media_file_system_dir_path) || |
| 51 !base::CreateTemporaryFileInDir(media_file_system_dir_path, | 69 !base::CreateTemporaryFileInDir(media_file_system_dir_path, |
| 52 &snapshot_file_path)) { | 70 &snapshot_file_path)) { |
| 53 LOG(WARNING) << "Could not create media snapshot file " | 71 LOG(WARNING) << "Could not create media snapshot file " |
| 54 << media_file_system_dir_path.value(); | 72 << media_file_system_dir_path.value(); |
| 55 snapshot_file_path = base::FilePath(); | 73 snapshot_file_path = base::FilePath(); |
| 56 } | 74 } |
| 57 return snapshot_file_path; | 75 return snapshot_file_path; |
| 58 } | 76 } |
| 59 | 77 |
| 78 // Called after OnDidCreateSnapshotFile finishes media check. | |
| 79 // |callback| is invoked to complete the CreateSnapshotFile request. | |
| 80 void OnDidCheckMediaForCreateSnapshotFile( | |
| 81 const AsyncFileUtil::CreateSnapshotFileCallback& callback, | |
| 82 const base::File::Info& file_info, | |
| 83 scoped_refptr<webkit_blob::ShareableFileReference> platform_file, | |
| 84 base::File::Error error) { | |
| 85 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
| 86 base::FilePath platform_path(platform_file.get()->path()); | |
| 87 if (error != base::File::FILE_OK) | |
| 88 platform_file = NULL; | |
| 89 callback.Run(error, file_info, platform_path, platform_file); | |
| 90 } | |
| 91 | |
| 92 // Called when the snapshot file specified by the |platform_path| is | |
| 93 // successfully created. |file_info| contains the device media file details | |
| 94 // for which the snapshot file is created. | |
| 95 void OnDidCreateSnapshotFile( | |
| 96 const AsyncFileUtil::CreateSnapshotFileCallback& callback, | |
| 97 base::SequencedTaskRunner* media_task_runner, | |
| 98 bool validate_media_files, | |
| 99 const base::File::Info& file_info, | |
| 100 const base::FilePath& platform_path) { | |
| 101 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
| 102 scoped_refptr<webkit_blob::ShareableFileReference> file = | |
| 103 ShareableFileReference::GetOrCreate( | |
| 104 platform_path, | |
| 105 ShareableFileReference::DELETE_ON_FINAL_RELEASE, | |
| 106 media_task_runner); | |
| 107 | |
| 108 if (validate_media_files) { | |
| 109 base::PostTaskAndReplyWithResult( | |
| 110 media_task_runner, | |
| 111 FROM_HERE, | |
| 112 base::Bind(&NativeMediaFileUtil::IsMediaFile, platform_path), | |
| 113 base::Bind(&OnDidCheckMediaForCreateSnapshotFile, | |
| 114 callback, | |
| 115 file_info, | |
| 116 file)); | |
| 117 } else { | |
| 118 OnDidCheckMediaForCreateSnapshotFile(callback, file_info, file, | |
| 119 base::File::FILE_OK); | |
| 120 } | |
| 121 } | |
| 122 | |
| 123 // Called when CreateSnapshotFile method call fails. |callback| is invoked to | |
| 124 // notify the caller about the |error|. | |
| 125 void OnCreateSnapshotFileError( | |
| 126 const AsyncFileUtil::CreateSnapshotFileCallback& callback, | |
| 127 base::File::Error error) { | |
| 128 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
| 129 callback.Run(error, base::File::Info(), base::FilePath(), | |
| 130 scoped_refptr<ShareableFileReference>()); | |
| 131 } | |
| 132 | |
| 133 // Called when the snapshot file specified by the |snapshot_file_path| is | |
| 134 // created to hold the contents of the url.path(). If the snapshot | |
| 135 // file is successfully created, |snapshot_file_path| will be an non-empty | |
| 136 // file path. In case of failure, |snapshot_file_path| will be an empty file | |
| 137 // path. Forwards the CreateSnapshot request to the delegate to copy the | |
| 138 // contents of url.path() to |snapshot_file_path|. | |
| 139 void OnSnapshotFileCreatedRunTask( | |
| 140 scoped_ptr<FileSystemOperationContext> context, | |
| 141 const AsyncFileUtil::CreateSnapshotFileCallback& callback, | |
| 142 const FileSystemURL& url, | |
| 143 bool validate_media_files, | |
| 144 const base::FilePath& snapshot_file_path) { | |
| 145 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
| 146 if (snapshot_file_path.empty()) { | |
| 147 OnCreateSnapshotFileError(callback, base::File::FILE_ERROR_FAILED); | |
| 148 return; | |
| 149 } | |
| 150 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(url); | |
| 151 if (!delegate) { | |
| 152 OnCreateSnapshotFileError(callback, base::File::FILE_ERROR_NOT_FOUND); | |
| 153 return; | |
| 154 } | |
| 155 delegate->CreateSnapshotFile( | |
| 156 url.path(), // device file path | |
| 157 snapshot_file_path, | |
| 158 base::Bind(&OnDidCreateSnapshotFile, | |
| 159 callback, | |
| 160 make_scoped_refptr(context->task_runner()), | |
| 161 validate_media_files), | |
| 162 base::Bind(&OnCreateSnapshotFileError, callback)); | |
| 163 } | |
| 164 | |
| 60 } // namespace | 165 } // namespace |
| 61 | 166 |
| 62 DeviceMediaAsyncFileUtil::~DeviceMediaAsyncFileUtil() { | 167 DeviceMediaAsyncFileUtil::~DeviceMediaAsyncFileUtil() { |
| 63 } | 168 } |
| 64 | 169 |
| 65 // static | 170 // static |
| 66 DeviceMediaAsyncFileUtil* DeviceMediaAsyncFileUtil::Create( | 171 scoped_ptr<DeviceMediaAsyncFileUtil> DeviceMediaAsyncFileUtil::Create( |
| 67 const base::FilePath& profile_path, | 172 const base::FilePath& profile_path, |
| 68 MediaFileValidationType validation_type) { | 173 MediaFileValidationType validation_type) { |
| 69 DCHECK(!profile_path.empty()); | 174 DCHECK(!profile_path.empty()); |
| 70 return new DeviceMediaAsyncFileUtil(profile_path, validation_type); | 175 return make_scoped_ptr( |
| 176 new DeviceMediaAsyncFileUtil(profile_path, validation_type)); | |
| 71 } | 177 } |
| 72 | 178 |
| 73 bool DeviceMediaAsyncFileUtil::SupportsStreaming( | 179 bool DeviceMediaAsyncFileUtil::SupportsStreaming( |
| 74 const fileapi::FileSystemURL& url) { | 180 const fileapi::FileSystemURL& url) { |
| 75 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 181 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 76 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(url); | 182 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(url); |
| 77 if (!delegate) | 183 return delegate ? delegate->IsStreaming() : false; |
|
vandebo (ex-Chrome)
2014/05/21 18:46:46
nit: this seems less readable.
Lei Zhang
2014/05/21 19:04:38
*shrug* revert
| |
| 78 return false; | |
| 79 return delegate->IsStreaming(); | |
| 80 } | 184 } |
| 81 | 185 |
| 82 void DeviceMediaAsyncFileUtil::CreateOrOpen( | 186 void DeviceMediaAsyncFileUtil::CreateOrOpen( |
| 83 scoped_ptr<FileSystemOperationContext> context, | 187 scoped_ptr<FileSystemOperationContext> context, |
| 84 const FileSystemURL& url, | 188 const FileSystemURL& url, |
| 85 int file_flags, | 189 int file_flags, |
| 86 const CreateOrOpenCallback& callback) { | 190 const CreateOrOpenCallback& callback) { |
| 87 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 191 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 88 // Returns an error if any unsupported flag is found. | 192 // Returns an error if any unsupported flag is found. |
| 89 if (file_flags & ~(base::File::FLAG_OPEN | | 193 if (file_flags & ~(base::File::FLAG_OPEN | |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(url); | 233 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(url); |
| 130 if (!delegate) { | 234 if (!delegate) { |
| 131 OnGetFileInfoError(callback, base::File::FILE_ERROR_NOT_FOUND); | 235 OnGetFileInfoError(callback, base::File::FILE_ERROR_NOT_FOUND); |
| 132 return; | 236 return; |
| 133 } | 237 } |
| 134 delegate->GetFileInfo( | 238 delegate->GetFileInfo( |
| 135 url.path(), | 239 url.path(), |
| 136 base::Bind(&DeviceMediaAsyncFileUtil::OnDidGetFileInfo, | 240 base::Bind(&DeviceMediaAsyncFileUtil::OnDidGetFileInfo, |
| 137 weak_ptr_factory_.GetWeakPtr(), | 241 weak_ptr_factory_.GetWeakPtr(), |
| 138 callback), | 242 callback), |
| 139 base::Bind(&DeviceMediaAsyncFileUtil::OnGetFileInfoError, | 243 base::Bind(&OnGetFileInfoError, callback)); |
| 140 weak_ptr_factory_.GetWeakPtr(), | |
| 141 callback)); | |
| 142 } | 244 } |
| 143 | 245 |
| 144 void DeviceMediaAsyncFileUtil::ReadDirectory( | 246 void DeviceMediaAsyncFileUtil::ReadDirectory( |
| 145 scoped_ptr<FileSystemOperationContext> context, | 247 scoped_ptr<FileSystemOperationContext> context, |
| 146 const FileSystemURL& url, | 248 const FileSystemURL& url, |
| 147 const ReadDirectoryCallback& callback) { | 249 const ReadDirectoryCallback& callback) { |
| 148 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 250 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 149 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(url); | 251 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(url); |
| 150 if (!delegate) { | 252 if (!delegate) { |
| 151 OnReadDirectoryError(callback, base::File::FILE_ERROR_NOT_FOUND); | 253 OnReadDirectoryError(callback, base::File::FILE_ERROR_NOT_FOUND); |
| 152 return; | 254 return; |
| 153 } | 255 } |
| 154 delegate->ReadDirectory( | 256 delegate->ReadDirectory( |
| 155 url.path(), | 257 url.path(), |
| 156 base::Bind(&DeviceMediaAsyncFileUtil::OnDidReadDirectory, | 258 base::Bind(&DeviceMediaAsyncFileUtil::OnDidReadDirectory, |
| 157 weak_ptr_factory_.GetWeakPtr(), | 259 weak_ptr_factory_.GetWeakPtr(), |
| 158 callback), | 260 callback), |
| 159 base::Bind(&DeviceMediaAsyncFileUtil::OnReadDirectoryError, | 261 base::Bind(&OnReadDirectoryError, callback)); |
| 160 weak_ptr_factory_.GetWeakPtr(), | |
| 161 callback)); | |
| 162 } | 262 } |
| 163 | 263 |
| 164 void DeviceMediaAsyncFileUtil::Touch( | 264 void DeviceMediaAsyncFileUtil::Touch( |
| 165 scoped_ptr<FileSystemOperationContext> context, | 265 scoped_ptr<FileSystemOperationContext> context, |
| 166 const FileSystemURL& url, | 266 const FileSystemURL& url, |
| 167 const base::Time& last_access_time, | 267 const base::Time& last_access_time, |
| 168 const base::Time& last_modified_time, | 268 const base::Time& last_modified_time, |
| 169 const StatusCallback& callback) { | 269 const StatusCallback& callback) { |
| 170 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 270 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 171 NOTIMPLEMENTED(); | 271 NOTIMPLEMENTED(); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 scoped_ptr<FileSystemOperationContext> context, | 345 scoped_ptr<FileSystemOperationContext> context, |
| 246 const FileSystemURL& url, | 346 const FileSystemURL& url, |
| 247 const CreateSnapshotFileCallback& callback) { | 347 const CreateSnapshotFileCallback& callback) { |
| 248 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 348 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 249 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(url); | 349 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(url); |
| 250 if (!delegate) { | 350 if (!delegate) { |
| 251 OnCreateSnapshotFileError(callback, base::File::FILE_ERROR_NOT_FOUND); | 351 OnCreateSnapshotFileError(callback, base::File::FILE_ERROR_NOT_FOUND); |
| 252 return; | 352 return; |
| 253 } | 353 } |
| 254 | 354 |
| 255 // Grab the SequencedTaskRunner now because base::Passed(&context) will | |
| 256 // turn |context| empty before |task_runner| gets accessed. | |
| 257 scoped_refptr<base::SequencedTaskRunner> task_runner(context->task_runner()); | 355 scoped_refptr<base::SequencedTaskRunner> task_runner(context->task_runner()); |
| 258 base::PostTaskAndReplyWithResult( | 356 base::PostTaskAndReplyWithResult( |
| 259 task_runner, | 357 task_runner, |
| 260 FROM_HERE, | 358 FROM_HERE, |
| 261 base::Bind(&CreateSnapshotFileOnBlockingPool, | 359 base::Bind(&CreateSnapshotFileOnBlockingPool, url.path(), profile_path_), |
| 262 url.path(), | 360 base::Bind(&OnSnapshotFileCreatedRunTask, |
| 263 profile_path_), | |
| 264 base::Bind(&DeviceMediaAsyncFileUtil::OnSnapshotFileCreatedRunTask, | |
| 265 weak_ptr_factory_.GetWeakPtr(), | |
| 266 base::Passed(&context), | 361 base::Passed(&context), |
| 267 callback, | 362 callback, |
| 268 url)); | 363 url, |
| 364 validate_media_files())); | |
| 269 } | 365 } |
| 270 | 366 |
| 271 scoped_ptr<webkit_blob::FileStreamReader> | 367 scoped_ptr<webkit_blob::FileStreamReader> |
| 272 DeviceMediaAsyncFileUtil::GetFileStreamReader( | 368 DeviceMediaAsyncFileUtil::GetFileStreamReader( |
| 273 const FileSystemURL& url, | 369 const FileSystemURL& url, |
| 274 int64 offset, | 370 int64 offset, |
| 275 const base::Time& expected_modification_time, | 371 const base::Time& expected_modification_time, |
| 276 fileapi::FileSystemContext* context) { | 372 fileapi::FileSystemContext* context) { |
| 277 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(url); | 373 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(url); |
| 278 if (!delegate) | 374 if (!delegate) |
| 279 return scoped_ptr<webkit_blob::FileStreamReader>(); | 375 return scoped_ptr<webkit_blob::FileStreamReader>(); |
| 280 | 376 |
| 281 DCHECK(delegate->IsStreaming()); | 377 DCHECK(delegate->IsStreaming()); |
| 282 return scoped_ptr<webkit_blob::FileStreamReader>( | 378 return scoped_ptr<webkit_blob::FileStreamReader>( |
| 283 new ReadaheadFileStreamReader(new MTPFileStreamReader( | 379 new ReadaheadFileStreamReader( |
| 284 context, url, offset, expected_modification_time, | 380 new MTPFileStreamReader(context, |
| 285 validation_type_ == APPLY_MEDIA_FILE_VALIDATION))); | 381 url, |
| 382 offset, | |
| 383 expected_modification_time, | |
| 384 validate_media_files()))); | |
| 286 } | 385 } |
| 287 | 386 |
| 288 DeviceMediaAsyncFileUtil::DeviceMediaAsyncFileUtil( | 387 DeviceMediaAsyncFileUtil::DeviceMediaAsyncFileUtil( |
| 289 const base::FilePath& profile_path, | 388 const base::FilePath& profile_path, |
| 290 MediaFileValidationType validation_type) | 389 MediaFileValidationType validation_type) |
| 291 : profile_path_(profile_path), | 390 : profile_path_(profile_path), |
| 292 validation_type_(validation_type), | 391 validation_type_(validation_type), |
| 293 weak_ptr_factory_(this) { | 392 weak_ptr_factory_(this) { |
| 294 } | 393 } |
| 295 | 394 |
| 296 void DeviceMediaAsyncFileUtil::OnDidGetFileInfo( | 395 void DeviceMediaAsyncFileUtil::OnDidGetFileInfo( |
| 297 const AsyncFileUtil::GetFileInfoCallback& callback, | 396 const GetFileInfoCallback& callback, |
| 298 const base::File::Info& file_info) { | 397 const base::File::Info& file_info) { |
| 398 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
| 299 callback.Run(base::File::FILE_OK, file_info); | 399 callback.Run(base::File::FILE_OK, file_info); |
| 300 } | 400 } |
| 301 | 401 |
| 302 void DeviceMediaAsyncFileUtil::OnGetFileInfoError( | |
| 303 const AsyncFileUtil::GetFileInfoCallback& callback, | |
| 304 base::File::Error error) { | |
| 305 callback.Run(error, base::File::Info()); | |
| 306 } | |
| 307 | |
| 308 void DeviceMediaAsyncFileUtil::OnDidReadDirectory( | 402 void DeviceMediaAsyncFileUtil::OnDidReadDirectory( |
| 309 const AsyncFileUtil::ReadDirectoryCallback& callback, | 403 const ReadDirectoryCallback& callback, |
| 310 const AsyncFileUtil::EntryList& file_list, | 404 const EntryList& file_list, |
| 311 bool has_more) { | 405 bool has_more) { |
| 406 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
| 312 callback.Run(base::File::FILE_OK, file_list, has_more); | 407 callback.Run(base::File::FILE_OK, file_list, has_more); |
| 313 } | 408 } |
| 314 | 409 |
| 315 void DeviceMediaAsyncFileUtil::OnReadDirectoryError( | 410 bool DeviceMediaAsyncFileUtil::validate_media_files() const { |
| 316 const AsyncFileUtil::ReadDirectoryCallback& callback, | 411 return validation_type_ == APPLY_MEDIA_FILE_VALIDATION; |
| 317 base::File::Error error) { | |
| 318 callback.Run(error, AsyncFileUtil::EntryList(), false /*no more*/); | |
| 319 } | 412 } |
| 320 | |
| 321 void DeviceMediaAsyncFileUtil::OnDidCreateSnapshotFile( | |
| 322 const AsyncFileUtil::CreateSnapshotFileCallback& callback, | |
| 323 base::SequencedTaskRunner* media_task_runner, | |
| 324 const base::File::Info& file_info, | |
| 325 const base::FilePath& platform_path) { | |
| 326 scoped_refptr<webkit_blob::ShareableFileReference> file = | |
| 327 ShareableFileReference::GetOrCreate( | |
| 328 platform_path, | |
| 329 ShareableFileReference::DELETE_ON_FINAL_RELEASE, | |
| 330 media_task_runner); | |
| 331 | |
| 332 if (validation_type_ == APPLY_MEDIA_FILE_VALIDATION) { | |
| 333 base::PostTaskAndReplyWithResult( | |
| 334 media_task_runner, | |
| 335 FROM_HERE, | |
| 336 base::Bind(&NativeMediaFileUtil::IsMediaFile, platform_path), | |
| 337 base::Bind(&DeviceMediaAsyncFileUtil::OnDidCheckMedia, | |
| 338 weak_ptr_factory_.GetWeakPtr(), | |
| 339 callback, | |
| 340 file_info, | |
| 341 file)); | |
| 342 } else { | |
| 343 OnDidCheckMedia(callback, file_info, file, base::File::FILE_OK); | |
| 344 } | |
| 345 } | |
| 346 | |
| 347 void DeviceMediaAsyncFileUtil::OnDidCheckMedia( | |
| 348 const AsyncFileUtil::CreateSnapshotFileCallback& callback, | |
| 349 const base::File::Info& file_info, | |
| 350 scoped_refptr<webkit_blob::ShareableFileReference> platform_file, | |
| 351 base::File::Error error) { | |
| 352 base::FilePath platform_path(platform_file.get()->path()); | |
| 353 if (error != base::File::FILE_OK) | |
| 354 platform_file = NULL; | |
| 355 callback.Run(error, file_info, platform_path, platform_file); | |
| 356 } | |
| 357 | |
| 358 void DeviceMediaAsyncFileUtil::OnCreateSnapshotFileError( | |
| 359 const AsyncFileUtil::CreateSnapshotFileCallback& callback, | |
| 360 base::File::Error error) { | |
| 361 callback.Run(error, base::File::Info(), base::FilePath(), | |
| 362 scoped_refptr<ShareableFileReference>()); | |
| 363 } | |
| 364 | |
| 365 void DeviceMediaAsyncFileUtil::OnSnapshotFileCreatedRunTask( | |
| 366 scoped_ptr<FileSystemOperationContext> context, | |
| 367 const AsyncFileUtil::CreateSnapshotFileCallback& callback, | |
| 368 const FileSystemURL& url, | |
| 369 const base::FilePath& snapshot_file_path) { | |
| 370 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
| 371 if (snapshot_file_path.empty()) { | |
| 372 OnCreateSnapshotFileError(callback, base::File::FILE_ERROR_FAILED); | |
| 373 return; | |
| 374 } | |
| 375 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(url); | |
| 376 if (!delegate) { | |
| 377 OnCreateSnapshotFileError(callback, base::File::FILE_ERROR_NOT_FOUND); | |
| 378 return; | |
| 379 } | |
| 380 delegate->CreateSnapshotFile( | |
| 381 url.path(), // device file path | |
| 382 snapshot_file_path, | |
| 383 base::Bind(&DeviceMediaAsyncFileUtil::OnDidCreateSnapshotFile, | |
| 384 weak_ptr_factory_.GetWeakPtr(), | |
| 385 callback, | |
| 386 make_scoped_refptr(context->task_runner())), | |
| 387 base::Bind(&DeviceMediaAsyncFileUtil::OnCreateSnapshotFileError, | |
| 388 weak_ptr_factory_.GetWeakPtr(), | |
| 389 callback)); | |
| 390 } | |
| OLD | NEW |