| 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/device_media_async_file_util.h" | 5 #include "webkit/fileapi/media/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 "webkit/fileapi/file_system_context.h" | 10 #include "webkit/fileapi/file_system_context.h" |
| 11 #include "webkit/fileapi/file_system_operation_context.h" | 11 #include "webkit/fileapi/file_system_operation_context.h" |
| 12 #include "webkit/fileapi/file_system_task_runners.h" | 12 #include "webkit/fileapi/file_system_task_runners.h" |
| 13 #include "webkit/fileapi/file_system_url.h" | 13 #include "webkit/fileapi/file_system_url.h" |
| 14 #include "webkit/fileapi/isolated_context.h" | 14 #include "webkit/fileapi/isolated_context.h" |
| 15 #include "webkit/fileapi/media/filtering_file_enumerator.h" | 15 #include "webkit/fileapi/media/filtering_file_enumerator.h" |
| 16 #include "webkit/fileapi/media/media_path_filter.h" | 16 #include "webkit/fileapi/media/media_path_filter.h" |
| 17 #include "webkit/fileapi/media/mtp_device_async_delegate.h" | 17 #include "webkit/fileapi/media/mtp_device_async_delegate.h" |
| 18 #include "webkit/fileapi/media/mtp_device_map_service.h" | 18 #include "webkit/fileapi/media/mtp_device_map_service.h" |
| 19 #include "webkit/fileapi/media/native_media_file_util.h" |
| 20 #include "webkit/fileapi/native_file_util.h" |
| 19 | 21 |
| 20 namespace fileapi { | 22 namespace fileapi { |
| 21 | 23 |
| 22 namespace { | 24 namespace { |
| 23 | 25 |
| 24 const base::FilePath::CharType kDeviceMediaAsyncFileUtilTempDir[] = | 26 const base::FilePath::CharType kDeviceMediaAsyncFileUtilTempDir[] = |
| 25 FILE_PATH_LITERAL("DeviceMediaFileSystem"); | 27 FILE_PATH_LITERAL("DeviceMediaFileSystem"); |
| 26 | 28 |
| 27 // Returns true if the current thread is IO thread. | 29 // Returns true if the current thread is IO thread. |
| 28 bool IsOnIOThread(FileSystemOperationContext* context) { | 30 bool IsOnIOThread(FileSystemOperationContext* context) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 53 profile_path.Append(kDeviceMediaAsyncFileUtilTempDir); | 55 profile_path.Append(kDeviceMediaAsyncFileUtilTempDir); |
| 54 if (!file_util::CreateDirectory(isolated_media_file_system_dir_path) || | 56 if (!file_util::CreateDirectory(isolated_media_file_system_dir_path) || |
| 55 !file_util::CreateTemporaryFileInDir(isolated_media_file_system_dir_path, | 57 !file_util::CreateTemporaryFileInDir(isolated_media_file_system_dir_path, |
| 56 snapshot_file_path)) { | 58 snapshot_file_path)) { |
| 57 LOG(WARNING) << "Could not create media snapshot file " | 59 LOG(WARNING) << "Could not create media snapshot file " |
| 58 << isolated_media_file_system_dir_path.value(); | 60 << isolated_media_file_system_dir_path.value(); |
| 59 *snapshot_file_path = base::FilePath(); | 61 *snapshot_file_path = base::FilePath(); |
| 60 } | 62 } |
| 61 } | 63 } |
| 62 | 64 |
| 65 void CheckMediaFile( |
| 66 const base::FilePath& file_path, |
| 67 base::PlatformFileError* error) { |
| 68 *error = NativeMediaFileUtil::IsMediaFile(file_path); |
| 69 if (*error == base::PLATFORM_FILE_ERROR_SECURITY) |
| 70 // It exists but we reject it. Try to clean up. |
| 71 NativeFileUtil::DeleteFile(file_path); |
| 72 } |
| 73 |
| 63 } // namespace | 74 } // namespace |
| 64 | 75 |
| 65 DeviceMediaAsyncFileUtil::~DeviceMediaAsyncFileUtil() { | 76 DeviceMediaAsyncFileUtil::~DeviceMediaAsyncFileUtil() { |
| 66 } | 77 } |
| 67 | 78 |
| 68 // static | 79 // static |
| 69 DeviceMediaAsyncFileUtil* DeviceMediaAsyncFileUtil::Create( | 80 DeviceMediaAsyncFileUtil* DeviceMediaAsyncFileUtil::Create( |
| 70 const base::FilePath& profile_path) { | 81 const base::FilePath& profile_path) { |
| 71 DCHECK(!profile_path.empty()); | 82 DCHECK(!profile_path.empty()); |
| 72 return new DeviceMediaAsyncFileUtil(profile_path); | 83 return new DeviceMediaAsyncFileUtil(profile_path); |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 } | 308 } |
| 298 | 309 |
| 299 void DeviceMediaAsyncFileUtil::OnReadDirectoryError( | 310 void DeviceMediaAsyncFileUtil::OnReadDirectoryError( |
| 300 const AsyncFileUtil::ReadDirectoryCallback& callback, | 311 const AsyncFileUtil::ReadDirectoryCallback& callback, |
| 301 base::PlatformFileError error) { | 312 base::PlatformFileError error) { |
| 302 if (!callback.is_null()) | 313 if (!callback.is_null()) |
| 303 callback.Run(error, AsyncFileUtil::EntryList(), false /*no more*/); | 314 callback.Run(error, AsyncFileUtil::EntryList(), false /*no more*/); |
| 304 } | 315 } |
| 305 | 316 |
| 306 void DeviceMediaAsyncFileUtil::OnDidCreateSnapshotFile( | 317 void DeviceMediaAsyncFileUtil::OnDidCreateSnapshotFile( |
| 318 FileSystemOperationContext* context, |
| 307 const AsyncFileUtil::CreateSnapshotFileCallback& callback, | 319 const AsyncFileUtil::CreateSnapshotFileCallback& callback, |
| 308 const base::PlatformFileInfo& file_info, | 320 const base::PlatformFileInfo& file_info, |
| 309 const base::FilePath& platform_path) { | 321 const base::FilePath& platform_path) { |
| 310 if (!callback.is_null()) | 322 base::PlatformFileError* error = new base::PlatformFileError; |
| 311 callback.Run(base::PLATFORM_FILE_OK, file_info, platform_path, | 323 context->file_system_context()->task_runners()->media_task_runner()-> |
| 312 kSnapshotFileTemporary); | 324 PostTaskAndReply( |
| 325 FROM_HERE, |
| 326 base::Bind(&CheckMediaFile, platform_path, |
| 327 base::Unretained(error)), |
| 328 base::Bind(&DeviceMediaAsyncFileUtil::OnDidCheckMediaRunTask, |
| 329 weak_ptr_factory_.GetWeakPtr(), |
| 330 callback, file_info, platform_path, |
| 331 base::Owned(error))); |
| 332 } |
| 333 |
| 334 void DeviceMediaAsyncFileUtil::OnDidCheckMediaRunTask( |
| 335 const AsyncFileUtil::CreateSnapshotFileCallback& callback, |
| 336 const base::PlatformFileInfo& file_info, |
| 337 const base::FilePath& platform_path, |
| 338 base::PlatformFileError* error) { |
| 339 if (!callback.is_null()) { |
| 340 callback.Run(*error, file_info, platform_path, kSnapshotFileTemporary); |
| 341 } |
| 313 } | 342 } |
| 314 | 343 |
| 315 void DeviceMediaAsyncFileUtil::OnCreateSnapshotFileError( | 344 void DeviceMediaAsyncFileUtil::OnCreateSnapshotFileError( |
| 316 const AsyncFileUtil::CreateSnapshotFileCallback& callback, | 345 const AsyncFileUtil::CreateSnapshotFileCallback& callback, |
| 317 base::PlatformFileError error) { | 346 base::PlatformFileError error) { |
| 318 if (!callback.is_null()) | 347 if (!callback.is_null()) |
| 319 callback.Run(error, base::PlatformFileInfo(), base::FilePath(), | 348 callback.Run(error, base::PlatformFileInfo(), base::FilePath(), |
| 320 kSnapshotFileTemporary); | 349 kSnapshotFileTemporary); |
| 321 } | 350 } |
| 322 | 351 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 333 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(context); | 362 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(context); |
| 334 if (!delegate) { | 363 if (!delegate) { |
| 335 OnCreateSnapshotFileError(callback, base::PLATFORM_FILE_ERROR_NOT_FOUND); | 364 OnCreateSnapshotFileError(callback, base::PLATFORM_FILE_ERROR_NOT_FOUND); |
| 336 return; | 365 return; |
| 337 } | 366 } |
| 338 delegate->CreateSnapshotFile( | 367 delegate->CreateSnapshotFile( |
| 339 device_file_path, | 368 device_file_path, |
| 340 *snapshot_file_path, | 369 *snapshot_file_path, |
| 341 base::Bind(&DeviceMediaAsyncFileUtil::OnDidCreateSnapshotFile, | 370 base::Bind(&DeviceMediaAsyncFileUtil::OnDidCreateSnapshotFile, |
| 342 weak_ptr_factory_.GetWeakPtr(), | 371 weak_ptr_factory_.GetWeakPtr(), |
| 372 context, |
| 343 callback), | 373 callback), |
| 344 base::Bind(&DeviceMediaAsyncFileUtil::OnCreateSnapshotFileError, | 374 base::Bind(&DeviceMediaAsyncFileUtil::OnCreateSnapshotFileError, |
| 345 weak_ptr_factory_.GetWeakPtr(), | 375 weak_ptr_factory_.GetWeakPtr(), |
| 346 callback)); | 376 callback)); |
| 347 } | 377 } |
| 348 | 378 |
| 349 } // namespace fileapi | 379 } // namespace fileapi |
| OLD | NEW |