| 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_FILEAPI_OBFUSCATED_FILE_UTIL_H_ | 5 #ifndef WEBKIT_FILEAPI_OBFUSCATED_FILE_UTIL_H_ |
| 6 #define WEBKIT_FILEAPI_OBFUSCATED_FILE_UTIL_H_ | 6 #define WEBKIT_FILEAPI_OBFUSCATED_FILE_UTIL_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 public: | 48 public: |
| 49 virtual ~AbstractOriginEnumerator() {} | 49 virtual ~AbstractOriginEnumerator() {} |
| 50 | 50 |
| 51 // Returns the next origin. Returns empty if there are no more origins. | 51 // Returns the next origin. Returns empty if there are no more origins. |
| 52 virtual GURL Next() = 0; | 52 virtual GURL Next() = 0; |
| 53 | 53 |
| 54 // Returns the current origin's information. | 54 // Returns the current origin's information. |
| 55 virtual bool HasFileSystemType(FileSystemType type) const = 0; | 55 virtual bool HasFileSystemType(FileSystemType type) const = 0; |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 explicit ObfuscatedFileUtil(const FilePath& file_system_directory); | 58 explicit ObfuscatedFileUtil(const base::FilePath& file_system_directory); |
| 59 virtual ~ObfuscatedFileUtil(); | 59 virtual ~ObfuscatedFileUtil(); |
| 60 | 60 |
| 61 // FileSystemFileUtil overrides. | 61 // FileSystemFileUtil overrides. |
| 62 virtual base::PlatformFileError CreateOrOpen( | 62 virtual base::PlatformFileError CreateOrOpen( |
| 63 FileSystemOperationContext* context, | 63 FileSystemOperationContext* context, |
| 64 const FileSystemURL& url, | 64 const FileSystemURL& url, |
| 65 int file_flags, | 65 int file_flags, |
| 66 base::PlatformFile* file_handle, | 66 base::PlatformFile* file_handle, |
| 67 bool* created) OVERRIDE; | 67 bool* created) OVERRIDE; |
| 68 virtual base::PlatformFileError Close( | 68 virtual base::PlatformFileError Close( |
| 69 FileSystemOperationContext* context, | 69 FileSystemOperationContext* context, |
| 70 base::PlatformFile file) OVERRIDE; | 70 base::PlatformFile file) OVERRIDE; |
| 71 virtual base::PlatformFileError EnsureFileExists( | 71 virtual base::PlatformFileError EnsureFileExists( |
| 72 FileSystemOperationContext* context, | 72 FileSystemOperationContext* context, |
| 73 const FileSystemURL& url, bool* created) OVERRIDE; | 73 const FileSystemURL& url, bool* created) OVERRIDE; |
| 74 virtual base::PlatformFileError CreateDirectory( | 74 virtual base::PlatformFileError CreateDirectory( |
| 75 FileSystemOperationContext* context, | 75 FileSystemOperationContext* context, |
| 76 const FileSystemURL& url, | 76 const FileSystemURL& url, |
| 77 bool exclusive, | 77 bool exclusive, |
| 78 bool recursive) OVERRIDE; | 78 bool recursive) OVERRIDE; |
| 79 virtual base::PlatformFileError GetFileInfo( | 79 virtual base::PlatformFileError GetFileInfo( |
| 80 FileSystemOperationContext* context, | 80 FileSystemOperationContext* context, |
| 81 const FileSystemURL& url, | 81 const FileSystemURL& url, |
| 82 base::PlatformFileInfo* file_info, | 82 base::PlatformFileInfo* file_info, |
| 83 FilePath* platform_file) OVERRIDE; | 83 base::FilePath* platform_file) OVERRIDE; |
| 84 virtual scoped_ptr<AbstractFileEnumerator> CreateFileEnumerator( | 84 virtual scoped_ptr<AbstractFileEnumerator> CreateFileEnumerator( |
| 85 FileSystemOperationContext* context, | 85 FileSystemOperationContext* context, |
| 86 const FileSystemURL& root_url, | 86 const FileSystemURL& root_url, |
| 87 bool recursive) OVERRIDE; | 87 bool recursive) OVERRIDE; |
| 88 virtual base::PlatformFileError GetLocalFilePath( | 88 virtual base::PlatformFileError GetLocalFilePath( |
| 89 FileSystemOperationContext* context, | 89 FileSystemOperationContext* context, |
| 90 const FileSystemURL& file_system_url, | 90 const FileSystemURL& file_system_url, |
| 91 FilePath* local_path) OVERRIDE; | 91 base::FilePath* local_path) OVERRIDE; |
| 92 virtual base::PlatformFileError Touch( | 92 virtual base::PlatformFileError Touch( |
| 93 FileSystemOperationContext* context, | 93 FileSystemOperationContext* context, |
| 94 const FileSystemURL& url, | 94 const FileSystemURL& url, |
| 95 const base::Time& last_access_time, | 95 const base::Time& last_access_time, |
| 96 const base::Time& last_modified_time) OVERRIDE; | 96 const base::Time& last_modified_time) OVERRIDE; |
| 97 virtual base::PlatformFileError Truncate( | 97 virtual base::PlatformFileError Truncate( |
| 98 FileSystemOperationContext* context, | 98 FileSystemOperationContext* context, |
| 99 const FileSystemURL& url, | 99 const FileSystemURL& url, |
| 100 int64 length) OVERRIDE; | 100 int64 length) OVERRIDE; |
| 101 virtual base::PlatformFileError CopyOrMoveFile( | 101 virtual base::PlatformFileError CopyOrMoveFile( |
| 102 FileSystemOperationContext* context, | 102 FileSystemOperationContext* context, |
| 103 const FileSystemURL& src_url, | 103 const FileSystemURL& src_url, |
| 104 const FileSystemURL& dest_url, | 104 const FileSystemURL& dest_url, |
| 105 bool copy) OVERRIDE; | 105 bool copy) OVERRIDE; |
| 106 virtual base::PlatformFileError CopyInForeignFile( | 106 virtual base::PlatformFileError CopyInForeignFile( |
| 107 FileSystemOperationContext* context, | 107 FileSystemOperationContext* context, |
| 108 const FilePath& src_file_path, | 108 const base::FilePath& src_file_path, |
| 109 const FileSystemURL& dest_url) OVERRIDE; | 109 const FileSystemURL& dest_url) OVERRIDE; |
| 110 virtual base::PlatformFileError DeleteFile( | 110 virtual base::PlatformFileError DeleteFile( |
| 111 FileSystemOperationContext* context, | 111 FileSystemOperationContext* context, |
| 112 const FileSystemURL& url) OVERRIDE; | 112 const FileSystemURL& url) OVERRIDE; |
| 113 virtual base::PlatformFileError DeleteDirectory( | 113 virtual base::PlatformFileError DeleteDirectory( |
| 114 FileSystemOperationContext* context, | 114 FileSystemOperationContext* context, |
| 115 const FileSystemURL& url) OVERRIDE; | 115 const FileSystemURL& url) OVERRIDE; |
| 116 virtual base::PlatformFileError CreateSnapshotFile( | 116 virtual base::PlatformFileError CreateSnapshotFile( |
| 117 FileSystemOperationContext* context, | 117 FileSystemOperationContext* context, |
| 118 const FileSystemURL& url, | 118 const FileSystemURL& url, |
| 119 base::PlatformFileInfo* file_info, | 119 base::PlatformFileInfo* file_info, |
| 120 FilePath* platform_path, | 120 base::FilePath* platform_path, |
| 121 SnapshotFilePolicy* policy) OVERRIDE; | 121 SnapshotFilePolicy* policy) OVERRIDE; |
| 122 | 122 |
| 123 // Returns true if the directory |url| is empty. | 123 // Returns true if the directory |url| is empty. |
| 124 bool IsDirectoryEmpty( | 124 bool IsDirectoryEmpty( |
| 125 FileSystemOperationContext* context, | 125 FileSystemOperationContext* context, |
| 126 const FileSystemURL& url); | 126 const FileSystemURL& url); |
| 127 | 127 |
| 128 // Gets the topmost directory specific to this origin and type. This will | 128 // Gets the topmost directory specific to this origin and type. This will |
| 129 // contain both the directory database's files and all the backing file | 129 // contain both the directory database's files and all the backing file |
| 130 // subdirectories. | 130 // subdirectories. |
| 131 // Returns an empty path if the directory is undefined (e.g. because |type| | 131 // Returns an empty path if the directory is undefined (e.g. because |type| |
| 132 // is invalid). If the directory is defined, it will be returned, even if | 132 // is invalid). If the directory is defined, it will be returned, even if |
| 133 // there is a file system error (e.g. the directory doesn't exist on disk and | 133 // there is a file system error (e.g. the directory doesn't exist on disk and |
| 134 // |create| is false). Callers should always check |error_code| to make sure | 134 // |create| is false). Callers should always check |error_code| to make sure |
| 135 // the returned path is usable. | 135 // the returned path is usable. |
| 136 FilePath GetDirectoryForOriginAndType( | 136 base::FilePath GetDirectoryForOriginAndType( |
| 137 const GURL& origin, | 137 const GURL& origin, |
| 138 FileSystemType type, | 138 FileSystemType type, |
| 139 bool create, | 139 bool create, |
| 140 base::PlatformFileError* error_code); | 140 base::PlatformFileError* error_code); |
| 141 | 141 |
| 142 // Deletes the topmost directory specific to this origin and type. This will | 142 // Deletes the topmost directory specific to this origin and type. This will |
| 143 // delete its directory database. | 143 // delete its directory database. |
| 144 bool DeleteDirectoryForOriginAndType(const GURL& origin, FileSystemType type); | 144 bool DeleteDirectoryForOriginAndType(const GURL& origin, FileSystemType type); |
| 145 | 145 |
| 146 // TODO(ericu): This doesn't really feel like it belongs in this class. | 146 // TODO(ericu): This doesn't really feel like it belongs in this class. |
| 147 // The previous version lives in FileSystemPathManager, but perhaps | 147 // The previous version lives in FileSystemPathManager, but perhaps |
| 148 // SandboxMountPointProvider would be better? | 148 // SandboxMountPointProvider would be better? |
| 149 static FilePath::StringType GetDirectoryNameForType(FileSystemType type); | 149 static base::FilePath::StringType GetDirectoryNameForType(FileSystemType type)
; |
| 150 | 150 |
| 151 // This method and all methods of its returned class must be called only on | 151 // This method and all methods of its returned class must be called only on |
| 152 // the FILE thread. The caller is responsible for deleting the returned | 152 // the FILE thread. The caller is responsible for deleting the returned |
| 153 // object. | 153 // object. |
| 154 AbstractOriginEnumerator* CreateOriginEnumerator(); | 154 AbstractOriginEnumerator* CreateOriginEnumerator(); |
| 155 | 155 |
| 156 // Deletes a directory database from the database list in the ObfuscatedFSFU | 156 // Deletes a directory database from the database list in the ObfuscatedFSFU |
| 157 // and destroys the database on the disk. | 157 // and destroys the database on the disk. |
| 158 bool DestroyDirectoryDatabase(const GURL& origin, FileSystemType type); | 158 bool DestroyDirectoryDatabase(const GURL& origin, FileSystemType type); |
| 159 | 159 |
| 160 // Computes a cost for storing a given file in the obfuscated FSFU. | 160 // Computes a cost for storing a given file in the obfuscated FSFU. |
| 161 // As the cost of a file is independent of the cost of its parent directories, | 161 // As the cost of a file is independent of the cost of its parent directories, |
| 162 // this ignores all but the BaseName of the supplied path. In order to | 162 // this ignores all but the BaseName of the supplied path. In order to |
| 163 // compute the cost of adding a multi-segment directory recursively, call this | 163 // compute the cost of adding a multi-segment directory recursively, call this |
| 164 // on each path segment and add the results. | 164 // on each path segment and add the results. |
| 165 static int64 ComputeFilePathCost(const FilePath& path); | 165 static int64 ComputeFilePathCost(const base::FilePath& path); |
| 166 | 166 |
| 167 private: | 167 private: |
| 168 typedef FileSystemDirectoryDatabase::FileId FileId; | 168 typedef FileSystemDirectoryDatabase::FileId FileId; |
| 169 typedef FileSystemDirectoryDatabase::FileInfo FileInfo; | 169 typedef FileSystemDirectoryDatabase::FileInfo FileInfo; |
| 170 | 170 |
| 171 friend class ObfuscatedFileEnumerator; | 171 friend class ObfuscatedFileEnumerator; |
| 172 | 172 |
| 173 base::PlatformFileError GetFileInfoInternal( | 173 base::PlatformFileError GetFileInfoInternal( |
| 174 FileSystemDirectoryDatabase* db, | 174 FileSystemDirectoryDatabase* db, |
| 175 FileSystemOperationContext* context, | 175 FileSystemOperationContext* context, |
| 176 const GURL& origin, | 176 const GURL& origin, |
| 177 FileSystemType type, | 177 FileSystemType type, |
| 178 FileId file_id, | 178 FileId file_id, |
| 179 FileInfo* local_info, | 179 FileInfo* local_info, |
| 180 base::PlatformFileInfo* file_info, | 180 base::PlatformFileInfo* file_info, |
| 181 FilePath* platform_file_path); | 181 base::FilePath* platform_file_path); |
| 182 | 182 |
| 183 // Creates a new file, both the underlying backing file and the entry in the | 183 // Creates a new file, both the underlying backing file and the entry in the |
| 184 // database. |dest_file_info| is an in-out parameter. Supply the name and | 184 // database. |dest_file_info| is an in-out parameter. Supply the name and |
| 185 // parent_id; data_path is ignored. On success, data_path will | 185 // parent_id; data_path is ignored. On success, data_path will |
| 186 // always be set to the relative path [from the root of the type-specific | 186 // always be set to the relative path [from the root of the type-specific |
| 187 // filesystem directory] of a NEW backing file, and handle, if supplied, will | 187 // filesystem directory] of a NEW backing file, and handle, if supplied, will |
| 188 // hold open PlatformFile for the backing file, which the caller is | 188 // hold open PlatformFile for the backing file, which the caller is |
| 189 // responsible for closing. If you supply a path in |source_path|, it will be | 189 // responsible for closing. If you supply a path in |source_path|, it will be |
| 190 // used as a source from which to COPY data. | 190 // used as a source from which to COPY data. |
| 191 // Caveat: do not supply handle if you're also supplying a data path. It was | 191 // Caveat: do not supply handle if you're also supplying a data path. It was |
| 192 // easier not to support this, and no code has needed it so far, so it will | 192 // easier not to support this, and no code has needed it so far, so it will |
| 193 // DCHECK and handle will hold base::kInvalidPlatformFileValue. | 193 // DCHECK and handle will hold base::kInvalidPlatformFileValue. |
| 194 base::PlatformFileError CreateFile( | 194 base::PlatformFileError CreateFile( |
| 195 FileSystemOperationContext* context, | 195 FileSystemOperationContext* context, |
| 196 const FilePath& source_file_path, | 196 const base::FilePath& source_file_path, |
| 197 const GURL& dest_origin, | 197 const GURL& dest_origin, |
| 198 FileSystemType dest_type, | 198 FileSystemType dest_type, |
| 199 FileInfo* dest_file_info, | 199 FileInfo* dest_file_info, |
| 200 int file_flags, | 200 int file_flags, |
| 201 base::PlatformFile* handle); | 201 base::PlatformFile* handle); |
| 202 | 202 |
| 203 // This converts from a relative path [as is stored in the FileInfo.data_path | 203 // This converts from a relative path [as is stored in the FileInfo.data_path |
| 204 // field] to an absolute platform path that can be given to the native | 204 // field] to an absolute platform path that can be given to the native |
| 205 // filesystem. | 205 // filesystem. |
| 206 FilePath DataPathToLocalPath( | 206 base::FilePath DataPathToLocalPath( |
| 207 const GURL& origin, | 207 const GURL& origin, |
| 208 FileSystemType type, | 208 FileSystemType type, |
| 209 const FilePath& data_file_path); | 209 const base::FilePath& data_file_path); |
| 210 | 210 |
| 211 // This returns NULL if |create| flag is false and a filesystem does not | 211 // This returns NULL if |create| flag is false and a filesystem does not |
| 212 // exist for the given |origin_url| and |type|. | 212 // exist for the given |origin_url| and |type|. |
| 213 // For read operations |create| should be false. | 213 // For read operations |create| should be false. |
| 214 FileSystemDirectoryDatabase* GetDirectoryDatabase( | 214 FileSystemDirectoryDatabase* GetDirectoryDatabase( |
| 215 const GURL& origin_url, FileSystemType type, bool create); | 215 const GURL& origin_url, FileSystemType type, bool create); |
| 216 | 216 |
| 217 // Gets the topmost directory specific to this origin. This will | 217 // Gets the topmost directory specific to this origin. This will |
| 218 // contain both the filesystem type subdirectories. | 218 // contain both the filesystem type subdirectories. |
| 219 FilePath GetDirectoryForOrigin(const GURL& origin, | 219 base::FilePath GetDirectoryForOrigin(const GURL& origin, |
| 220 bool create, | 220 bool create, |
| 221 base::PlatformFileError* error_code); | 221 base::PlatformFileError* error_code); |
| 222 | 222 |
| 223 void InvalidateUsageCache(FileSystemOperationContext* context, | 223 void InvalidateUsageCache(FileSystemOperationContext* context, |
| 224 const GURL& origin, | 224 const GURL& origin, |
| 225 FileSystemType type); | 225 FileSystemType type); |
| 226 | 226 |
| 227 void MarkUsed(); | 227 void MarkUsed(); |
| 228 void DropDatabases(); | 228 void DropDatabases(); |
| 229 bool InitOriginDatabase(bool create); | 229 bool InitOriginDatabase(bool create); |
| 230 | 230 |
| 231 base::PlatformFileError GenerateNewLocalPath( | 231 base::PlatformFileError GenerateNewLocalPath( |
| 232 FileSystemDirectoryDatabase* db, | 232 FileSystemDirectoryDatabase* db, |
| 233 FileSystemOperationContext* context, | 233 FileSystemOperationContext* context, |
| 234 const GURL& origin, | 234 const GURL& origin, |
| 235 FileSystemType type, | 235 FileSystemType type, |
| 236 FilePath* local_path); | 236 base::FilePath* local_path); |
| 237 | 237 |
| 238 typedef std::map<std::string, FileSystemDirectoryDatabase*> DirectoryMap; | 238 typedef std::map<std::string, FileSystemDirectoryDatabase*> DirectoryMap; |
| 239 DirectoryMap directories_; | 239 DirectoryMap directories_; |
| 240 scoped_ptr<FileSystemOriginDatabase> origin_database_; | 240 scoped_ptr<FileSystemOriginDatabase> origin_database_; |
| 241 FilePath file_system_directory_; | 241 base::FilePath file_system_directory_; |
| 242 base::OneShotTimer<ObfuscatedFileUtil> timer_; | 242 base::OneShotTimer<ObfuscatedFileUtil> timer_; |
| 243 | 243 |
| 244 DISALLOW_COPY_AND_ASSIGN(ObfuscatedFileUtil); | 244 DISALLOW_COPY_AND_ASSIGN(ObfuscatedFileUtil); |
| 245 }; | 245 }; |
| 246 | 246 |
| 247 } // namespace fileapi | 247 } // namespace fileapi |
| 248 | 248 |
| 249 #endif // WEBKIT_FILEAPI_OBFUSCATED_FILE_UTIL_H_ | 249 #endif // WEBKIT_FILEAPI_OBFUSCATED_FILE_UTIL_H_ |
| OLD | NEW |