| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_NATIVE_MEDIA_FILE_UTIL_H_ | 5 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_NATIVE_MEDIA_FILE_UTIL_H_ |
| 6 #define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_NATIVE_MEDIA_FILE_UTIL_H_ | 6 #define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_NATIVE_MEDIA_FILE_UTIL_H_ |
| 7 | 7 |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "webkit/browser/fileapi/async_file_util.h" | 10 #include "webkit/browser/fileapi/async_file_util.h" |
| 11 | 11 |
| 12 class MediaPathFilter; | 12 class MediaPathFilter; |
| 13 | 13 |
| 14 // This class handles native file system operations with media type filtering. | 14 // This class handles native file system operations with media type filtering. |
| 15 // To support virtual file systems it implements the AsyncFileUtil interface | 15 // To support virtual file systems it implements the AsyncFileUtil interface |
| 16 // from scratch and provides synchronous override points. | 16 // from scratch and provides synchronous override points. |
| 17 class NativeMediaFileUtil : public fileapi::AsyncFileUtil { | 17 class NativeMediaFileUtil : public fileapi::AsyncFileUtil { |
| 18 public: | 18 public: |
| 19 explicit NativeMediaFileUtil(MediaPathFilter* media_path_filter); | 19 explicit NativeMediaFileUtil(MediaPathFilter* media_path_filter); |
| 20 virtual ~NativeMediaFileUtil(); | 20 virtual ~NativeMediaFileUtil(); |
| 21 | 21 |
| 22 // Uses the MIME sniffer code, which actually looks into the file, | 22 // Uses the MIME sniffer code, which actually looks into the file, |
| 23 // to determine if it is really a media file (to avoid exposing | 23 // to determine if it is really a media file (to avoid exposing |
| 24 // non-media files with a media file extension.) | 24 // non-media files with a media file extension.) |
| 25 static base::PlatformFileError IsMediaFile(const base::FilePath& path); | 25 static base::File::Error IsMediaFile(const base::FilePath& path); |
| 26 | 26 |
| 27 // AsyncFileUtil overrides. | 27 // AsyncFileUtil overrides. |
| 28 virtual void CreateOrOpen( | 28 virtual void CreateOrOpen( |
| 29 scoped_ptr<fileapi::FileSystemOperationContext> context, | 29 scoped_ptr<fileapi::FileSystemOperationContext> context, |
| 30 const fileapi::FileSystemURL& url, | 30 const fileapi::FileSystemURL& url, |
| 31 int file_flags, | 31 int file_flags, |
| 32 const CreateOrOpenCallback& callback) OVERRIDE; | 32 const CreateOrOpenCallback& callback) OVERRIDE; |
| 33 virtual void EnsureFileExists( | 33 virtual void EnsureFileExists( |
| 34 scoped_ptr<fileapi::FileSystemOperationContext> context, | 34 scoped_ptr<fileapi::FileSystemOperationContext> context, |
| 35 const fileapi::FileSystemURL& url, | 35 const fileapi::FileSystemURL& url, |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 const fileapi::FileSystemURL& url, | 130 const fileapi::FileSystemURL& url, |
| 131 const StatusCallback& callback); | 131 const StatusCallback& callback); |
| 132 virtual void CreateSnapshotFileOnTaskRunnerThread( | 132 virtual void CreateSnapshotFileOnTaskRunnerThread( |
| 133 scoped_ptr<fileapi::FileSystemOperationContext> context, | 133 scoped_ptr<fileapi::FileSystemOperationContext> context, |
| 134 const fileapi::FileSystemURL& url, | 134 const fileapi::FileSystemURL& url, |
| 135 const CreateSnapshotFileCallback& callback); | 135 const CreateSnapshotFileCallback& callback); |
| 136 | 136 |
| 137 // The following methods should only be called on the task runner thread. | 137 // The following methods should only be called on the task runner thread. |
| 138 | 138 |
| 139 // Necessary for copy/move to succeed. | 139 // Necessary for copy/move to succeed. |
| 140 virtual base::PlatformFileError CreateDirectorySync( | 140 virtual base::File::Error CreateDirectorySync( |
| 141 fileapi::FileSystemOperationContext* context, | 141 fileapi::FileSystemOperationContext* context, |
| 142 const fileapi::FileSystemURL& url, | 142 const fileapi::FileSystemURL& url, |
| 143 bool exclusive, | 143 bool exclusive, |
| 144 bool recursive); | 144 bool recursive); |
| 145 virtual base::PlatformFileError CopyOrMoveFileSync( | 145 virtual base::File::Error CopyOrMoveFileSync( |
| 146 fileapi::FileSystemOperationContext* context, | 146 fileapi::FileSystemOperationContext* context, |
| 147 const fileapi::FileSystemURL& src_url, | 147 const fileapi::FileSystemURL& src_url, |
| 148 const fileapi::FileSystemURL& dest_url, | 148 const fileapi::FileSystemURL& dest_url, |
| 149 CopyOrMoveOption option, | 149 CopyOrMoveOption option, |
| 150 bool copy); | 150 bool copy); |
| 151 virtual base::PlatformFileError CopyInForeignFileSync( | 151 virtual base::File::Error CopyInForeignFileSync( |
| 152 fileapi::FileSystemOperationContext* context, | 152 fileapi::FileSystemOperationContext* context, |
| 153 const base::FilePath& src_file_path, | 153 const base::FilePath& src_file_path, |
| 154 const fileapi::FileSystemURL& dest_url); | 154 const fileapi::FileSystemURL& dest_url); |
| 155 virtual base::PlatformFileError GetFileInfoSync( | 155 virtual base::File::Error GetFileInfoSync( |
| 156 fileapi::FileSystemOperationContext* context, | 156 fileapi::FileSystemOperationContext* context, |
| 157 const fileapi::FileSystemURL& url, | 157 const fileapi::FileSystemURL& url, |
| 158 base::PlatformFileInfo* file_info, | 158 base::File::Info* file_info, |
| 159 base::FilePath* platform_path); | 159 base::FilePath* platform_path); |
| 160 // Called by GetFileInfoSync. Meant to be overridden by subclasses that | 160 // Called by GetFileInfoSync. Meant to be overridden by subclasses that |
| 161 // have special mappings from URLs to platform paths (virtual filesystems). | 161 // have special mappings from URLs to platform paths (virtual filesystems). |
| 162 virtual base::PlatformFileError GetLocalFilePath( | 162 virtual base::File::Error GetLocalFilePath( |
| 163 fileapi::FileSystemOperationContext* context, | 163 fileapi::FileSystemOperationContext* context, |
| 164 const fileapi::FileSystemURL& file_system_url, | 164 const fileapi::FileSystemURL& file_system_url, |
| 165 base::FilePath* local_file_path); | 165 base::FilePath* local_file_path); |
| 166 virtual base::PlatformFileError ReadDirectorySync( | 166 virtual base::File::Error ReadDirectorySync( |
| 167 fileapi::FileSystemOperationContext* context, | 167 fileapi::FileSystemOperationContext* context, |
| 168 const fileapi::FileSystemURL& url, | 168 const fileapi::FileSystemURL& url, |
| 169 EntryList* file_list); | 169 EntryList* file_list); |
| 170 virtual base::PlatformFileError DeleteFileSync( | 170 virtual base::File::Error DeleteFileSync( |
| 171 fileapi::FileSystemOperationContext* context, | 171 fileapi::FileSystemOperationContext* context, |
| 172 const fileapi::FileSystemURL& url); | 172 const fileapi::FileSystemURL& url); |
| 173 // Necessary for move to succeed. | 173 // Necessary for move to succeed. |
| 174 virtual base::PlatformFileError DeleteDirectorySync( | 174 virtual base::File::Error DeleteDirectorySync( |
| 175 fileapi::FileSystemOperationContext* context, | 175 fileapi::FileSystemOperationContext* context, |
| 176 const fileapi::FileSystemURL& url); | 176 const fileapi::FileSystemURL& url); |
| 177 virtual base::PlatformFileError CreateSnapshotFileSync( | 177 virtual base::File::Error CreateSnapshotFileSync( |
| 178 fileapi::FileSystemOperationContext* context, | 178 fileapi::FileSystemOperationContext* context, |
| 179 const fileapi::FileSystemURL& url, | 179 const fileapi::FileSystemURL& url, |
| 180 base::PlatformFileInfo* file_info, | 180 base::File::Info* file_info, |
| 181 base::FilePath* platform_path, | 181 base::FilePath* platform_path, |
| 182 scoped_refptr<webkit_blob::ShareableFileReference>* file_ref); | 182 scoped_refptr<webkit_blob::ShareableFileReference>* file_ref); |
| 183 | 183 |
| 184 protected: | 184 protected: |
| 185 MediaPathFilter* media_path_filter() { | 185 MediaPathFilter* media_path_filter() { |
| 186 return media_path_filter_; | 186 return media_path_filter_; |
| 187 } | 187 } |
| 188 | 188 |
| 189 private: | 189 private: |
| 190 // Like GetLocalFilePath(), but always take media_path_filter() into | 190 // Like GetLocalFilePath(), but always take media_path_filter() into |
| 191 // consideration. If the media_path_filter() check fails, return | 191 // consideration. If the media_path_filter() check fails, return |
| 192 // PLATFORM_FILE_ERROR_SECURITY. |local_file_path| does not have to exist. | 192 // PLATFORM_FILE_ERROR_SECURITY. |local_file_path| does not have to exist. |
| 193 base::PlatformFileError GetFilteredLocalFilePath( | 193 base::File::Error GetFilteredLocalFilePath( |
| 194 fileapi::FileSystemOperationContext* context, | 194 fileapi::FileSystemOperationContext* context, |
| 195 const fileapi::FileSystemURL& file_system_url, | 195 const fileapi::FileSystemURL& file_system_url, |
| 196 base::FilePath* local_file_path); | 196 base::FilePath* local_file_path); |
| 197 | 197 |
| 198 // Like GetLocalFilePath(), but if the file does not exist, then return | 198 // Like GetLocalFilePath(), but if the file does not exist, then return |
| 199 // |failure_error|. | 199 // |failure_error|. |
| 200 // If |local_file_path| is a file, then take media_path_filter() into | 200 // If |local_file_path| is a file, then take media_path_filter() into |
| 201 // consideration. | 201 // consideration. |
| 202 // If the media_path_filter() check fails, return |failure_error|. | 202 // If the media_path_filter() check fails, return |failure_error|. |
| 203 // If |local_file_path| is a directory, return PLATFORM_FILE_OK. | 203 // If |local_file_path| is a directory, return PLATFORM_FILE_OK. |
| 204 base::PlatformFileError GetFilteredLocalFilePathForExistingFileOrDirectory( | 204 base::File::Error GetFilteredLocalFilePathForExistingFileOrDirectory( |
| 205 fileapi::FileSystemOperationContext* context, | 205 fileapi::FileSystemOperationContext* context, |
| 206 const fileapi::FileSystemURL& file_system_url, | 206 const fileapi::FileSystemURL& file_system_url, |
| 207 base::PlatformFileError failure_error, | 207 base::File::Error failure_error, |
| 208 base::FilePath* local_file_path); | 208 base::FilePath* local_file_path); |
| 209 | 209 |
| 210 | 210 |
| 211 // Not owned, owned by the backend which owns this. | 211 // Not owned, owned by the backend which owns this. |
| 212 MediaPathFilter* media_path_filter_; | 212 MediaPathFilter* media_path_filter_; |
| 213 | 213 |
| 214 base::WeakPtrFactory<NativeMediaFileUtil> weak_factory_; | 214 base::WeakPtrFactory<NativeMediaFileUtil> weak_factory_; |
| 215 | 215 |
| 216 DISALLOW_COPY_AND_ASSIGN(NativeMediaFileUtil); | 216 DISALLOW_COPY_AND_ASSIGN(NativeMediaFileUtil); |
| 217 }; | 217 }; |
| 218 | 218 |
| 219 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_NATIVE_MEDIA_FILE_UTIL_H_ | 219 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_NATIVE_MEDIA_FILE_UTIL_H_ |
| OLD | NEW |