Index: webkit/fileapi/media_file_util.cc |
diff --git a/webkit/fileapi/media_file_util.cc b/webkit/fileapi/media_file_util.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..dd986b150b20b86b81939551b5da7558a83e5259 |
--- /dev/null |
+++ b/webkit/fileapi/media_file_util.cc |
@@ -0,0 +1,213 @@ |
+// 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_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/media_device_map_service.h" |
+#include "webkit/fileapi/isolated_context.h" |
+ |
+#if defined(OS_WIN) |
+#include "webkit/fileapi/mtp_device_interface_win.h" |
+#elif defined(OS_POSIX) && !defined(OS_MACOSX) |
+#include "webkit/fileapi/mtp_device_interface_linux.h" |
+#endif |
+ |
+using base::PlatformFileError; |
+using base::PlatformFileInfo; |
+ |
+namespace fileapi { |
+ |
+MediaFileUtil::MediaFileUtil() { |
+} |
+ |
+PlatformFileError MediaFileUtil::CreateOrOpen( |
+ FileSystemOperationContext* context, |
+ const FileSystemURL& url, int file_flags, |
+ PlatformFile* file_handle, bool* created) { |
+ return base::PLATFORM_FILE_ERROR_SECURITY; |
+} |
+ |
+PlatformFileError MediaFileUtil::Close( |
+ FileSystemOperationContext* context, |
+ PlatformFile file_handle) { |
+ // We don't allow open thus Close won't be called. |
+ return base::PLATFORM_FILE_ERROR_SECURITY; |
+} |
+ |
+PlatformFileError MediaFileUtil::EnsureFileExists( |
+ FileSystemOperationContext* context, |
+ const FileSystemURL& url, |
+ bool* created) { |
+ return base::PLATFORM_FILE_ERROR_SECURITY; |
+} |
+ |
+PlatformFileError MediaFileUtil::CreateDirectory( |
+ FileSystemOperationContext* context, |
+ const FileSystemURL& url, |
+ bool exclusive, |
+ bool recursive) { |
+ return base::PLATFORM_FILE_ERROR_SECURITY; |
+} |
+ |
+PlatformFileError MediaFileUtil::GetFileInfo( |
+ FileSystemOperationContext* context, |
+ const FileSystemURL& url, |
+ PlatformFileInfo* file_info, |
+ FilePath* platform_path) { |
+ if (!GetPlatformPath(url, platform_path)) |
vandebo (ex-Chrome)
2012/07/24 21:36:55
nit: looks like you could put all of this into the
kmadhusu
2012/07/27 02:13:40
Done
|
+ return base::PLATFORM_FILE_ERROR_INVALID_URL; |
+ |
+ scoped_refptr<MediaDevice> device; |
+ if (!MediaDeviceMapService::GetInstance()->GetMediaDevice( |
+ platform_path->value(), &device)) { |
+ return base::PLATFORM_FILE_ERROR_INVALID_URL; |
+ } |
+ return device->GetFileInfo(*platform_path, file_info); |
+} |
+ |
+FileSystemFileUtil::AbstractFileEnumerator* |
+MediaFileUtil::CreateFileEnumerator( |
+ FileSystemOperationContext* context, |
+ const FileSystemURL& root, |
+ bool recursive) { |
+ FilePath platform_path; |
+ if (!GetPlatformPath(root, &platform_path)) |
+ return new FileSystemFileUtil::EmptyFileEnumerator(); |
+ |
+ scoped_refptr<MediaDevice> device; |
+ if (!MediaDeviceMapService::GetInstance()->GetMediaDevice( |
+ platform_path.value(), &device)) { |
+ return new FileSystemFileUtil::EmptyFileEnumerator(); |
+ } |
+ return device->CreateFileEnumerator(platform_path, recursive); |
+} |
+ |
+PlatformFileError MediaFileUtil::GetLocalFilePath( |
+ FileSystemOperationContext* context, |
+ const FileSystemURL& file_system_url, |
+ FilePath* local_file_path) { |
+ return base::PLATFORM_FILE_ERROR_SECURITY; |
+} |
+ |
+PlatformFileError MediaFileUtil::Touch( |
+ FileSystemOperationContext* context, |
+ const FileSystemURL& url, |
+ const base::Time& last_access_time, |
+ const base::Time& last_modified_time) { |
+ FilePath platform_path; |
+ if (!GetPlatformPath(url, &platform_path)) |
+ return base::PLATFORM_FILE_ERROR_INVALID_URL; |
+ |
+ scoped_refptr<MediaDevice> device; |
+ if (!MediaDeviceMapService::GetInstance()->GetMediaDevice( |
+ platform_path.value(), &device)) { |
+ return base::PLATFORM_FILE_ERROR_INVALID_URL; |
+ } |
+ return device->Touch(platform_path, last_access_time, last_modified_time); |
+} |
+ |
+PlatformFileError MediaFileUtil::Truncate( |
+ FileSystemOperationContext* context, |
+ const FileSystemURL& url, |
+ int64 length) { |
+ return base::PLATFORM_FILE_ERROR_SECURITY; |
+} |
+ |
+bool MediaFileUtil::PathExists( |
+ FileSystemOperationContext* context, |
+ const FileSystemURL& url) { |
+ FilePath platform_path; |
+ if (!GetPlatformPath(url, &platform_path)) |
+ return false; |
+ |
+ scoped_refptr<MediaDevice> device; |
+ if (!MediaDeviceMapService::GetInstance()->GetMediaDevice( |
+ platform_path.value(), &device)) { |
+ return false; |
+ } |
+ return device->PathExists(platform_path); |
+} |
+ |
+bool MediaFileUtil::DirectoryExists( |
+ FileSystemOperationContext* context, |
+ const FileSystemURL& url) { |
+ FilePath platform_path; |
+ if (!GetPlatformPath(url, &platform_path)) |
+ return false; |
+ |
+ scoped_refptr<MediaDevice> device; |
+ if (!MediaDeviceMapService::GetInstance()->GetMediaDevice( |
+ platform_path.value(), &device)) { |
+ return false; |
+ } |
+ return device->DirectoryExists(platform_path); |
+} |
+ |
+bool MediaFileUtil::IsDirectoryEmpty( |
+ FileSystemOperationContext* context, |
+ const FileSystemURL& url) { |
+ FilePath platform_path; |
+ if (!GetPlatformPath(url, &platform_path)) |
+ return false; |
+ |
+ scoped_refptr<MediaDevice> device; |
+ if (!MediaDeviceMapService::GetInstance()->GetMediaDevice( |
+ platform_path.value(), &device)) { |
+ return false; |
+ } |
+ return device->IsDirectoryEmpty(platform_path); |
+} |
+ |
+PlatformFileError MediaFileUtil::CopyOrMoveFile( |
+ FileSystemOperationContext* context, |
+ const FileSystemURL& src_url, |
+ const FileSystemURL& dest_url, |
+ bool copy) { |
+ return base::PLATFORM_FILE_ERROR_SECURITY; |
+} |
+ |
+PlatformFileError MediaFileUtil::CopyInForeignFile( |
+ FileSystemOperationContext* context, |
+ const FilePath& src_file_path, |
+ const FileSystemURL& dest_url) { |
+ return base::PLATFORM_FILE_ERROR_SECURITY; |
+} |
+ |
+PlatformFileError MediaFileUtil::DeleteFile( |
+ FileSystemOperationContext* context, |
+ const FileSystemURL& url) { |
+ return base::PLATFORM_FILE_ERROR_SECURITY; |
+} |
+ |
+PlatformFileError MediaFileUtil::DeleteSingleDirectory( |
+ FileSystemOperationContext* context, |
+ const FileSystemURL& url) { |
+ return base::PLATFORM_FILE_ERROR_SECURITY; |
+} |
+ |
+scoped_refptr<webkit_blob::ShareableFileReference> |
+ MediaFileUtil::CreateSnapshotFile( |
+ FileSystemOperationContext* context, |
+ const FileSystemURL& url, |
+ base::PlatformFileError* result, |
+ base::PlatformFileInfo* file_info, |
+ FilePath* platform_path) { |
+ return NULL; |
+} |
+ |
+bool MediaFileUtil::GetPlatformPath(const FileSystemURL& url, |
+ FilePath* platform_path) const { |
+ DCHECK(platform_path); |
+ std::string filesystem_id; |
+ if (!IsolatedContext::GetInstance()->CrackIsolatedPath( |
+ url.path(), &filesystem_id, NULL, platform_path)) |
+ return false; |
+ return true; |
+} |
+ |
+} // namespace |