| 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/isolated_mount_point_provider.h" |
| 15 #include "webkit/fileapi/media/filtering_file_enumerator.h" | 16 #include "webkit/fileapi/media/filtering_file_enumerator.h" |
| 16 #include "webkit/fileapi/media/media_path_filter.h" | 17 #include "webkit/fileapi/media/media_path_filter.h" |
| 17 #include "webkit/fileapi/media/mtp_device_async_delegate.h" | 18 #include "webkit/fileapi/media/mtp_device_async_delegate.h" |
| 18 #include "webkit/fileapi/media/mtp_device_map_service.h" | 19 #include "webkit/fileapi/media/mtp_device_map_service.h" |
| 19 | 20 |
| 20 namespace fileapi { | 21 namespace fileapi { |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 const base::FilePath::CharType kDeviceMediaAsyncFileUtilTempDir[] = | 25 const base::FilePath::CharType kDeviceMediaAsyncFileUtilTempDir[] = |
| 25 FILE_PATH_LITERAL("DeviceMediaFileSystem"); | 26 FILE_PATH_LITERAL("DeviceMediaFileSystem"); |
| 26 | 27 |
| 27 // Returns true if the current thread is IO thread. | 28 // Returns true if the current thread is IO thread. |
| 28 bool IsOnIOThread(FileSystemOperationContext* context) { | 29 bool IsOnIOThread(FileSystemOperationContext* context) { |
| 29 return context->file_system_context()->task_runners()-> | 30 return context->file_system_context()->task_runners()-> |
| 30 io_task_runner()->RunsTasksOnCurrentThread(); | 31 io_task_runner()->RunsTasksOnCurrentThread(); |
| 31 } | 32 } |
| 32 | 33 |
| 33 // Called on the IO thread. | 34 // Called on the IO thread. |
| 34 MTPDeviceAsyncDelegate* GetMTPDeviceDelegate( | 35 MTPDeviceAsyncDelegate* GetMTPDeviceDelegate( |
| 35 FileSystemOperationContext* context) { | 36 FileSystemOperationContext* context) { |
| 36 DCHECK(IsOnIOThread(context)); | 37 DCHECK(IsOnIOThread(context)); |
| 37 return MTPDeviceMapService::GetInstance()->GetMTPDeviceAsyncDelegate( | 38 return MTPDeviceMapService::GetInstance()->GetMTPDeviceAsyncDelegate( |
| 38 context->mtp_device_delegate_url()); | 39 context->GetUserValue<std::string>( |
| 40 IsolatedMountPointProvider::kMTPDeviceDelegateURLKey)); |
| 39 } | 41 } |
| 40 | 42 |
| 41 // Called on a blocking pool thread to create a snapshot file to hold the | 43 // Called on a blocking pool thread to create a snapshot file to hold the |
| 42 // contents of |device_file_path|. The snapshot file is created in | 44 // contents of |device_file_path|. The snapshot file is created in |
| 43 // "profile_path/kDeviceMediaAsyncFileUtilTempDir" directory. If the snapshot | 45 // "profile_path/kDeviceMediaAsyncFileUtilTempDir" directory. If the snapshot |
| 44 // file is created successfully, |snapshot_file_path| will be a non-empty file | 46 // file is created successfully, |snapshot_file_path| will be a non-empty file |
| 45 // path. In case of failure, the |snapshot_file_path| will be an empty file | 47 // path. In case of failure, the |snapshot_file_path| will be an empty file |
| 46 // path. | 48 // path. |
| 47 void CreateSnapshotFileOnBlockingPool( | 49 void CreateSnapshotFileOnBlockingPool( |
| 48 const base::FilePath& device_file_path, | 50 const base::FilePath& device_file_path, |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 FileSystemOperationContext* context, | 246 FileSystemOperationContext* context, |
| 245 const FileSystemURL& url, | 247 const FileSystemURL& url, |
| 246 const CreateSnapshotFileCallback& callback) { | 248 const CreateSnapshotFileCallback& callback) { |
| 247 DCHECK(IsOnIOThread(context)); | 249 DCHECK(IsOnIOThread(context)); |
| 248 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(context); | 250 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(context); |
| 249 if (!delegate) { | 251 if (!delegate) { |
| 250 OnCreateSnapshotFileError(callback, base::PLATFORM_FILE_ERROR_NOT_FOUND); | 252 OnCreateSnapshotFileError(callback, base::PLATFORM_FILE_ERROR_NOT_FOUND); |
| 251 return true; | 253 return true; |
| 252 } | 254 } |
| 253 base::FilePath* snapshot_file_path = new base::FilePath; | 255 base::FilePath* snapshot_file_path = new base::FilePath; |
| 254 return context->file_system_context()->task_runners()->media_task_runner()-> | 256 return context->task_runner()->PostTaskAndReply( |
| 255 PostTaskAndReply( | |
| 256 FROM_HERE, | 257 FROM_HERE, |
| 257 base::Bind(&CreateSnapshotFileOnBlockingPool, | 258 base::Bind(&CreateSnapshotFileOnBlockingPool, |
| 258 url.path(), | 259 url.path(), |
| 259 profile_path_, | 260 profile_path_, |
| 260 base::Unretained(snapshot_file_path)), | 261 base::Unretained(snapshot_file_path)), |
| 261 base::Bind(&DeviceMediaAsyncFileUtil::OnSnapshotFileCreatedRunTask, | 262 base::Bind(&DeviceMediaAsyncFileUtil::OnSnapshotFileCreatedRunTask, |
| 262 weak_ptr_factory_.GetWeakPtr(), | 263 weak_ptr_factory_.GetWeakPtr(), |
| 263 context, | 264 context, |
| 264 callback, | 265 callback, |
| 265 url.path(), | 266 url.path(), |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 *snapshot_file_path, | 341 *snapshot_file_path, |
| 341 base::Bind(&DeviceMediaAsyncFileUtil::OnDidCreateSnapshotFile, | 342 base::Bind(&DeviceMediaAsyncFileUtil::OnDidCreateSnapshotFile, |
| 342 weak_ptr_factory_.GetWeakPtr(), | 343 weak_ptr_factory_.GetWeakPtr(), |
| 343 callback), | 344 callback), |
| 344 base::Bind(&DeviceMediaAsyncFileUtil::OnCreateSnapshotFileError, | 345 base::Bind(&DeviceMediaAsyncFileUtil::OnCreateSnapshotFileError, |
| 345 weak_ptr_factory_.GetWeakPtr(), | 346 weak_ptr_factory_.GetWeakPtr(), |
| 346 callback)); | 347 callback)); |
| 347 } | 348 } |
| 348 | 349 |
| 349 } // namespace fileapi | 350 } // namespace fileapi |
| OLD | NEW |