Index: webkit/fileapi/media/device_media_file_util.cc |
diff --git a/webkit/fileapi/media/device_media_file_util.cc b/webkit/fileapi/media/device_media_file_util.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..31a5a0d1989a6491fc1e13990c85c58b031b1211 |
--- /dev/null |
+++ b/webkit/fileapi/media/device_media_file_util.cc |
@@ -0,0 +1,205 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "webkit/fileapi/media/device_media_file_util.h" |
+ |
+#include "base/message_loop_proxy.h" |
+#include "base/file_util.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "webkit/blob/shareable_file_reference.h" |
+#include "webkit/fileapi/file_system_operation_context.h" |
+#include "webkit/fileapi/file_system_url.h" |
+#include "webkit/fileapi/isolated_context.h" |
+#include "webkit/fileapi/media/media_device_map_service.h" |
+#include "webkit/fileapi/media/media_device_interface_impl.h" |
+ |
+using base::PlatformFileError; |
+using base::PlatformFileInfo; |
+using webkit_blob::ShareableFileReference; |
+ |
+namespace fileapi { |
+ |
+namespace { |
+ |
+const FilePath::CharType kIsolatedMediaFileSystemDir[] = |
+ FILE_PATH_LITERAL("IsolatedMediaFileSystem"); |
kinuko
2012/07/30 23:19:03
DeviceMediaFileSystem might reflect where the path
kmadhusu
2012/07/31 01:17:48
Done.
|
+ |
+} // namespace |
+ |
+DeviceMediaFileUtil::DeviceMediaFileUtil(const FilePath& profile_path) |
+ : profile_path_(profile_path) { |
+} |
+ |
+PlatformFileError DeviceMediaFileUtil::CreateOrOpen( |
+ FileSystemOperationContext* context, |
+ const FileSystemURL& url, int file_flags, |
+ PlatformFile* file_handle, bool* created) { |
+ return base::PLATFORM_FILE_ERROR_SECURITY; |
+} |
+ |
+PlatformFileError DeviceMediaFileUtil::Close( |
+ FileSystemOperationContext* context, |
+ PlatformFile file_handle) { |
+ // We don't allow open thus Close won't be called. |
+ return base::PLATFORM_FILE_ERROR_SECURITY; |
+} |
+ |
+PlatformFileError DeviceMediaFileUtil::EnsureFileExists( |
+ FileSystemOperationContext* context, |
+ const FileSystemURL& url, |
+ bool* created) { |
+ return base::PLATFORM_FILE_ERROR_SECURITY; |
+} |
+ |
+PlatformFileError DeviceMediaFileUtil::CreateDirectory( |
+ FileSystemOperationContext* context, |
+ const FileSystemURL& url, |
+ bool exclusive, |
+ bool recursive) { |
+ return base::PLATFORM_FILE_ERROR_SECURITY; |
+} |
+ |
+PlatformFileError DeviceMediaFileUtil::GetFileInfo( |
+ FileSystemOperationContext* context, |
+ const FileSystemURL& url, |
+ PlatformFileInfo* file_info, |
+ FilePath* platform_path) { |
+ scoped_refptr<MediaDeviceInterfaceImpl> device(context->media_device()); |
+ if (!device.get()) |
+ return base::PLATFORM_FILE_ERROR_INVALID_URL; |
+ *platform_path = url.path(); |
kinuko
2012/07/30 23:19:03
Returning this url.path() won't be usable outside
kmadhusu
2012/07/31 01:17:48
Done.
|
+ return device->GetFileInfo(*platform_path, file_info); |
kinuko
2012/07/30 23:19:03
nit: *platform_path -> url.path() (though they ha
kmadhusu
2012/07/31 01:17:48
Done.
|
+} |
+ |
+FileSystemFileUtil::AbstractFileEnumerator* |
+DeviceMediaFileUtil::CreateFileEnumerator( |
+ FileSystemOperationContext* context, |
+ const FileSystemURL& url, |
+ bool recursive) { |
+ scoped_refptr<MediaDeviceInterfaceImpl> device(context->media_device()); |
+ if (!device.get()) |
+ return new FileSystemFileUtil::EmptyFileEnumerator(); |
+ return device->CreateFileEnumerator(url.path(), recursive); |
+} |
+ |
+PlatformFileError DeviceMediaFileUtil::GetLocalFilePath( |
+ FileSystemOperationContext* context, |
+ const FileSystemURL& file_system_url, |
+ FilePath* local_file_path) { |
+ return base::PLATFORM_FILE_ERROR_SECURITY; |
+} |
+ |
+PlatformFileError DeviceMediaFileUtil::Touch( |
+ FileSystemOperationContext* context, |
+ const FileSystemURL& url, |
+ const base::Time& last_access_time, |
+ const base::Time& last_modified_time) { |
+ scoped_refptr<MediaDeviceInterfaceImpl> device(context->media_device()); |
+ if (!device.get()) |
+ return base::PLATFORM_FILE_ERROR_INVALID_URL; |
+ return device->Touch(url.path(), last_access_time, last_modified_time); |
+} |
+ |
+PlatformFileError DeviceMediaFileUtil::Truncate( |
+ FileSystemOperationContext* context, |
+ const FileSystemURL& url, |
+ int64 length) { |
+ return base::PLATFORM_FILE_ERROR_SECURITY; |
+} |
+ |
+bool DeviceMediaFileUtil::PathExists( |
+ FileSystemOperationContext* context, |
+ const FileSystemURL& url) { |
+ scoped_refptr<MediaDeviceInterfaceImpl> device(context->media_device()); |
+ if (!device.get()) |
+ return false; |
+ return device->PathExists(url.path()); |
+} |
+ |
+bool DeviceMediaFileUtil::DirectoryExists( |
+ FileSystemOperationContext* context, |
+ const FileSystemURL& url) { |
+ scoped_refptr<MediaDeviceInterfaceImpl> device(context->media_device()); |
+ if (!device.get()) |
+ return false; |
+ return device->DirectoryExists(url.path()); |
+} |
+ |
+bool DeviceMediaFileUtil::IsDirectoryEmpty( |
+ FileSystemOperationContext* context, |
+ const FileSystemURL& url) { |
+ scoped_refptr<MediaDeviceInterfaceImpl> device(context->media_device()); |
+ if (!device.get()) |
+ return false; |
+ return device->IsDirectoryEmpty(url.path()); |
+} |
+ |
+PlatformFileError DeviceMediaFileUtil::CopyOrMoveFile( |
+ FileSystemOperationContext* context, |
+ const FileSystemURL& src_url, |
+ const FileSystemURL& dest_url, |
+ bool copy) { |
+ return base::PLATFORM_FILE_ERROR_SECURITY; |
+} |
+ |
+PlatformFileError DeviceMediaFileUtil::CopyInForeignFile( |
+ FileSystemOperationContext* context, |
+ const FilePath& src_file_path, |
+ const FileSystemURL& dest_url) { |
+ return base::PLATFORM_FILE_ERROR_SECURITY; |
+} |
+ |
+PlatformFileError DeviceMediaFileUtil::DeleteFile( |
+ FileSystemOperationContext* context, |
+ const FileSystemURL& url) { |
+ return base::PLATFORM_FILE_ERROR_SECURITY; |
+} |
+ |
+PlatformFileError DeviceMediaFileUtil::DeleteSingleDirectory( |
+ FileSystemOperationContext* context, |
+ const FileSystemURL& url) { |
+ return base::PLATFORM_FILE_ERROR_SECURITY; |
+} |
+ |
+scoped_refptr<ShareableFileReference> DeviceMediaFileUtil::CreateSnapshotFile( |
+ FileSystemOperationContext* context, |
+ const FileSystemURL& url, |
+ base::PlatformFileError* result, |
+ base::PlatformFileInfo* file_info, |
+ FilePath* local_path) { |
kinuko
2012/07/30 23:19:03
Can we DCHECK out ptrs before we dereference them?
kmadhusu
2012/07/31 01:17:48
Done.
|
+ scoped_refptr<ShareableFileReference> file_ref; |
+ *result = base::PLATFORM_FILE_ERROR_INVALID_URL; |
+ |
+ scoped_refptr<MediaDeviceInterfaceImpl> device(context->media_device()); |
+ if (!device.get()) |
kinuko
2012/07/30 23:19:03
Maybe we should set a better error code to *result
kmadhusu
2012/07/31 01:17:48
This is very unlikely to happen. As we discussed,
|
+ return file_ref; |
+ |
+ // Create a temp file in "profile_path_/kIsolatedMediaFileSystemDir". |
+ FilePath isolated_media_file_system_dir_path = |
+ profile_path_.Append(kIsolatedMediaFileSystemDir); |
+ bool dir_exists = file_util::DirectoryExists( |
+ isolated_media_file_system_dir_path); |
+ if (!dir_exists) { |
+ if (!file_util::CreateDirectory(isolated_media_file_system_dir_path)) |
kinuko
2012/07/30 23:19:03
ditto.
kmadhusu
2012/07/31 01:17:48
Done.
|
+ return file_ref; |
+ } |
+ |
+ bool file_created = file_util::CreateTemporaryFileInDir( |
Lei Zhang
2012/07/30 23:03:25
kinuko: What do you think of this potential issue?
kinuko
2012/07/30 23:19:03
I see what you mean. I think we should rather fix
|
+ isolated_media_file_system_dir_path, local_path); |
+ if (!file_created) |
kinuko
2012/07/30 23:19:03
ditto.
kmadhusu
2012/07/31 01:17:48
Done.
|
+ return file_ref; |
+ |
+ if (device->CreateSnapshotFile(url.path(), *local_path, file_info)) |
+ *result = base::PLATFORM_FILE_OK; |
+ |
+ if (*result != base::PLATFORM_FILE_ERROR_INVALID_URL) { |
kinuko
2012/07/30 23:19:03
if (*result == base::PLATFORM_FILE_OK)
kmadhusu
2012/07/31 01:17:48
Done.
|
+ file_ref = ShareableFileReference::GetOrCreate( |
+ *local_path, |
+ ShareableFileReference::DELETE_ON_FINAL_RELEASE, |
+ context->file_task_runner()); |
+ } |
+ return file_ref; |
+} |
+ |
+} // namespace fileapi |