| 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 WEBKIT_BROWSER_FILEAPI_OBFUSCATED_FILE_UTIL_H_ | 5 #ifndef WEBKIT_BROWSER_FILEAPI_OBFUSCATED_FILE_UTIL_H_ |
| 6 #define WEBKIT_BROWSER_FILEAPI_OBFUSCATED_FILE_UTIL_H_ | 6 #define WEBKIT_BROWSER_FILEAPI_OBFUSCATED_FILE_UTIL_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/callback_forward.h" | 13 #include "base/callback_forward.h" |
| 14 #include "base/files/file.h" |
| 14 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 15 #include "base/files/file_util_proxy.h" | 16 #include "base/files/file_util_proxy.h" |
| 16 #include "base/gtest_prod_util.h" | 17 #include "base/gtest_prod_util.h" |
| 17 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
| 18 #include "base/platform_file.h" | 19 #include "base/platform_file.h" |
| 19 #include "webkit/browser/fileapi/file_system_file_util.h" | 20 #include "webkit/browser/fileapi/file_system_file_util.h" |
| 20 #include "webkit/browser/fileapi/file_system_url.h" | 21 #include "webkit/browser/fileapi/file_system_url.h" |
| 21 #include "webkit/browser/fileapi/sandbox_directory_database.h" | 22 #include "webkit/browser/fileapi/sandbox_directory_database.h" |
| 22 #include "webkit/browser/fileapi/sandbox_file_system_backend_delegate.h" | 23 #include "webkit/browser/fileapi/sandbox_file_system_backend_delegate.h" |
| 23 #include "webkit/browser/webkit_storage_browser_export.h" | 24 #include "webkit/browser/webkit_storage_browser_export.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 ObfuscatedFileUtil( | 104 ObfuscatedFileUtil( |
| 104 quota::SpecialStoragePolicy* special_storage_policy, | 105 quota::SpecialStoragePolicy* special_storage_policy, |
| 105 const base::FilePath& file_system_directory, | 106 const base::FilePath& file_system_directory, |
| 106 base::SequencedTaskRunner* file_task_runner, | 107 base::SequencedTaskRunner* file_task_runner, |
| 107 const GetTypeStringForURLCallback& get_type_string_for_url, | 108 const GetTypeStringForURLCallback& get_type_string_for_url, |
| 108 const std::set<std::string>& known_type_strings, | 109 const std::set<std::string>& known_type_strings, |
| 109 SandboxFileSystemBackendDelegate* sandbox_delegate); | 110 SandboxFileSystemBackendDelegate* sandbox_delegate); |
| 110 virtual ~ObfuscatedFileUtil(); | 111 virtual ~ObfuscatedFileUtil(); |
| 111 | 112 |
| 112 // FileSystemFileUtil overrides. | 113 // FileSystemFileUtil overrides. |
| 113 virtual base::PlatformFileError CreateOrOpen( | 114 virtual base::File::Error CreateOrOpen( |
| 114 FileSystemOperationContext* context, | 115 FileSystemOperationContext* context, |
| 115 const FileSystemURL& url, | 116 const FileSystemURL& url, |
| 116 int file_flags, | 117 int file_flags, |
| 117 base::PlatformFile* file_handle, | 118 base::PlatformFile* file_handle, |
| 118 bool* created) OVERRIDE; | 119 bool* created) OVERRIDE; |
| 119 virtual base::PlatformFileError Close( | 120 virtual base::File::Error Close( |
| 120 FileSystemOperationContext* context, | 121 FileSystemOperationContext* context, |
| 121 base::PlatformFile file) OVERRIDE; | 122 base::PlatformFile file) OVERRIDE; |
| 122 virtual base::PlatformFileError EnsureFileExists( | 123 virtual base::File::Error EnsureFileExists( |
| 123 FileSystemOperationContext* context, | 124 FileSystemOperationContext* context, |
| 124 const FileSystemURL& url, bool* created) OVERRIDE; | 125 const FileSystemURL& url, bool* created) OVERRIDE; |
| 125 virtual base::PlatformFileError CreateDirectory( | 126 virtual base::File::Error CreateDirectory( |
| 126 FileSystemOperationContext* context, | 127 FileSystemOperationContext* context, |
| 127 const FileSystemURL& url, | 128 const FileSystemURL& url, |
| 128 bool exclusive, | 129 bool exclusive, |
| 129 bool recursive) OVERRIDE; | 130 bool recursive) OVERRIDE; |
| 130 virtual base::PlatformFileError GetFileInfo( | 131 virtual base::File::Error GetFileInfo( |
| 131 FileSystemOperationContext* context, | 132 FileSystemOperationContext* context, |
| 132 const FileSystemURL& url, | 133 const FileSystemURL& url, |
| 133 base::PlatformFileInfo* file_info, | 134 base::File::Info* file_info, |
| 134 base::FilePath* platform_file) OVERRIDE; | 135 base::FilePath* platform_file) OVERRIDE; |
| 135 virtual scoped_ptr<AbstractFileEnumerator> CreateFileEnumerator( | 136 virtual scoped_ptr<AbstractFileEnumerator> CreateFileEnumerator( |
| 136 FileSystemOperationContext* context, | 137 FileSystemOperationContext* context, |
| 137 const FileSystemURL& root_url) OVERRIDE; | 138 const FileSystemURL& root_url) OVERRIDE; |
| 138 virtual base::PlatformFileError GetLocalFilePath( | 139 virtual base::File::Error GetLocalFilePath( |
| 139 FileSystemOperationContext* context, | 140 FileSystemOperationContext* context, |
| 140 const FileSystemURL& file_system_url, | 141 const FileSystemURL& file_system_url, |
| 141 base::FilePath* local_path) OVERRIDE; | 142 base::FilePath* local_path) OVERRIDE; |
| 142 virtual base::PlatformFileError Touch( | 143 virtual base::File::Error Touch( |
| 143 FileSystemOperationContext* context, | 144 FileSystemOperationContext* context, |
| 144 const FileSystemURL& url, | 145 const FileSystemURL& url, |
| 145 const base::Time& last_access_time, | 146 const base::Time& last_access_time, |
| 146 const base::Time& last_modified_time) OVERRIDE; | 147 const base::Time& last_modified_time) OVERRIDE; |
| 147 virtual base::PlatformFileError Truncate( | 148 virtual base::File::Error Truncate( |
| 148 FileSystemOperationContext* context, | 149 FileSystemOperationContext* context, |
| 149 const FileSystemURL& url, | 150 const FileSystemURL& url, |
| 150 int64 length) OVERRIDE; | 151 int64 length) OVERRIDE; |
| 151 virtual base::PlatformFileError CopyOrMoveFile( | 152 virtual base::File::Error CopyOrMoveFile( |
| 152 FileSystemOperationContext* context, | 153 FileSystemOperationContext* context, |
| 153 const FileSystemURL& src_url, | 154 const FileSystemURL& src_url, |
| 154 const FileSystemURL& dest_url, | 155 const FileSystemURL& dest_url, |
| 155 CopyOrMoveOption option, | 156 CopyOrMoveOption option, |
| 156 bool copy) OVERRIDE; | 157 bool copy) OVERRIDE; |
| 157 virtual base::PlatformFileError CopyInForeignFile( | 158 virtual base::File::Error CopyInForeignFile( |
| 158 FileSystemOperationContext* context, | 159 FileSystemOperationContext* context, |
| 159 const base::FilePath& src_file_path, | 160 const base::FilePath& src_file_path, |
| 160 const FileSystemURL& dest_url) OVERRIDE; | 161 const FileSystemURL& dest_url) OVERRIDE; |
| 161 virtual base::PlatformFileError DeleteFile( | 162 virtual base::File::Error DeleteFile( |
| 162 FileSystemOperationContext* context, | 163 FileSystemOperationContext* context, |
| 163 const FileSystemURL& url) OVERRIDE; | 164 const FileSystemURL& url) OVERRIDE; |
| 164 virtual base::PlatformFileError DeleteDirectory( | 165 virtual base::File::Error DeleteDirectory( |
| 165 FileSystemOperationContext* context, | 166 FileSystemOperationContext* context, |
| 166 const FileSystemURL& url) OVERRIDE; | 167 const FileSystemURL& url) OVERRIDE; |
| 167 virtual webkit_blob::ScopedFile CreateSnapshotFile( | 168 virtual webkit_blob::ScopedFile CreateSnapshotFile( |
| 168 FileSystemOperationContext* context, | 169 FileSystemOperationContext* context, |
| 169 const FileSystemURL& url, | 170 const FileSystemURL& url, |
| 170 base::PlatformFileError* error, | 171 base::File::Error* error, |
| 171 base::PlatformFileInfo* file_info, | 172 base::File::Info* file_info, |
| 172 base::FilePath* platform_path) OVERRIDE; | 173 base::FilePath* platform_path) OVERRIDE; |
| 173 | 174 |
| 174 // Same as the other CreateFileEnumerator, but with recursive support. | 175 // Same as the other CreateFileEnumerator, but with recursive support. |
| 175 scoped_ptr<AbstractFileEnumerator> CreateFileEnumerator( | 176 scoped_ptr<AbstractFileEnumerator> CreateFileEnumerator( |
| 176 FileSystemOperationContext* context, | 177 FileSystemOperationContext* context, |
| 177 const FileSystemURL& root_url, | 178 const FileSystemURL& root_url, |
| 178 bool recursive); | 179 bool recursive); |
| 179 | 180 |
| 180 // Returns true if the directory |url| is empty. | 181 // Returns true if the directory |url| is empty. |
| 181 bool IsDirectoryEmpty( | 182 bool IsDirectoryEmpty( |
| 182 FileSystemOperationContext* context, | 183 FileSystemOperationContext* context, |
| 183 const FileSystemURL& url); | 184 const FileSystemURL& url); |
| 184 | 185 |
| 185 // Gets the topmost directory specific to this origin and type. This will | 186 // Gets the topmost directory specific to this origin and type. This will |
| 186 // contain both the directory database's files and all the backing file | 187 // contain both the directory database's files and all the backing file |
| 187 // subdirectories. | 188 // subdirectories. |
| 188 // Returns the topmost origin directory if |type_string| is empty. | 189 // Returns the topmost origin directory if |type_string| is empty. |
| 189 // Returns an empty path if the directory is undefined. | 190 // Returns an empty path if the directory is undefined. |
| 190 // If the directory is defined, it will be returned, even if | 191 // If the directory is defined, it will be returned, even if |
| 191 // there is a file system error (e.g. the directory doesn't exist on disk and | 192 // there is a file system error (e.g. the directory doesn't exist on disk and |
| 192 // |create| is false). Callers should always check |error_code| to make sure | 193 // |create| is false). Callers should always check |error_code| to make sure |
| 193 // the returned path is usable. | 194 // the returned path is usable. |
| 194 base::FilePath GetDirectoryForOriginAndType( | 195 base::FilePath GetDirectoryForOriginAndType( |
| 195 const GURL& origin, | 196 const GURL& origin, |
| 196 const std::string& type_string, | 197 const std::string& type_string, |
| 197 bool create, | 198 bool create, |
| 198 base::PlatformFileError* error_code); | 199 base::File::Error* error_code); |
| 199 | 200 |
| 200 // Deletes the topmost directory specific to this origin and type. This will | 201 // Deletes the topmost directory specific to this origin and type. This will |
| 201 // delete its directory database. | 202 // delete its directory database. |
| 202 // Deletes the topmost origin directory if |type_string| is empty. | 203 // Deletes the topmost origin directory if |type_string| is empty. |
| 203 bool DeleteDirectoryForOriginAndType( | 204 bool DeleteDirectoryForOriginAndType( |
| 204 const GURL& origin, | 205 const GURL& origin, |
| 205 const std::string& type_string); | 206 const std::string& type_string); |
| 206 | 207 |
| 207 // This method and all methods of its returned class must be called only on | 208 // This method and all methods of its returned class must be called only on |
| 208 // the FILE thread. The caller is responsible for deleting the returned | 209 // the FILE thread. The caller is responsible for deleting the returned |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 // (temporary, persistent) file systems. Used only for testing. | 241 // (temporary, persistent) file systems. Used only for testing. |
| 241 // Note: this is implemented in sandbox_file_system_backend_delegate.cc. | 242 // Note: this is implemented in sandbox_file_system_backend_delegate.cc. |
| 242 static ObfuscatedFileUtil* CreateForTesting( | 243 static ObfuscatedFileUtil* CreateForTesting( |
| 243 quota::SpecialStoragePolicy* special_storage_policy, | 244 quota::SpecialStoragePolicy* special_storage_policy, |
| 244 const base::FilePath& file_system_directory, | 245 const base::FilePath& file_system_directory, |
| 245 base::SequencedTaskRunner* file_task_runner); | 246 base::SequencedTaskRunner* file_task_runner); |
| 246 | 247 |
| 247 base::FilePath GetDirectoryForURL( | 248 base::FilePath GetDirectoryForURL( |
| 248 const FileSystemURL& url, | 249 const FileSystemURL& url, |
| 249 bool create, | 250 bool create, |
| 250 base::PlatformFileError* error_code); | 251 base::File::Error* error_code); |
| 251 | 252 |
| 252 // This just calls get_type_string_for_url_ callback that is given in ctor. | 253 // This just calls get_type_string_for_url_ callback that is given in ctor. |
| 253 std::string CallGetTypeStringForURL(const FileSystemURL& url); | 254 std::string CallGetTypeStringForURL(const FileSystemURL& url); |
| 254 | 255 |
| 255 base::PlatformFileError GetFileInfoInternal( | 256 base::File::Error GetFileInfoInternal( |
| 256 SandboxDirectoryDatabase* db, | 257 SandboxDirectoryDatabase* db, |
| 257 FileSystemOperationContext* context, | 258 FileSystemOperationContext* context, |
| 258 const FileSystemURL& url, | 259 const FileSystemURL& url, |
| 259 FileId file_id, | 260 FileId file_id, |
| 260 FileInfo* local_info, | 261 FileInfo* local_info, |
| 261 base::PlatformFileInfo* file_info, | 262 base::File::Info* file_info, |
| 262 base::FilePath* platform_file_path); | 263 base::FilePath* platform_file_path); |
| 263 | 264 |
| 264 // Creates a new file, both the underlying backing file and the entry in the | 265 // Creates a new file, both the underlying backing file and the entry in the |
| 265 // database. |dest_file_info| is an in-out parameter. Supply the name and | 266 // database. |dest_file_info| is an in-out parameter. Supply the name and |
| 266 // parent_id; data_path is ignored. On success, data_path will | 267 // parent_id; data_path is ignored. On success, data_path will |
| 267 // always be set to the relative path [from the root of the type-specific | 268 // always be set to the relative path [from the root of the type-specific |
| 268 // filesystem directory] of a NEW backing file, and handle, if supplied, will | 269 // filesystem directory] of a NEW backing file, and handle, if supplied, will |
| 269 // hold open PlatformFile for the backing file, which the caller is | 270 // hold open PlatformFile for the backing file, which the caller is |
| 270 // responsible for closing. If you supply a path in |source_path|, it will be | 271 // responsible for closing. If you supply a path in |source_path|, it will be |
| 271 // used as a source from which to COPY data. | 272 // used as a source from which to COPY data. |
| 272 // Caveat: do not supply handle if you're also supplying a data path. It was | 273 // Caveat: do not supply handle if you're also supplying a data path. It was |
| 273 // easier not to support this, and no code has needed it so far, so it will | 274 // easier not to support this, and no code has needed it so far, so it will |
| 274 // DCHECK and handle will hold base::kInvalidPlatformFileValue. | 275 // DCHECK and handle will hold base::kInvalidPlatformFileValue. |
| 275 base::PlatformFileError CreateFile( | 276 base::File::Error CreateFile( |
| 276 FileSystemOperationContext* context, | 277 FileSystemOperationContext* context, |
| 277 const base::FilePath& source_file_path, | 278 const base::FilePath& source_file_path, |
| 278 const FileSystemURL& dest_url, | 279 const FileSystemURL& dest_url, |
| 279 FileInfo* dest_file_info, | 280 FileInfo* dest_file_info, |
| 280 int file_flags, | 281 int file_flags, |
| 281 base::PlatformFile* handle); | 282 base::PlatformFile* handle); |
| 282 | 283 |
| 283 // This converts from a relative path [as is stored in the FileInfo.data_path | 284 // This converts from a relative path [as is stored in the FileInfo.data_path |
| 284 // field] to an absolute platform path that can be given to the native | 285 // field] to an absolute platform path that can be given to the native |
| 285 // filesystem. | 286 // filesystem. |
| 286 base::FilePath DataPathToLocalPath( | 287 base::FilePath DataPathToLocalPath( |
| 287 const FileSystemURL& url, | 288 const FileSystemURL& url, |
| 288 const base::FilePath& data_file_path); | 289 const base::FilePath& data_file_path); |
| 289 | 290 |
| 290 std::string GetDirectoryDatabaseKey(const GURL& origin, | 291 std::string GetDirectoryDatabaseKey(const GURL& origin, |
| 291 const std::string& type_string); | 292 const std::string& type_string); |
| 292 | 293 |
| 293 // This returns NULL if |create| flag is false and a filesystem does not | 294 // This returns NULL if |create| flag is false and a filesystem does not |
| 294 // exist for the given |url|. | 295 // exist for the given |url|. |
| 295 // For read operations |create| should be false. | 296 // For read operations |create| should be false. |
| 296 SandboxDirectoryDatabase* GetDirectoryDatabase(const FileSystemURL& url, | 297 SandboxDirectoryDatabase* GetDirectoryDatabase(const FileSystemURL& url, |
| 297 bool create); | 298 bool create); |
| 298 | 299 |
| 299 // Gets the topmost directory specific to this origin. This will | 300 // Gets the topmost directory specific to this origin. This will |
| 300 // contain both the filesystem type subdirectories. | 301 // contain both the filesystem type subdirectories. |
| 301 base::FilePath GetDirectoryForOrigin(const GURL& origin, | 302 base::FilePath GetDirectoryForOrigin(const GURL& origin, |
| 302 bool create, | 303 bool create, |
| 303 base::PlatformFileError* error_code); | 304 base::File::Error* error_code); |
| 304 | 305 |
| 305 void InvalidateUsageCache(FileSystemOperationContext* context, | 306 void InvalidateUsageCache(FileSystemOperationContext* context, |
| 306 const GURL& origin, | 307 const GURL& origin, |
| 307 FileSystemType type); | 308 FileSystemType type); |
| 308 | 309 |
| 309 void MarkUsed(); | 310 void MarkUsed(); |
| 310 void DropDatabases(); | 311 void DropDatabases(); |
| 311 | 312 |
| 312 // Initializes the origin database. |origin_hint| may be used as a hint | 313 // Initializes the origin database. |origin_hint| may be used as a hint |
| 313 // for initializing database if it's not empty. | 314 // for initializing database if it's not empty. |
| 314 bool InitOriginDatabase(const GURL& origin_hint, bool create); | 315 bool InitOriginDatabase(const GURL& origin_hint, bool create); |
| 315 | 316 |
| 316 base::PlatformFileError GenerateNewLocalPath( | 317 base::File::Error GenerateNewLocalPath( |
| 317 SandboxDirectoryDatabase* db, | 318 SandboxDirectoryDatabase* db, |
| 318 FileSystemOperationContext* context, | 319 FileSystemOperationContext* context, |
| 319 const FileSystemURL& url, | 320 const FileSystemURL& url, |
| 320 base::FilePath* local_path); | 321 base::FilePath* local_path); |
| 321 | 322 |
| 322 base::PlatformFileError CreateOrOpenInternal( | 323 base::File::Error CreateOrOpenInternal( |
| 323 FileSystemOperationContext* context, | 324 FileSystemOperationContext* context, |
| 324 const FileSystemURL& url, | 325 const FileSystemURL& url, |
| 325 int file_flags, | 326 int file_flags, |
| 326 base::PlatformFile* file_handle, | 327 base::PlatformFile* file_handle, |
| 327 bool* created); | 328 bool* created); |
| 328 | 329 |
| 329 bool HasIsolatedStorage(const GURL& origin); | 330 bool HasIsolatedStorage(const GURL& origin); |
| 330 | 331 |
| 331 typedef std::map<std::string, SandboxDirectoryDatabase*> DirectoryMap; | 332 typedef std::map<std::string, SandboxDirectoryDatabase*> DirectoryMap; |
| 332 DirectoryMap directories_; | 333 DirectoryMap directories_; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 345 | 346 |
| 346 // Not owned. | 347 // Not owned. |
| 347 SandboxFileSystemBackendDelegate* sandbox_delegate_; | 348 SandboxFileSystemBackendDelegate* sandbox_delegate_; |
| 348 | 349 |
| 349 DISALLOW_COPY_AND_ASSIGN(ObfuscatedFileUtil); | 350 DISALLOW_COPY_AND_ASSIGN(ObfuscatedFileUtil); |
| 350 }; | 351 }; |
| 351 | 352 |
| 352 } // namespace fileapi | 353 } // namespace fileapi |
| 353 | 354 |
| 354 #endif // WEBKIT_BROWSER_FILEAPI_OBFUSCATED_FILE_UTIL_H_ | 355 #endif // WEBKIT_BROWSER_FILEAPI_OBFUSCATED_FILE_UTIL_H_ |
| OLD | NEW |