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

Side by Side Diff: webkit/fileapi/media/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: Fixed "which thread" errors. Created 7 years, 8 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 "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_file_system_config.h"
19 #include "webkit/fileapi/media/mtp_device_map_service.h" 19 #include "webkit/fileapi/media/mtp_device_map_service.h"
20 #include "webkit/fileapi/media/native_media_file_util.h"
21 #include "webkit/fileapi/native_file_util.h"
20 22
21 namespace fileapi { 23 namespace fileapi {
22 24
23 namespace { 25 namespace {
24 26
25 const base::FilePath::CharType kDeviceMediaAsyncFileUtilTempDir[] = 27 const base::FilePath::CharType kDeviceMediaAsyncFileUtilTempDir[] =
26 FILE_PATH_LITERAL("DeviceMediaFileSystem"); 28 FILE_PATH_LITERAL("DeviceMediaFileSystem");
27 29
28 // Returns true if the current thread is IO thread. 30 // Returns true if the current thread is IO thread.
29 bool IsOnIOThread(FileSystemOperationContext* context) { 31 bool IsOnIOThread(FileSystemOperationContext* context) {
(...skipping 24 matching lines...) Expand all
54 profile_path.Append(kDeviceMediaAsyncFileUtilTempDir); 56 profile_path.Append(kDeviceMediaAsyncFileUtilTempDir);
55 if (!file_util::CreateDirectory(isolated_media_file_system_dir_path) || 57 if (!file_util::CreateDirectory(isolated_media_file_system_dir_path) ||
56 !file_util::CreateTemporaryFileInDir(isolated_media_file_system_dir_path, 58 !file_util::CreateTemporaryFileInDir(isolated_media_file_system_dir_path,
57 snapshot_file_path)) { 59 snapshot_file_path)) {
58 LOG(WARNING) << "Could not create media snapshot file " 60 LOG(WARNING) << "Could not create media snapshot file "
59 << isolated_media_file_system_dir_path.value(); 61 << isolated_media_file_system_dir_path.value();
60 *snapshot_file_path = base::FilePath(); 62 *snapshot_file_path = base::FilePath();
61 } 63 }
62 } 64 }
63 65
66 void CheckMediaFile(
67 const base::FilePath& file_path,
68 base::PlatformFileError* p_error) {
vandebo (ex-Chrome) 2013/03/29 21:53:20 nit: error, not p_error in all your change.
Kevin Bailey 2013/04/03 18:05:07 Done.
69 *p_error = NativeMediaFileUtil::IsMediaFile(file_path);
70 if (*p_error == base::PLATFORM_FILE_ERROR_SECURITY)
71 // It exists but we reject it. Try to clean up.
72 NativeFileUtil::DeleteFile(file_path);
73 }
74
64 } // namespace 75 } // namespace
65 76
66 DeviceMediaAsyncFileUtil::~DeviceMediaAsyncFileUtil() { 77 DeviceMediaAsyncFileUtil::~DeviceMediaAsyncFileUtil() {
67 } 78 }
68 79
69 // static 80 // static
70 DeviceMediaAsyncFileUtil* DeviceMediaAsyncFileUtil::Create( 81 DeviceMediaAsyncFileUtil* DeviceMediaAsyncFileUtil::Create(
71 const base::FilePath& profile_path) { 82 const base::FilePath& profile_path) {
72 #if defined(USE_MTP_DEVICE_ASYNC_DELEGATE) 83 #if defined(USE_MTP_DEVICE_ASYNC_DELEGATE)
73 DCHECK(!profile_path.empty()); 84 DCHECK(!profile_path.empty());
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 } 313 }
303 314
304 void DeviceMediaAsyncFileUtil::OnReadDirectoryError( 315 void DeviceMediaAsyncFileUtil::OnReadDirectoryError(
305 const AsyncFileUtil::ReadDirectoryCallback& callback, 316 const AsyncFileUtil::ReadDirectoryCallback& callback,
306 base::PlatformFileError error) { 317 base::PlatformFileError error) {
307 if (!callback.is_null()) 318 if (!callback.is_null())
308 callback.Run(error, AsyncFileUtil::EntryList(), false /*no more*/); 319 callback.Run(error, AsyncFileUtil::EntryList(), false /*no more*/);
309 } 320 }
310 321
311 void DeviceMediaAsyncFileUtil::OnDidCreateSnapshotFile( 322 void DeviceMediaAsyncFileUtil::OnDidCreateSnapshotFile(
323 FileSystemOperationContext* context,
312 const AsyncFileUtil::CreateSnapshotFileCallback& callback, 324 const AsyncFileUtil::CreateSnapshotFileCallback& callback,
313 const base::PlatformFileInfo& file_info, 325 const base::PlatformFileInfo& file_info,
314 const base::FilePath& platform_path) { 326 const base::FilePath& platform_path) {
315 if (!callback.is_null()) 327 base::PlatformFileError* p_error = new base::PlatformFileError;
316 callback.Run(base::PLATFORM_FILE_OK, file_info, platform_path, 328 context->file_system_context()->task_runners()->media_task_runner()->
317 kSnapshotFileTemporary); 329 PostTaskAndReply(
330 FROM_HERE,
331 base::Bind(&CheckMediaFile, platform_path,
332 base::Unretained(p_error)),
333 base::Bind(&DeviceMediaAsyncFileUtil::OnDidCheckMediaRunTask,
334 weak_ptr_factory_.GetWeakPtr(),
335 callback, file_info, platform_path,
336 base::Owned(p_error)));
337 }
338
339 void DeviceMediaAsyncFileUtil::OnDidCheckMediaRunTask(
340 const AsyncFileUtil::CreateSnapshotFileCallback& callback,
341 const base::PlatformFileInfo& file_info,
342 const base::FilePath& platform_path,
343 base::PlatformFileError* p_error) {
344 if (!callback.is_null()) {
345 callback.Run(*p_error, file_info, platform_path, kSnapshotFileTemporary);
346 }
318 } 347 }
319 348
320 void DeviceMediaAsyncFileUtil::OnCreateSnapshotFileError( 349 void DeviceMediaAsyncFileUtil::OnCreateSnapshotFileError(
321 const AsyncFileUtil::CreateSnapshotFileCallback& callback, 350 const AsyncFileUtil::CreateSnapshotFileCallback& callback,
322 base::PlatformFileError error) { 351 base::PlatformFileError error) {
323 if (!callback.is_null()) 352 if (!callback.is_null())
324 callback.Run(error, base::PlatformFileInfo(), base::FilePath(), 353 callback.Run(error, base::PlatformFileInfo(), base::FilePath(),
325 kSnapshotFileTemporary); 354 kSnapshotFileTemporary);
326 } 355 }
327 356
(...skipping 10 matching lines...) Expand all
338 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(context); 367 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(context);
339 if (!delegate) { 368 if (!delegate) {
340 OnCreateSnapshotFileError(callback, base::PLATFORM_FILE_ERROR_NOT_FOUND); 369 OnCreateSnapshotFileError(callback, base::PLATFORM_FILE_ERROR_NOT_FOUND);
341 return; 370 return;
342 } 371 }
343 delegate->CreateSnapshotFile( 372 delegate->CreateSnapshotFile(
344 device_file_path, 373 device_file_path,
345 *snapshot_file_path, 374 *snapshot_file_path,
346 base::Bind(&DeviceMediaAsyncFileUtil::OnDidCreateSnapshotFile, 375 base::Bind(&DeviceMediaAsyncFileUtil::OnDidCreateSnapshotFile,
347 weak_ptr_factory_.GetWeakPtr(), 376 weak_ptr_factory_.GetWeakPtr(),
377 context,
348 callback), 378 callback),
349 base::Bind(&DeviceMediaAsyncFileUtil::OnCreateSnapshotFileError, 379 base::Bind(&DeviceMediaAsyncFileUtil::OnCreateSnapshotFileError,
350 weak_ptr_factory_.GetWeakPtr(), 380 weak_ptr_factory_.GetWeakPtr(),
351 callback)); 381 callback));
352 } 382 }
353 383
354 } // namespace fileapi 384 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/media/device_media_async_file_util.h ('k') | webkit/fileapi/media/native_media_file_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698