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_file_system_config.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->mtp_device_delegate_url()); |
39 } | 40 } |
40 | 41 |
41 // Called on the blocking pool thread to create a snapshot file to hold the | 42 // 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 | 43 // contents of |device_file_path|. The snapshot file is created in |
43 // "profile_path/kDeviceMediaAsyncFileUtilTempDir" directory. If the snapshot | 44 // "profile_path/kDeviceMediaAsyncFileUtilTempDir" directory. If the snapshot |
44 // file is created successfully, |snapshot_file_path| will be a non-empty file | 45 // 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 | 46 // path. In case of failure, the |snapshot_file_path| will be an empty file |
46 // path. | 47 // path. |
47 void CreateSnapshotFileOnBlockingPool( | 48 void CreateSnapshotFileOnBlockingPool( |
48 const base::FilePath& device_file_path, | 49 const base::FilePath& device_file_path, |
49 const base::FilePath& profile_path, | 50 const base::FilePath& profile_path, |
50 base::FilePath* snapshot_file_path) { | 51 base::FilePath* snapshot_file_path) { |
51 DCHECK(snapshot_file_path); | 52 DCHECK(snapshot_file_path); |
52 base::FilePath isolated_media_file_system_dir_path = | 53 base::FilePath isolated_media_file_system_dir_path = |
53 profile_path.Append(kDeviceMediaAsyncFileUtilTempDir); | 54 profile_path.Append(kDeviceMediaAsyncFileUtilTempDir); |
54 if (!file_util::CreateDirectory(isolated_media_file_system_dir_path) || | 55 if (!file_util::CreateDirectory(isolated_media_file_system_dir_path) || |
55 !file_util::CreateTemporaryFileInDir(isolated_media_file_system_dir_path, | 56 !file_util::CreateTemporaryFileInDir(isolated_media_file_system_dir_path, |
56 snapshot_file_path)) { | 57 snapshot_file_path)) { |
57 LOG(WARNING) << "Could not create media snapshot file " | 58 LOG(WARNING) << "Could not create media snapshot file " |
58 << isolated_media_file_system_dir_path.value(); | 59 << isolated_media_file_system_dir_path.value(); |
59 *snapshot_file_path = base::FilePath(); | 60 *snapshot_file_path = base::FilePath(); |
60 } | 61 } |
61 } | 62 } |
62 | 63 |
63 } // namespace | 64 } // namespace |
64 | 65 |
65 DeviceMediaAsyncFileUtil::~DeviceMediaAsyncFileUtil() { | 66 DeviceMediaAsyncFileUtil::~DeviceMediaAsyncFileUtil() { |
66 } | 67 } |
67 | 68 |
68 // static | 69 // static |
69 DeviceMediaAsyncFileUtil* DeviceMediaAsyncFileUtil::Create( | 70 DeviceMediaAsyncFileUtil* DeviceMediaAsyncFileUtil::Create( |
70 const base::FilePath& profile_path) { | 71 const base::FilePath& profile_path) { |
| 72 #if defined(USE_MTP_DEVICE_ASYNC_DELEGATE) |
| 73 DCHECK(!profile_path.empty()); |
| 74 return new DeviceMediaAsyncFileUtil(profile_path); |
| 75 #else |
71 return NULL; | 76 return NULL; |
| 77 #endif |
72 } | 78 } |
73 | 79 |
74 bool DeviceMediaAsyncFileUtil::CreateOrOpen( | 80 bool DeviceMediaAsyncFileUtil::CreateOrOpen( |
75 FileSystemOperationContext* context, | 81 FileSystemOperationContext* context, |
76 const FileSystemURL& url, | 82 const FileSystemURL& url, |
77 int file_flags, | 83 int file_flags, |
78 const CreateOrOpenCallback& callback) { | 84 const CreateOrOpenCallback& callback) { |
79 DCHECK(IsOnIOThread(context)); | 85 DCHECK(IsOnIOThread(context)); |
80 NOTIMPLEMENTED(); | 86 NOTIMPLEMENTED(); |
81 if (!callback.is_null()) { | 87 if (!callback.is_null()) { |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 *snapshot_file_path, | 345 *snapshot_file_path, |
340 base::Bind(&DeviceMediaAsyncFileUtil::OnDidCreateSnapshotFile, | 346 base::Bind(&DeviceMediaAsyncFileUtil::OnDidCreateSnapshotFile, |
341 weak_ptr_factory_.GetWeakPtr(), | 347 weak_ptr_factory_.GetWeakPtr(), |
342 callback), | 348 callback), |
343 base::Bind(&DeviceMediaAsyncFileUtil::OnCreateSnapshotFileError, | 349 base::Bind(&DeviceMediaAsyncFileUtil::OnCreateSnapshotFileError, |
344 weak_ptr_factory_.GetWeakPtr(), | 350 weak_ptr_factory_.GetWeakPtr(), |
345 callback)); | 351 callback)); |
346 } | 352 } |
347 | 353 |
348 } // namespace fileapi | 354 } // namespace fileapi |
OLD | NEW |