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/message_loop_proxy.h" | |
|
Lei Zhang
2012/07/31 20:04:37
nit: alphabetical order in this block
kmadhusu
2012/08/01 01:43:59
Done.
| |
| 8 #include "base/file_util.h" | |
| 9 #include "base/memory/scoped_ptr.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_map_service.h" | |
| 15 #include "webkit/fileapi/media/media_device_interface_impl.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 DCHECK(context->media_device()); | |
| 69 return context->media_device()->GetFileInfo(url.path(), file_info); | |
| 70 } | |
| 71 | |
| 72 FileSystemFileUtil::AbstractFileEnumerator* | |
| 73 DeviceMediaFileUtil::CreateFileEnumerator( | |
| 74 FileSystemOperationContext* context, | |
| 75 const FileSystemURL& url, | |
| 76 bool recursive) { | |
| 77 DCHECK(context->media_device()); | |
| 78 return context->media_device()->CreateFileEnumerator(url.path(), recursive); | |
| 79 } | |
| 80 | |
| 81 PlatformFileError DeviceMediaFileUtil::GetLocalFilePath( | |
| 82 FileSystemOperationContext* context, | |
| 83 const FileSystemURL& file_system_url, | |
| 84 FilePath* local_file_path) { | |
| 85 return base::PLATFORM_FILE_ERROR_SECURITY; | |
| 86 } | |
| 87 | |
| 88 PlatformFileError DeviceMediaFileUtil::Touch( | |
| 89 FileSystemOperationContext* context, | |
| 90 const FileSystemURL& url, | |
| 91 const base::Time& last_access_time, | |
| 92 const base::Time& last_modified_time) { | |
| 93 DCHECK(context->media_device()); | |
| 94 return context->media_device()->Touch(url.path(), last_access_time, | |
| 95 last_modified_time); | |
| 96 } | |
| 97 | |
| 98 PlatformFileError DeviceMediaFileUtil::Truncate( | |
| 99 FileSystemOperationContext* context, | |
| 100 const FileSystemURL& url, | |
| 101 int64 length) { | |
| 102 return base::PLATFORM_FILE_ERROR_SECURITY; | |
| 103 } | |
| 104 | |
| 105 bool DeviceMediaFileUtil::PathExists( | |
| 106 FileSystemOperationContext* context, | |
| 107 const FileSystemURL& url) { | |
| 108 DCHECK(context->media_device()); | |
| 109 return context->media_device()->PathExists(url.path()); | |
| 110 } | |
| 111 | |
| 112 bool DeviceMediaFileUtil::DirectoryExists( | |
| 113 FileSystemOperationContext* context, | |
| 114 const FileSystemURL& url) { | |
| 115 DCHECK(context->media_device()); | |
| 116 return context->media_device()->DirectoryExists(url.path()); | |
| 117 } | |
| 118 | |
| 119 bool DeviceMediaFileUtil::IsDirectoryEmpty( | |
| 120 FileSystemOperationContext* context, | |
| 121 const FileSystemURL& url) { | |
| 122 DCHECK(context->media_device()); | |
| 123 return context->media_device()->IsDirectoryEmpty(url.path()); | |
| 124 } | |
| 125 | |
| 126 PlatformFileError DeviceMediaFileUtil::CopyOrMoveFile( | |
| 127 FileSystemOperationContext* context, | |
| 128 const FileSystemURL& src_url, | |
| 129 const FileSystemURL& dest_url, | |
| 130 bool copy) { | |
| 131 return base::PLATFORM_FILE_ERROR_SECURITY; | |
| 132 } | |
| 133 | |
| 134 PlatformFileError DeviceMediaFileUtil::CopyInForeignFile( | |
| 135 FileSystemOperationContext* context, | |
| 136 const FilePath& src_file_path, | |
| 137 const FileSystemURL& dest_url) { | |
| 138 return base::PLATFORM_FILE_ERROR_SECURITY; | |
| 139 } | |
| 140 | |
| 141 PlatformFileError DeviceMediaFileUtil::DeleteFile( | |
| 142 FileSystemOperationContext* context, | |
| 143 const FileSystemURL& url) { | |
| 144 return base::PLATFORM_FILE_ERROR_SECURITY; | |
| 145 } | |
| 146 | |
| 147 PlatformFileError DeviceMediaFileUtil::DeleteSingleDirectory( | |
| 148 FileSystemOperationContext* context, | |
| 149 const FileSystemURL& url) { | |
| 150 return base::PLATFORM_FILE_ERROR_SECURITY; | |
| 151 } | |
| 152 | |
| 153 scoped_refptr<ShareableFileReference> DeviceMediaFileUtil::CreateSnapshotFile( | |
| 154 FileSystemOperationContext* context, | |
| 155 const FileSystemURL& url, | |
| 156 base::PlatformFileError* result, | |
| 157 base::PlatformFileInfo* file_info, | |
| 158 FilePath* local_path) { | |
| 159 DCHECK(result); | |
| 160 DCHECK(file_info); | |
| 161 DCHECK(local_path); | |
| 162 | |
| 163 scoped_refptr<ShareableFileReference> file_ref; | |
| 164 *result = base::PLATFORM_FILE_ERROR_FAILED; | |
| 165 | |
| 166 // Create a temp file in "profile_path_/kDeviceMediaFileUtilTempDir". | |
| 167 FilePath isolated_media_file_system_dir_path = | |
| 168 profile_path_.Append(kDeviceMediaFileUtilTempDir); | |
| 169 bool dir_exists = file_util::DirectoryExists( | |
| 170 isolated_media_file_system_dir_path); | |
| 171 if (!dir_exists) { | |
| 172 if (!file_util::CreateDirectory(isolated_media_file_system_dir_path)) | |
| 173 return file_ref; | |
| 174 } | |
| 175 | |
| 176 bool file_created = file_util::CreateTemporaryFileInDir( | |
| 177 isolated_media_file_system_dir_path, local_path); | |
| 178 if (!file_created) | |
| 179 return file_ref; | |
| 180 | |
| 181 DCHECK(context->media_device()); | |
| 182 *result = context->media_device()->CreateSnapshotFile(url.path(), *local_path, | |
| 183 file_info); | |
| 184 if (*result == base::PLATFORM_FILE_OK) { | |
| 185 file_ref = ShareableFileReference::GetOrCreate( | |
| 186 *local_path, | |
| 187 ShareableFileReference::DELETE_ON_FINAL_RELEASE, | |
| 188 context->file_task_runner()); | |
| 189 } | |
| 190 return file_ref; | |
| 191 } | |
| 192 | |
| 193 } // namespace fileapi | |
| OLD | NEW |