| 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 "webkit/browser/fileapi/isolated_file_util.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "webkit/browser/fileapi/async_file_util.h" |
| 10 | 11 |
| 11 namespace chrome { | 12 namespace chrome { |
| 12 | 13 |
| 13 // This class handles native file system operations with media type filtering | 14 // This class handles native file system operations with media type filtering. |
| 14 // which is passed to each method via fileapi::FileSystemOperationContext as | 15 // To support virtual file systems it implements the AsyncFileUtil interface |
| 15 // MediaPathFilter. | 16 // from scratch and provides synchronous override points. |
| 16 class NativeMediaFileUtil : public fileapi::IsolatedFileUtil { | 17 class NativeMediaFileUtil : public fileapi::AsyncFileUtil { |
| 17 public: | 18 public: |
| 18 NativeMediaFileUtil(); | 19 NativeMediaFileUtil(); |
| 20 virtual ~NativeMediaFileUtil(); |
| 19 | 21 |
| 20 virtual base::PlatformFileError CreateOrOpen( | 22 // AsyncFileUtil overrides. |
| 23 virtual bool CreateOrOpen( |
| 21 fileapi::FileSystemOperationContext* context, | 24 fileapi::FileSystemOperationContext* context, |
| 22 const fileapi::FileSystemURL& url, | 25 const fileapi::FileSystemURL& url, |
| 23 int file_flags, | 26 int file_flags, |
| 24 base::PlatformFile* file_handle, | 27 const CreateOrOpenCallback& callback) OVERRIDE; |
| 25 bool* created) OVERRIDE; | 28 virtual bool EnsureFileExists( |
| 26 virtual base::PlatformFileError EnsureFileExists( | |
| 27 fileapi::FileSystemOperationContext* context, | 29 fileapi::FileSystemOperationContext* context, |
| 28 const fileapi::FileSystemURL& url, bool* created) OVERRIDE; | 30 const fileapi::FileSystemURL& url, |
| 29 virtual scoped_ptr<AbstractFileEnumerator> CreateFileEnumerator( | 31 const EnsureFileExistsCallback& callback) OVERRIDE; |
| 32 virtual bool CreateDirectory( |
| 30 fileapi::FileSystemOperationContext* context, | 33 fileapi::FileSystemOperationContext* context, |
| 31 const fileapi::FileSystemURL& root_url) OVERRIDE; | 34 const fileapi::FileSystemURL& url, |
| 32 virtual base::PlatformFileError Touch( | 35 bool exclusive, |
| 36 bool recursive, |
| 37 const StatusCallback& callback) OVERRIDE; |
| 38 virtual bool GetFileInfo( |
| 39 fileapi::FileSystemOperationContext* context, |
| 40 const fileapi::FileSystemURL& url, |
| 41 const GetFileInfoCallback& callback) OVERRIDE; |
| 42 virtual bool ReadDirectory( |
| 43 fileapi::FileSystemOperationContext* context, |
| 44 const fileapi::FileSystemURL& url, |
| 45 const ReadDirectoryCallback& callback) OVERRIDE; |
| 46 virtual bool Touch( |
| 33 fileapi::FileSystemOperationContext* context, | 47 fileapi::FileSystemOperationContext* context, |
| 34 const fileapi::FileSystemURL& url, | 48 const fileapi::FileSystemURL& url, |
| 35 const base::Time& last_access_time, | 49 const base::Time& last_access_time, |
| 36 const base::Time& last_modified_time) OVERRIDE; | 50 const base::Time& last_modified_time, |
| 37 virtual base::PlatformFileError Truncate( | 51 const StatusCallback& callback) OVERRIDE; |
| 52 virtual bool Truncate( |
| 38 fileapi::FileSystemOperationContext* context, | 53 fileapi::FileSystemOperationContext* context, |
| 39 const fileapi::FileSystemURL& url, | 54 const fileapi::FileSystemURL& url, |
| 40 int64 length) OVERRIDE; | 55 int64 length, |
| 41 virtual base::PlatformFileError CopyOrMoveFile( | 56 const StatusCallback& callback) OVERRIDE; |
| 57 virtual bool CopyFileLocal( |
| 42 fileapi::FileSystemOperationContext* context, | 58 fileapi::FileSystemOperationContext* context, |
| 43 const fileapi::FileSystemURL& src_url, | 59 const fileapi::FileSystemURL& src_url, |
| 44 const fileapi::FileSystemURL& dest_url, | 60 const fileapi::FileSystemURL& dest_url, |
| 45 bool copy) OVERRIDE; | 61 const StatusCallback& callback) OVERRIDE; |
| 46 virtual base::PlatformFileError CopyInForeignFile( | 62 virtual bool MoveFileLocal( |
| 47 fileapi::FileSystemOperationContext* context, | |
| 48 const base::FilePath& src_file_path, | |
| 49 const fileapi::FileSystemURL& dest_url) OVERRIDE; | |
| 50 virtual base::PlatformFileError DeleteFile( | |
| 51 fileapi::FileSystemOperationContext* context, | 63 fileapi::FileSystemOperationContext* context, |
| 52 const fileapi::FileSystemURL& url) OVERRIDE; | 64 const fileapi::FileSystemURL& src_url, |
| 53 virtual base::PlatformFileError GetFileInfo( | 65 const fileapi::FileSystemURL& dest_url, |
| 66 const StatusCallback& callback) OVERRIDE; |
| 67 virtual bool CopyInForeignFile( |
| 68 fileapi::FileSystemOperationContext* context, |
| 69 const base::FilePath& src_file_path, |
| 70 const fileapi::FileSystemURL& dest_url, |
| 71 const StatusCallback& callback) OVERRIDE; |
| 72 virtual bool DeleteFile( |
| 54 fileapi::FileSystemOperationContext* context, | 73 fileapi::FileSystemOperationContext* context, |
| 55 const fileapi::FileSystemURL& url, | 74 const fileapi::FileSystemURL& url, |
| 56 base::PlatformFileInfo* file_info, | 75 const StatusCallback& callback) OVERRIDE; |
| 57 base::FilePath* platform_path) OVERRIDE; | 76 virtual bool DeleteDirectory( |
| 58 virtual webkit_blob::ScopedFile CreateSnapshotFile( | |
| 59 fileapi::FileSystemOperationContext* context, | 77 fileapi::FileSystemOperationContext* context, |
| 60 const fileapi::FileSystemURL& url, | 78 const fileapi::FileSystemURL& url, |
| 61 base::PlatformFileError* error, | 79 const StatusCallback& callback) OVERRIDE; |
| 62 base::PlatformFileInfo* file_info, | 80 virtual bool CreateSnapshotFile( |
| 63 base::FilePath* platform_path) OVERRIDE; | 81 fileapi::FileSystemOperationContext* context, |
| 82 const fileapi::FileSystemURL& url, |
| 83 const CreateSnapshotFileCallback& callback) OVERRIDE; |
| 64 | 84 |
| 65 // Uses the MIME sniffer code, which actually looks into the file, | 85 // Uses the MIME sniffer code, which actually looks into the file, |
| 66 // to determine if it is really a media file (to avoid exposing | 86 // to determine if it is really a media file (to avoid exposing |
| 67 // non-media files with a media file extension.) | 87 // non-media files with a media file extension.) |
| 68 static base::PlatformFileError IsMediaFile(const base::FilePath& path); | 88 static base::PlatformFileError IsMediaFile(const base::FilePath& path); |
| 69 | 89 |
| 90 protected: |
| 91 // The following methods should only be called on the task runner thread. |
| 92 |
| 93 // Necessary for copy/move to succeed. |
| 94 virtual base::PlatformFileError CreateDirectorySync( |
| 95 fileapi::FileSystemOperationContext* context, |
| 96 const fileapi::FileSystemURL& url, |
| 97 bool exclusive, |
| 98 bool recursive); |
| 99 virtual base::PlatformFileError CopyOrMoveFileSync( |
| 100 fileapi::FileSystemOperationContext* context, |
| 101 const fileapi::FileSystemURL& src_url, |
| 102 const fileapi::FileSystemURL& dest_url, |
| 103 bool copy); |
| 104 virtual base::PlatformFileError CopyInForeignFileSync( |
| 105 fileapi::FileSystemOperationContext* context, |
| 106 const base::FilePath& src_file_path, |
| 107 const fileapi::FileSystemURL& dest_url); |
| 108 virtual base::PlatformFileError GetFileInfoSync( |
| 109 fileapi::FileSystemOperationContext* context, |
| 110 const fileapi::FileSystemURL& url, |
| 111 base::PlatformFileInfo* file_info, |
| 112 base::FilePath* platform_path); |
| 113 // Called by GetFileInfoSync. Meant to be overridden by subclasses that |
| 114 // have special mappings from URLs to platform paths (virtual filesystems). |
| 115 virtual base::PlatformFileError GetLocalFilePath( |
| 116 fileapi::FileSystemOperationContext* context, |
| 117 const fileapi::FileSystemURL& file_system_url, |
| 118 base::FilePath* local_file_path); |
| 119 virtual base::PlatformFileError ReadDirectorySync( |
| 120 fileapi::FileSystemOperationContext* context, |
| 121 const fileapi::FileSystemURL& url, |
| 122 EntryList* file_list); |
| 123 // Necessary for move to succeed. |
| 124 virtual base::PlatformFileError DeleteDirectorySync( |
| 125 fileapi::FileSystemOperationContext* context, |
| 126 const fileapi::FileSystemURL& url); |
| 127 virtual base::PlatformFileError CreateSnapshotFileSync( |
| 128 fileapi::FileSystemOperationContext* context, |
| 129 const fileapi::FileSystemURL& url, |
| 130 base::PlatformFileInfo* file_info, |
| 131 base::FilePath* platform_path, |
| 132 scoped_refptr<webkit_blob::ShareableFileReference>* file_ref); |
| 133 |
| 70 private: | 134 private: |
| 71 // Like GetLocalFilePath(), but always take media_path_filter() into | 135 // Like GetLocalFilePath(), but always take media_path_filter() into |
| 72 // consideration. If the media_path_filter() check fails, return | 136 // consideration. If the media_path_filter() check fails, return |
| 73 // PLATFORM_FILE_ERROR_SECURITY. |local_file_path| does not have to exist. | 137 // PLATFORM_FILE_ERROR_SECURITY. |local_file_path| does not have to exist. |
| 74 base::PlatformFileError GetFilteredLocalFilePath( | 138 base::PlatformFileError GetFilteredLocalFilePath( |
| 75 fileapi::FileSystemOperationContext* context, | 139 fileapi::FileSystemOperationContext* context, |
| 76 const fileapi::FileSystemURL& file_system_url, | 140 const fileapi::FileSystemURL& file_system_url, |
| 77 base::FilePath* local_file_path); | 141 base::FilePath* local_file_path); |
| 78 | 142 |
| 79 // Like GetLocalFilePath(), but if the file does not exist, then return | 143 // Like GetLocalFilePath(), but if the file does not exist, then return |
| 80 // |failure_error|. | 144 // |failure_error|. |
| 81 // If |local_file_path| is a file, then take media_path_filter() into | 145 // If |local_file_path| is a file, then take media_path_filter() into |
| 82 // consideration. | 146 // consideration. |
| 83 // If the media_path_filter() check fails, return |failure_error|. | 147 // If the media_path_filter() check fails, return |failure_error|. |
| 84 // If |local_file_path| is a directory, return PLATFORM_FILE_OK. | 148 // If |local_file_path| is a directory, return PLATFORM_FILE_OK. |
| 85 base::PlatformFileError GetFilteredLocalFilePathForExistingFileOrDirectory( | 149 base::PlatformFileError GetFilteredLocalFilePathForExistingFileOrDirectory( |
| 86 fileapi::FileSystemOperationContext* context, | 150 fileapi::FileSystemOperationContext* context, |
| 87 const fileapi::FileSystemURL& file_system_url, | 151 const fileapi::FileSystemURL& file_system_url, |
| 88 base::PlatformFileError failure_error, | 152 base::PlatformFileError failure_error, |
| 89 base::FilePath* local_file_path); | 153 base::FilePath* local_file_path); |
| 90 | 154 |
| 155 virtual void CreateDirectoryOnTaskRunnerThread( |
| 156 fileapi::FileSystemOperationContext* context, |
| 157 const fileapi::FileSystemURL& url, |
| 158 bool exclusive, |
| 159 bool recursive, |
| 160 const StatusCallback& callback); |
| 161 virtual void GetFileInfoOnTaskRunnerThread( |
| 162 fileapi::FileSystemOperationContext* context, |
| 163 const fileapi::FileSystemURL& url, |
| 164 const GetFileInfoCallback& callback); |
| 165 virtual void ReadDirectoryOnTaskRunnerThread( |
| 166 fileapi::FileSystemOperationContext* context, |
| 167 const fileapi::FileSystemURL& url, |
| 168 const ReadDirectoryCallback& callback); |
| 169 virtual void CopyOrMoveFileLocalOnTaskRunnerThread( |
| 170 fileapi::FileSystemOperationContext* context, |
| 171 const fileapi::FileSystemURL& src_url, |
| 172 const fileapi::FileSystemURL& dest_url, |
| 173 bool copy, |
| 174 const StatusCallback& callback); |
| 175 virtual void CopyInForeignFileOnTaskRunnerThread( |
| 176 fileapi::FileSystemOperationContext* context, |
| 177 const base::FilePath& src_file_path, |
| 178 const fileapi::FileSystemURL& dest_url, |
| 179 const StatusCallback& callback); |
| 180 virtual void DeleteDirectoryOnTaskRunnerThread( |
| 181 fileapi::FileSystemOperationContext* context, |
| 182 const fileapi::FileSystemURL& url, |
| 183 const StatusCallback& callback); |
| 184 virtual void CreateSnapshotFileOnTaskRunnerThread( |
| 185 fileapi::FileSystemOperationContext* context, |
| 186 const fileapi::FileSystemURL& url, |
| 187 const CreateSnapshotFileCallback& callback); |
| 188 |
| 189 base::WeakPtrFactory<NativeMediaFileUtil> weak_factory_; |
| 190 |
| 91 DISALLOW_COPY_AND_ASSIGN(NativeMediaFileUtil); | 191 DISALLOW_COPY_AND_ASSIGN(NativeMediaFileUtil); |
| 92 }; | 192 }; |
| 93 | 193 |
| 94 } // namespace chrome | 194 } // namespace chrome |
| 95 | 195 |
| 96 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_NATIVE_MEDIA_FILE_UTIL_H_ | 196 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_NATIVE_MEDIA_FILE_UTIL_H_ |
| OLD | NEW |