Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "webkit/fileapi/media/device_media_file_util.h" | |
| 6 | |
| 7 #include "base/file_util.h" | |
| 8 #include "base/memory/scoped_ptr.h" | |
| 9 #include "base/message_loop_proxy.h" | |
| 10 #include "webkit/blob/shareable_file_reference.h" | |
| 11 #include "webkit/fileapi/file_system_operation_context.h" | |
| 12 #include "webkit/fileapi/file_system_url.h" | |
| 13 #include "webkit/fileapi/isolated_context.h" | |
| 14 #include "webkit/fileapi/media/media_device_interface_impl.h" | |
| 15 #include "webkit/fileapi/media/media_device_map_service.h" | |
| 16 | |
| 17 using base::PlatformFileError; | |
| 18 using base::PlatformFileInfo; | |
| 19 using webkit_blob::ShareableFileReference; | |
| 20 | |
| 21 namespace fileapi { | |
| 22 | |
| 23 namespace { | |
| 24 | |
| 25 const FilePath::CharType kDeviceMediaFileUtilTempDir[] = | |
| 26 FILE_PATH_LITERAL("DeviceMediaFileSystem"); | |
| 27 | |
| 28 } // namespace | |
| 29 | |
| 30 DeviceMediaFileUtil::DeviceMediaFileUtil(const FilePath& profile_path) | |
| 31 : profile_path_(profile_path) { | |
| 32 } | |
| 33 | |
| 34 PlatformFileError DeviceMediaFileUtil::CreateOrOpen( | |
| 35 FileSystemOperationContext* context, | |
| 36 const FileSystemURL& url, int file_flags, | |
| 37 PlatformFile* file_handle, bool* created) { | |
| 38 return base::PLATFORM_FILE_ERROR_SECURITY; | |
| 39 } | |
| 40 | |
| 41 PlatformFileError DeviceMediaFileUtil::Close( | |
| 42 FileSystemOperationContext* context, | |
| 43 PlatformFile file_handle) { | |
| 44 // We don't allow open thus Close won't be called. | |
| 45 return base::PLATFORM_FILE_ERROR_SECURITY; | |
| 46 } | |
| 47 | |
| 48 PlatformFileError DeviceMediaFileUtil::EnsureFileExists( | |
| 49 FileSystemOperationContext* context, | |
| 50 const FileSystemURL& url, | |
| 51 bool* created) { | |
| 52 return base::PLATFORM_FILE_ERROR_SECURITY; | |
| 53 } | |
| 54 | |
| 55 PlatformFileError DeviceMediaFileUtil::CreateDirectory( | |
| 56 FileSystemOperationContext* context, | |
| 57 const FileSystemURL& url, | |
| 58 bool exclusive, | |
| 59 bool recursive) { | |
| 60 return base::PLATFORM_FILE_ERROR_SECURITY; | |
| 61 } | |
| 62 | |
| 63 PlatformFileError DeviceMediaFileUtil::GetFileInfo( | |
| 64 FileSystemOperationContext* context, | |
| 65 const FileSystemURL& url, | |
| 66 PlatformFileInfo* file_info, | |
| 67 FilePath* platform_path) { | |
| 68 if (!context->media_device()) | |
| 69 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | |
| 70 return context->media_device()->GetFileInfo(url.path(), file_info); | |
| 71 } | |
| 72 | |
| 73 FileSystemFileUtil::AbstractFileEnumerator* | |
| 74 DeviceMediaFileUtil::CreateFileEnumerator( | |
| 75 FileSystemOperationContext* context, | |
| 76 const FileSystemURL& url, | |
| 77 bool recursive) { | |
| 78 if (!context->media_device()) | |
| 79 return new FileSystemFileUtil::EmptyFileEnumerator(); | |
| 80 return context->media_device()->CreateFileEnumerator(url.path(), recursive); | |
| 81 } | |
| 82 | |
| 83 PlatformFileError DeviceMediaFileUtil::GetLocalFilePath( | |
| 84 FileSystemOperationContext* context, | |
| 85 const FileSystemURL& file_system_url, | |
| 86 FilePath* local_file_path) { | |
| 87 return base::PLATFORM_FILE_ERROR_SECURITY; | |
| 88 } | |
| 89 | |
| 90 PlatformFileError DeviceMediaFileUtil::Touch( | |
| 91 FileSystemOperationContext* context, | |
| 92 const FileSystemURL& url, | |
| 93 const base::Time& last_access_time, | |
| 94 const base::Time& last_modified_time) { | |
| 95 if (!context->media_device()) | |
| 96 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | |
| 97 return context->media_device()->Touch(url.path(), last_access_time, | |
| 98 last_modified_time); | |
| 99 } | |
| 100 | |
| 101 PlatformFileError DeviceMediaFileUtil::Truncate( | |
| 102 FileSystemOperationContext* context, | |
| 103 const FileSystemURL& url, | |
| 104 int64 length) { | |
| 105 return base::PLATFORM_FILE_ERROR_SECURITY; | |
| 106 } | |
| 107 | |
| 108 bool DeviceMediaFileUtil::PathExists( | |
| 109 FileSystemOperationContext* context, | |
| 110 const FileSystemURL& url) { | |
| 111 if (!context->media_device()) | |
| 112 return false; | |
| 113 return context->media_device()->PathExists(url.path()); | |
| 114 } | |
| 115 | |
| 116 bool DeviceMediaFileUtil::DirectoryExists( | |
| 117 FileSystemOperationContext* context, | |
| 118 const FileSystemURL& url) { | |
| 119 if (!context->media_device()) | |
| 120 return false; | |
| 121 return context->media_device()->DirectoryExists(url.path()); | |
| 122 } | |
| 123 | |
| 124 bool DeviceMediaFileUtil::IsDirectoryEmpty( | |
| 125 FileSystemOperationContext* context, | |
| 126 const FileSystemURL& url) { | |
| 127 if (!context->media_device()) | |
| 128 return false; | |
| 129 return context->media_device()->IsDirectoryEmpty(url.path()); | |
| 130 } | |
| 131 | |
| 132 PlatformFileError DeviceMediaFileUtil::CopyOrMoveFile( | |
| 133 FileSystemOperationContext* context, | |
| 134 const FileSystemURL& src_url, | |
| 135 const FileSystemURL& dest_url, | |
| 136 bool copy) { | |
| 137 return base::PLATFORM_FILE_ERROR_SECURITY; | |
| 138 } | |
| 139 | |
| 140 PlatformFileError DeviceMediaFileUtil::CopyInForeignFile( | |
| 141 FileSystemOperationContext* context, | |
| 142 const FilePath& src_file_path, | |
| 143 const FileSystemURL& dest_url) { | |
| 144 return base::PLATFORM_FILE_ERROR_SECURITY; | |
| 145 } | |
| 146 | |
| 147 PlatformFileError DeviceMediaFileUtil::DeleteFile( | |
| 148 FileSystemOperationContext* context, | |
| 149 const FileSystemURL& url) { | |
| 150 return base::PLATFORM_FILE_ERROR_SECURITY; | |
| 151 } | |
| 152 | |
| 153 PlatformFileError DeviceMediaFileUtil::DeleteSingleDirectory( | |
| 154 FileSystemOperationContext* context, | |
| 155 const FileSystemURL& url) { | |
| 156 return base::PLATFORM_FILE_ERROR_SECURITY; | |
| 157 } | |
| 158 | |
| 159 scoped_refptr<ShareableFileReference> DeviceMediaFileUtil::CreateSnapshotFile( | |
| 160 FileSystemOperationContext* context, | |
| 161 const FileSystemURL& url, | |
| 162 base::PlatformFileError* result, | |
| 163 base::PlatformFileInfo* file_info, | |
| 164 FilePath* local_path) { | |
| 165 DCHECK(result); | |
| 166 DCHECK(file_info); | |
| 167 DCHECK(local_path); | |
| 168 | |
| 169 scoped_refptr<ShareableFileReference> file_ref; | |
| 170 if (!context->media_device()) { | |
| 171 *result = base::PLATFORM_FILE_ERROR_NOT_FOUND; | |
| 172 return file_ref; | |
| 173 } | |
| 174 | |
| 175 *result = base::PLATFORM_FILE_ERROR_FAILED; | |
| 176 | |
| 177 // Create a temp file in "profile_path_/kDeviceMediaFileUtilTempDir". | |
| 178 FilePath isolated_media_file_system_dir_path = | |
|
Lei Zhang
2012/08/02 21:32:03
I forgot to mention this problem because I hacked
kmadhusu
2012/08/02 22:05:39
kinuko@ is working on the fix.
kinuko
2012/08/13 16:41:03
I believe this has been fixed after http://crrev.c
kmadhusu
2012/08/13 16:43:06
Np. Thanks for the info.
| |
| 179 profile_path_.Append(kDeviceMediaFileUtilTempDir); | |
| 180 bool dir_exists = file_util::DirectoryExists( | |
| 181 isolated_media_file_system_dir_path); | |
| 182 if (!dir_exists) { | |
| 183 if (!file_util::CreateDirectory(isolated_media_file_system_dir_path)) | |
| 184 return file_ref; | |
| 185 } | |
| 186 | |
| 187 bool file_created = file_util::CreateTemporaryFileInDir( | |
| 188 isolated_media_file_system_dir_path, local_path); | |
| 189 if (!file_created) | |
| 190 return file_ref; | |
| 191 | |
| 192 *result = context->media_device()->CreateSnapshotFile(url.path(), *local_path, | |
| 193 file_info); | |
| 194 if (*result == base::PLATFORM_FILE_OK) { | |
| 195 file_ref = ShareableFileReference::GetOrCreate( | |
| 196 *local_path, ShareableFileReference::DELETE_ON_FINAL_RELEASE, | |
| 197 context->file_task_runner()); | |
| 198 } | |
| 199 return file_ref; | |
| 200 } | |
| 201 | |
| 202 } // namespace fileapi | |
| OLD | NEW |