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

Unified 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: Correct style in test. 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 side-by-side diff with in-line comments
Download patch
Index: webkit/fileapi/media/device_media_async_file_util.cc
diff --git a/webkit/fileapi/media/device_media_async_file_util.cc b/webkit/fileapi/media/device_media_async_file_util.cc
index 6235696ded0ad7a8fa692d1d1da720dfc779978b..19500c9b3ff79a46c6b60b8d62150331158a4255 100644
--- a/webkit/fileapi/media/device_media_async_file_util.cc
+++ b/webkit/fileapi/media/device_media_async_file_util.cc
@@ -17,6 +17,8 @@
#include "webkit/fileapi/media/mtp_device_async_delegate.h"
#include "webkit/fileapi/media/mtp_device_file_system_config.h"
#include "webkit/fileapi/media/mtp_device_map_service.h"
+#include "webkit/fileapi/media/native_media_file_util.h"
+#include "webkit/fileapi/native_file_util.h"
namespace fileapi {
@@ -61,6 +63,15 @@ void CreateSnapshotFileOnBlockingPool(
}
}
+void CheckMediaFile(
+ const base::FilePath& file_path,
+ base::PlatformFileError* error) {
+ *error = NativeMediaFileUtil::IsMediaFile(file_path);
+ if (*error == base::PLATFORM_FILE_ERROR_SECURITY)
+ // It exists but we reject it. Try to clean up.
+ NativeFileUtil::DeleteFile(file_path);
+}
+
} // namespace
DeviceMediaAsyncFileUtil::~DeviceMediaAsyncFileUtil() {
@@ -309,12 +320,30 @@ void DeviceMediaAsyncFileUtil::OnReadDirectoryError(
}
void DeviceMediaAsyncFileUtil::OnDidCreateSnapshotFile(
+ FileSystemOperationContext* context,
const AsyncFileUtil::CreateSnapshotFileCallback& callback,
const base::PlatformFileInfo& file_info,
const base::FilePath& platform_path) {
- if (!callback.is_null())
- callback.Run(base::PLATFORM_FILE_OK, file_info, platform_path,
- kSnapshotFileTemporary);
+ base::PlatformFileError* error = new base::PlatformFileError;
+ context->file_system_context()->task_runners()->media_task_runner()->
+ PostTaskAndReply(
+ FROM_HERE,
+ base::Bind(&CheckMediaFile, platform_path,
+ base::Unretained(error)),
+ base::Bind(&DeviceMediaAsyncFileUtil::OnDidCheckMediaRunTask,
+ weak_ptr_factory_.GetWeakPtr(),
+ callback, file_info, platform_path,
+ base::Owned(error)));
+}
+
+void DeviceMediaAsyncFileUtil::OnDidCheckMediaRunTask(
+ const AsyncFileUtil::CreateSnapshotFileCallback& callback,
+ const base::PlatformFileInfo& file_info,
+ const base::FilePath& platform_path,
+ base::PlatformFileError* error) {
+ if (!callback.is_null()) {
+ callback.Run(*error, file_info, platform_path, kSnapshotFileTemporary);
+ }
}
void DeviceMediaAsyncFileUtil::OnCreateSnapshotFileError(
@@ -345,6 +374,7 @@ void DeviceMediaAsyncFileUtil::OnSnapshotFileCreatedRunTask(
*snapshot_file_path,
base::Bind(&DeviceMediaAsyncFileUtil::OnDidCreateSnapshotFile,
weak_ptr_factory_.GetWeakPtr(),
+ context,
callback),
base::Bind(&DeviceMediaAsyncFileUtil::OnCreateSnapshotFileError,
weak_ptr_factory_.GetWeakPtr(),

Powered by Google App Engine
This is Rietveld 408576698