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 "chrome/browser/media_galleries/fileapi/filtering_file_enumerator.h" | 10 #include "chrome/browser/media_galleries/fileapi/filtering_file_enumerator.h" |
11 #include "chrome/browser/media_galleries/fileapi/media_file_system_mount_point_p rovider.h" | 11 #include "chrome/browser/media_galleries/fileapi/media_file_system_mount_point_p rovider.h" |
12 #include "chrome/browser/media_galleries/fileapi/media_path_filter.h" | 12 #include "chrome/browser/media_galleries/fileapi/media_path_filter.h" |
13 #include "chrome/browser/media_galleries/fileapi/mtp_device_async_delegate.h" | 13 #include "chrome/browser/media_galleries/fileapi/mtp_device_async_delegate.h" |
14 #include "chrome/browser/media_galleries/fileapi/mtp_device_map_service.h" | 14 #include "chrome/browser/media_galleries/fileapi/mtp_device_map_service.h" |
15 #include "chrome/browser/media_galleries/fileapi/native_media_file_util.h" | |
15 #include "webkit/blob/shareable_file_reference.h" | 16 #include "webkit/blob/shareable_file_reference.h" |
16 #include "webkit/fileapi/file_system_context.h" | 17 #include "webkit/fileapi/file_system_context.h" |
17 #include "webkit/fileapi/file_system_operation_context.h" | 18 #include "webkit/fileapi/file_system_operation_context.h" |
18 #include "webkit/fileapi/file_system_task_runners.h" | 19 #include "webkit/fileapi/file_system_task_runners.h" |
19 #include "webkit/fileapi/file_system_url.h" | 20 #include "webkit/fileapi/file_system_url.h" |
20 #include "webkit/fileapi/isolated_context.h" | 21 #include "webkit/fileapi/isolated_context.h" |
22 #include "webkit/fileapi/native_file_util.h" | |
21 | 23 |
22 using fileapi::FileSystemOperationContext; | 24 using fileapi::FileSystemOperationContext; |
23 using fileapi::FileSystemURL; | 25 using fileapi::FileSystemURL; |
24 using webkit_blob::ShareableFileReference; | 26 using webkit_blob::ShareableFileReference; |
25 | 27 |
26 namespace chrome { | 28 namespace chrome { |
27 | 29 |
28 namespace { | 30 namespace { |
29 | 31 |
30 const base::FilePath::CharType kDeviceMediaAsyncFileUtilTempDir[] = | 32 const base::FilePath::CharType kDeviceMediaAsyncFileUtilTempDir[] = |
(...skipping 29 matching lines...) Expand all Loading... | |
60 profile_path.Append(kDeviceMediaAsyncFileUtilTempDir); | 62 profile_path.Append(kDeviceMediaAsyncFileUtilTempDir); |
61 if (!file_util::CreateDirectory(isolated_media_file_system_dir_path) || | 63 if (!file_util::CreateDirectory(isolated_media_file_system_dir_path) || |
62 !file_util::CreateTemporaryFileInDir(isolated_media_file_system_dir_path, | 64 !file_util::CreateTemporaryFileInDir(isolated_media_file_system_dir_path, |
63 snapshot_file_path)) { | 65 snapshot_file_path)) { |
64 LOG(WARNING) << "Could not create media snapshot file " | 66 LOG(WARNING) << "Could not create media snapshot file " |
65 << isolated_media_file_system_dir_path.value(); | 67 << isolated_media_file_system_dir_path.value(); |
66 *snapshot_file_path = base::FilePath(); | 68 *snapshot_file_path = base::FilePath(); |
67 } | 69 } |
68 } | 70 } |
69 | 71 |
72 void CheckMediaFile( | |
73 const base::FilePath& file_path, | |
74 base::PlatformFileError* error) { | |
75 *error = NativeMediaFileUtil::IsMediaFile(file_path); | |
76 if (*error == base::PLATFORM_FILE_ERROR_SECURITY) | |
vandebo (ex-Chrome)
2013/04/30 21:20:36
nit: {}'s because the body is multi line.
Kevin Bailey
2013/05/02 00:54:02
Removed function.
| |
77 // It exists but we reject it. Try to clean up. | |
78 fileapi::NativeFileUtil::DeleteFile(file_path); | |
79 } | |
80 | |
70 } // namespace | 81 } // namespace |
71 | 82 |
72 DeviceMediaAsyncFileUtil::~DeviceMediaAsyncFileUtil() { | 83 DeviceMediaAsyncFileUtil::~DeviceMediaAsyncFileUtil() { |
73 } | 84 } |
74 | 85 |
75 // static | 86 // static |
76 DeviceMediaAsyncFileUtil* DeviceMediaAsyncFileUtil::Create( | 87 DeviceMediaAsyncFileUtil* DeviceMediaAsyncFileUtil::Create( |
77 const base::FilePath& profile_path) { | 88 const base::FilePath& profile_path) { |
78 DCHECK(!profile_path.empty()); | 89 DCHECK(!profile_path.empty()); |
79 return new DeviceMediaAsyncFileUtil(profile_path); | 90 return new DeviceMediaAsyncFileUtil(profile_path); |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
309 callback.Run(error, AsyncFileUtil::EntryList(), false /*no more*/); | 320 callback.Run(error, AsyncFileUtil::EntryList(), false /*no more*/); |
310 } | 321 } |
311 | 322 |
312 void DeviceMediaAsyncFileUtil::OnDidCreateSnapshotFile( | 323 void DeviceMediaAsyncFileUtil::OnDidCreateSnapshotFile( |
313 const AsyncFileUtil::CreateSnapshotFileCallback& callback, | 324 const AsyncFileUtil::CreateSnapshotFileCallback& callback, |
314 base::SequencedTaskRunner* media_task_runner, | 325 base::SequencedTaskRunner* media_task_runner, |
315 const base::PlatformFileInfo& file_info, | 326 const base::PlatformFileInfo& file_info, |
316 const base::FilePath& platform_path) { | 327 const base::FilePath& platform_path) { |
317 if (callback.is_null()) | 328 if (callback.is_null()) |
318 return; | 329 return; |
319 callback.Run(base::PLATFORM_FILE_OK, file_info, platform_path, | 330 base::PlatformFileError* error = new base::PlatformFileError; |
320 ShareableFileReference::GetOrCreate( | 331 media_task_runner->PostTaskAndReply( |
321 platform_path, | 332 FROM_HERE, |
322 ShareableFileReference::DELETE_ON_FINAL_RELEASE, | 333 base::Bind(&CheckMediaFile, platform_path, |
323 media_task_runner)); | 334 base::Unretained(error)), |
335 base::Bind(&DeviceMediaAsyncFileUtil::OnDidCheckMediaRunTask, | |
336 weak_ptr_factory_.GetWeakPtr(), | |
337 callback, base::Unretained(media_task_runner), | |
kinuko
2013/05/01 02:03:46
Please pass media_task_runner as a refptr, i.e.
m
Kevin Bailey
2013/05/02 00:54:02
Done. It's unfortunate that it doesn't do that aut
| |
338 file_info, platform_path, base::Owned(error))); | |
kinuko
2013/05/01 02:03:46
nit: You can create a ShareableFileReference earli
Kevin Bailey
2013/05/02 00:54:02
I moved the GetOrCreate upstream but it seems like
| |
339 } | |
340 | |
341 void DeviceMediaAsyncFileUtil::OnDidCheckMediaRunTask( | |
342 const AsyncFileUtil::CreateSnapshotFileCallback& callback, | |
343 base::SequencedTaskRunner* media_task_runner, | |
344 const base::PlatformFileInfo& file_info, | |
345 const base::FilePath& platform_path, | |
346 base::PlatformFileError* error) { | |
347 // really should be an assertion | |
348 if (callback.is_null()) | |
349 return; | |
350 if (*error == base::PLATFORM_FILE_OK) { | |
351 callback.Run(base::PLATFORM_FILE_OK, file_info, platform_path, | |
352 ShareableFileReference::GetOrCreate( | |
353 platform_path, | |
354 ShareableFileReference::DELETE_ON_FINAL_RELEASE, | |
355 media_task_runner)); | |
356 } else { | |
357 callback.Run(*error, file_info, platform_path, | |
358 scoped_refptr<ShareableFileReference>()); | |
359 } | |
324 } | 360 } |
325 | 361 |
326 void DeviceMediaAsyncFileUtil::OnCreateSnapshotFileError( | 362 void DeviceMediaAsyncFileUtil::OnCreateSnapshotFileError( |
327 const AsyncFileUtil::CreateSnapshotFileCallback& callback, | 363 const AsyncFileUtil::CreateSnapshotFileCallback& callback, |
328 base::PlatformFileError error) { | 364 base::PlatformFileError error) { |
329 if (!callback.is_null()) | 365 if (!callback.is_null()) |
330 callback.Run(error, base::PlatformFileInfo(), base::FilePath(), | 366 callback.Run(error, base::PlatformFileInfo(), base::FilePath(), |
331 scoped_refptr<ShareableFileReference>()); | 367 scoped_refptr<ShareableFileReference>()); |
332 } | 368 } |
333 | 369 |
(...skipping 18 matching lines...) Expand all Loading... | |
352 base::Bind(&DeviceMediaAsyncFileUtil::OnDidCreateSnapshotFile, | 388 base::Bind(&DeviceMediaAsyncFileUtil::OnDidCreateSnapshotFile, |
353 weak_ptr_factory_.GetWeakPtr(), | 389 weak_ptr_factory_.GetWeakPtr(), |
354 callback, | 390 callback, |
355 make_scoped_refptr(context->task_runner())), | 391 make_scoped_refptr(context->task_runner())), |
356 base::Bind(&DeviceMediaAsyncFileUtil::OnCreateSnapshotFileError, | 392 base::Bind(&DeviceMediaAsyncFileUtil::OnCreateSnapshotFileError, |
357 weak_ptr_factory_.GetWeakPtr(), | 393 weak_ptr_factory_.GetWeakPtr(), |
358 callback)); | 394 callback)); |
359 } | 395 } |
360 | 396 |
361 } // namespace chrome | 397 } // namespace chrome |
OLD | NEW |