Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(130)

Side by Side Diff: chrome/browser/media_galleries/fileapi/device_media_async_file_util.cc

Issue 12703012: Have media gallery (through native media file util) use MIME sniffer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More minor changes. Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 callback.Run(error, AsyncFileUtil::EntryList(), false /*no more*/); 311 callback.Run(error, AsyncFileUtil::EntryList(), false /*no more*/);
310 } 312 }
311 313
312 void DeviceMediaAsyncFileUtil::OnDidCreateSnapshotFile( 314 void DeviceMediaAsyncFileUtil::OnDidCreateSnapshotFile(
313 const AsyncFileUtil::CreateSnapshotFileCallback& callback, 315 const AsyncFileUtil::CreateSnapshotFileCallback& callback,
314 base::SequencedTaskRunner* media_task_runner, 316 base::SequencedTaskRunner* media_task_runner,
315 const base::PlatformFileInfo& file_info, 317 const base::PlatformFileInfo& file_info,
316 const base::FilePath& platform_path) { 318 const base::FilePath& platform_path) {
317 if (callback.is_null()) 319 if (callback.is_null())
318 return; 320 return;
319 callback.Run(base::PLATFORM_FILE_OK, file_info, platform_path, 321 base::PlatformFileError* error = new base::PlatformFileError;
320 ShareableFileReference::GetOrCreate( 322 media_task_runner->PostTaskAndReply(
321 platform_path, 323 FROM_HERE,
322 ShareableFileReference::DELETE_ON_FINAL_RELEASE, 324 base::Bind(&NativeMediaFileUtil::IsMediaFile, platform_path,
323 media_task_runner)); 325 base::Unretained(error)),
326 base::Bind(&DeviceMediaAsyncFileUtil::OnDidCheckMedia,
327 weak_ptr_factory_.GetWeakPtr(),
328 callback, make_scoped_refptr(media_task_runner),
329 file_info,
330 ShareableFileReference::GetOrCreate(
331 platform_path,
332 ShareableFileReference::DELETE_ON_FINAL_RELEASE,
333 media_task_runner),
334 base::Owned(error)));
335 }
336
337 void DeviceMediaAsyncFileUtil::OnDidCheckMedia(
338 const AsyncFileUtil::CreateSnapshotFileCallback& callback,
339 base::SequencedTaskRunner* media_task_runner,
340 const base::PlatformFileInfo& file_info,
341 scoped_refptr<webkit_blob::ShareableFileReference> platform_file,
342 base::PlatformFileError* error) {
343 if (callback.is_null())
344 return;
345 if (*error == base::PLATFORM_FILE_OK) {
vandebo (ex-Chrome) 2013/05/02 21:58:24 Instead of doing the if else with the callback.Run
Kevin Bailey 2013/05/03 16:52:55 Hope this is what you meant.
346 callback.Run(base::PLATFORM_FILE_OK, file_info, platform_file.get()->path(),
347 platform_file);
348 } else {
349 base::FilePath platform_path(platform_file.get()->path());
350 callback.Run(*error, file_info, platform_path,
351 scoped_refptr<ShareableFileReference>());
352 }
324 } 353 }
325 354
326 void DeviceMediaAsyncFileUtil::OnCreateSnapshotFileError( 355 void DeviceMediaAsyncFileUtil::OnCreateSnapshotFileError(
327 const AsyncFileUtil::CreateSnapshotFileCallback& callback, 356 const AsyncFileUtil::CreateSnapshotFileCallback& callback,
328 base::PlatformFileError error) { 357 base::PlatformFileError error) {
329 if (!callback.is_null()) 358 if (!callback.is_null())
330 callback.Run(error, base::PlatformFileInfo(), base::FilePath(), 359 callback.Run(error, base::PlatformFileInfo(), base::FilePath(),
331 scoped_refptr<ShareableFileReference>()); 360 scoped_refptr<ShareableFileReference>());
332 } 361 }
333 362
(...skipping 18 matching lines...) Expand all
352 base::Bind(&DeviceMediaAsyncFileUtil::OnDidCreateSnapshotFile, 381 base::Bind(&DeviceMediaAsyncFileUtil::OnDidCreateSnapshotFile,
353 weak_ptr_factory_.GetWeakPtr(), 382 weak_ptr_factory_.GetWeakPtr(),
354 callback, 383 callback,
355 make_scoped_refptr(context->task_runner())), 384 make_scoped_refptr(context->task_runner())),
356 base::Bind(&DeviceMediaAsyncFileUtil::OnCreateSnapshotFileError, 385 base::Bind(&DeviceMediaAsyncFileUtil::OnCreateSnapshotFileError,
357 weak_ptr_factory_.GetWeakPtr(), 386 weak_ptr_factory_.GetWeakPtr(),
358 callback)); 387 callback));
359 } 388 }
360 389
361 } // namespace chrome 390 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698