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

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: Oops, forgot, I can now add Flash 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 "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_file_system_mount_point_provider.h" 16 #include "webkit/fileapi/media/media_file_system_mount_point_provider.h"
17 #include "webkit/fileapi/media/media_path_filter.h" 17 #include "webkit/fileapi/media/media_path_filter.h"
18 #include "webkit/fileapi/media/mtp_device_async_delegate.h" 18 #include "webkit/fileapi/media/mtp_device_async_delegate.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 25 matching lines...) Expand all
55 profile_path.Append(kDeviceMediaAsyncFileUtilTempDir); 57 profile_path.Append(kDeviceMediaAsyncFileUtilTempDir);
56 if (!file_util::CreateDirectory(isolated_media_file_system_dir_path) || 58 if (!file_util::CreateDirectory(isolated_media_file_system_dir_path) ||
57 !file_util::CreateTemporaryFileInDir(isolated_media_file_system_dir_path, 59 !file_util::CreateTemporaryFileInDir(isolated_media_file_system_dir_path,
58 snapshot_file_path)) { 60 snapshot_file_path)) {
59 LOG(WARNING) << "Could not create media snapshot file " 61 LOG(WARNING) << "Could not create media snapshot file "
60 << isolated_media_file_system_dir_path.value(); 62 << isolated_media_file_system_dir_path.value();
61 *snapshot_file_path = base::FilePath(); 63 *snapshot_file_path = base::FilePath();
62 } 64 }
63 } 65 }
64 66
67 void CheckMediaFile(
68 const base::FilePath& file_path,
69 base::PlatformFileError* error) {
70 *error = NativeMediaFileUtil::IsMediaFile(file_path);
71 if (*error == base::PLATFORM_FILE_ERROR_SECURITY)
72 // It exists but we reject it. Try to clean up.
73 NativeFileUtil::DeleteFile(file_path);
74 }
75
65 } // namespace 76 } // namespace
66 77
67 DeviceMediaAsyncFileUtil::~DeviceMediaAsyncFileUtil() { 78 DeviceMediaAsyncFileUtil::~DeviceMediaAsyncFileUtil() {
68 } 79 }
69 80
70 // static 81 // static
71 DeviceMediaAsyncFileUtil* DeviceMediaAsyncFileUtil::Create( 82 DeviceMediaAsyncFileUtil* DeviceMediaAsyncFileUtil::Create(
72 const base::FilePath& profile_path) { 83 const base::FilePath& profile_path) {
73 DCHECK(!profile_path.empty()); 84 DCHECK(!profile_path.empty());
74 return new DeviceMediaAsyncFileUtil(profile_path); 85 return new DeviceMediaAsyncFileUtil(profile_path);
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 } 309 }
299 310
300 void DeviceMediaAsyncFileUtil::OnReadDirectoryError( 311 void DeviceMediaAsyncFileUtil::OnReadDirectoryError(
301 const AsyncFileUtil::ReadDirectoryCallback& callback, 312 const AsyncFileUtil::ReadDirectoryCallback& callback,
302 base::PlatformFileError error) { 313 base::PlatformFileError error) {
303 if (!callback.is_null()) 314 if (!callback.is_null())
304 callback.Run(error, AsyncFileUtil::EntryList(), false /*no more*/); 315 callback.Run(error, AsyncFileUtil::EntryList(), false /*no more*/);
305 } 316 }
306 317
307 void DeviceMediaAsyncFileUtil::OnDidCreateSnapshotFile( 318 void DeviceMediaAsyncFileUtil::OnDidCreateSnapshotFile(
319 FileSystemOperationContext* context,
308 const AsyncFileUtil::CreateSnapshotFileCallback& callback, 320 const AsyncFileUtil::CreateSnapshotFileCallback& callback,
309 const base::PlatformFileInfo& file_info, 321 const base::PlatformFileInfo& file_info,
310 const base::FilePath& platform_path) { 322 const base::FilePath& platform_path) {
311 if (!callback.is_null()) 323 base::PlatformFileError* error = new base::PlatformFileError;
312 callback.Run(base::PLATFORM_FILE_OK, file_info, platform_path, 324 context->file_system_context()->task_runners()->media_task_runner()->
313 kSnapshotFileTemporary); 325 PostTaskAndReply(
326 FROM_HERE,
327 base::Bind(&CheckMediaFile, platform_path,
328 base::Unretained(error)),
329 base::Bind(&DeviceMediaAsyncFileUtil::OnDidCheckMediaRunTask,
330 weak_ptr_factory_.GetWeakPtr(),
331 callback, file_info, platform_path,
332 base::Owned(error)));
333 }
334
335 void DeviceMediaAsyncFileUtil::OnDidCheckMediaRunTask(
336 const AsyncFileUtil::CreateSnapshotFileCallback& callback,
337 const base::PlatformFileInfo& file_info,
338 const base::FilePath& platform_path,
339 base::PlatformFileError* error) {
340 if (!callback.is_null()) {
341 callback.Run(*error, file_info, platform_path, kSnapshotFileTemporary);
342 }
314 } 343 }
315 344
316 void DeviceMediaAsyncFileUtil::OnCreateSnapshotFileError( 345 void DeviceMediaAsyncFileUtil::OnCreateSnapshotFileError(
317 const AsyncFileUtil::CreateSnapshotFileCallback& callback, 346 const AsyncFileUtil::CreateSnapshotFileCallback& callback,
318 base::PlatformFileError error) { 347 base::PlatformFileError error) {
319 if (!callback.is_null()) 348 if (!callback.is_null())
320 callback.Run(error, base::PlatformFileInfo(), base::FilePath(), 349 callback.Run(error, base::PlatformFileInfo(), base::FilePath(),
321 kSnapshotFileTemporary); 350 kSnapshotFileTemporary);
322 } 351 }
323 352
(...skipping 10 matching lines...) Expand all
334 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(context); 363 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(context);
335 if (!delegate) { 364 if (!delegate) {
336 OnCreateSnapshotFileError(callback, base::PLATFORM_FILE_ERROR_NOT_FOUND); 365 OnCreateSnapshotFileError(callback, base::PLATFORM_FILE_ERROR_NOT_FOUND);
337 return; 366 return;
338 } 367 }
339 delegate->CreateSnapshotFile( 368 delegate->CreateSnapshotFile(
340 device_file_path, 369 device_file_path,
341 *snapshot_file_path, 370 *snapshot_file_path,
342 base::Bind(&DeviceMediaAsyncFileUtil::OnDidCreateSnapshotFile, 371 base::Bind(&DeviceMediaAsyncFileUtil::OnDidCreateSnapshotFile,
343 weak_ptr_factory_.GetWeakPtr(), 372 weak_ptr_factory_.GetWeakPtr(),
373 context,
344 callback), 374 callback),
345 base::Bind(&DeviceMediaAsyncFileUtil::OnCreateSnapshotFileError, 375 base::Bind(&DeviceMediaAsyncFileUtil::OnCreateSnapshotFileError,
346 weak_ptr_factory_.GetWeakPtr(), 376 weak_ptr_factory_.GetWeakPtr(),
347 callback)); 377 callback));
348 } 378 }
349 379
350 } // namespace fileapi 380 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698