OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_SYSTEM_FILE_UTIL_H_ | 5 #ifndef WEBKIT_FILEAPI_OBFUSCATED_FILE_SYSTEM_FILE_UTIL_H_ |
6 #define WEBKIT_FILEAPI_OBFUSCATED_FILE_SYSTEM_FILE_UTIL_H_ | 6 #define WEBKIT_FILEAPI_OBFUSCATED_FILE_SYSTEM_FILE_UTIL_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 23 matching lines...) Expand all Loading... |
34 // backing file than have a database entry whose backing file is missing. When | 34 // backing file than have a database entry whose backing file is missing. When |
35 // doing FSCK operations, if you find a loose backing file with no reference, | 35 // doing FSCK operations, if you find a loose backing file with no reference, |
36 // you may safely delete it. | 36 // you may safely delete it. |
37 // | 37 // |
38 // This class is RefCountedThreadSafe because it may gain a reference on the IO | 38 // This class is RefCountedThreadSafe because it may gain a reference on the IO |
39 // thread, but must be deleted on the FILE thread because that's where | 39 // thread, but must be deleted on the FILE thread because that's where |
40 // DropDatabases needs to be called. References will be held by the | 40 // DropDatabases needs to be called. References will be held by the |
41 // SandboxMountPointProvider [and the task it uses to drop the reference] and | 41 // SandboxMountPointProvider [and the task it uses to drop the reference] and |
42 // SandboxMountPointProvider::GetFileSystemRootPathTask. Without that last one, | 42 // SandboxMountPointProvider::GetFileSystemRootPathTask. Without that last one, |
43 // we wouldn't need ref counting. | 43 // we wouldn't need ref counting. |
| 44 // |
| 45 // TODO(ericu): We don't ever update directory mtimes; which operations should |
| 46 // do that? |
44 class ObfuscatedFileSystemFileUtil : public FileSystemFileUtil, | 47 class ObfuscatedFileSystemFileUtil : public FileSystemFileUtil, |
45 public base::RefCountedThreadSafe<ObfuscatedFileSystemFileUtil> { | 48 public base::RefCountedThreadSafe<ObfuscatedFileSystemFileUtil> { |
46 public: | 49 public: |
47 | 50 |
48 ObfuscatedFileSystemFileUtil(const FilePath& file_system_directory); | 51 ObfuscatedFileSystemFileUtil(const FilePath& file_system_directory); |
49 virtual ~ObfuscatedFileSystemFileUtil(); | 52 virtual ~ObfuscatedFileSystemFileUtil(); |
50 | 53 |
51 virtual base::PlatformFileError CreateOrOpen( | 54 virtual base::PlatformFileError CreateOrOpen( |
52 FileSystemOperationContext* context, | 55 FileSystemOperationContext* context, |
53 const FilePath& file_path, | 56 const FilePath& file_path, |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 // that were created by LocalFileSystemFileUtil, not all backing files will | 127 // that were created by LocalFileSystemFileUtil, not all backing files will |
125 // actually be in this directory. | 128 // actually be in this directory. |
126 FilePath GetDirectoryForOriginAndType( | 129 FilePath GetDirectoryForOriginAndType( |
127 const GURL& origin, FileSystemType type, bool create); | 130 const GURL& origin, FileSystemType type, bool create); |
128 | 131 |
129 // Gets the topmost directory specific to this origin. This will | 132 // Gets the topmost directory specific to this origin. This will |
130 // contain both the filesystem type subdirectories. See previous comment | 133 // contain both the filesystem type subdirectories. See previous comment |
131 // about migration; TODO(ericu): implement migration and fix these comments. | 134 // about migration; TODO(ericu): implement migration and fix these comments. |
132 FilePath GetDirectoryForOrigin(const GURL& origin, bool create); | 135 FilePath GetDirectoryForOrigin(const GURL& origin, bool create); |
133 | 136 |
| 137 // This will migrate a filesystem from the old passthrough sandbox into the |
| 138 // new obfuscated one. It won't obfuscate the old filenames [it will maintain |
| 139 // the old structure, but move it to a new root], but any new files created |
| 140 // will go into the new standard locations. This will be completely |
| 141 // transparent to the user. This migration is atomic in that it won't alter |
| 142 // the source data until it's done, and that will be with a single directory |
| 143 // move [the directory with the unguessable name will move into the new |
| 144 // filesystem storage directory]. However, if this fails partway through, it |
| 145 // might leave a seemingly-valid database for this origin. When it starts up, |
| 146 // it will clear any such database, just in case. |
| 147 bool MigrateFromOldSandbox( |
| 148 const GURL& origin, FileSystemType type, const FilePath& root); |
| 149 |
| 150 FilePath::StringType GetDirectoryNameForType(FileSystemType type) const; |
| 151 |
134 protected: | 152 protected: |
135 virtual AbstractFileEnumerator* CreateFileEnumerator( | 153 virtual AbstractFileEnumerator* CreateFileEnumerator( |
136 FileSystemOperationContext* context, | 154 FileSystemOperationContext* context, |
137 const FilePath& root_path) OVERRIDE; | 155 const FilePath& root_path) OVERRIDE; |
138 | 156 |
139 private: | 157 private: |
140 typedef FileSystemDirectoryDatabase::FileId FileId; | 158 typedef FileSystemDirectoryDatabase::FileId FileId; |
141 typedef FileSystemDirectoryDatabase::FileInfo FileInfo; | 159 typedef FileSystemDirectoryDatabase::FileInfo FileInfo; |
142 | 160 |
143 // Creates a new file, both the underlying backing file and the entry in the | 161 // Creates a new file, both the underlying backing file and the entry in the |
144 // database. file_info is an in-out parameter. Supply the name and | 162 // database. file_info is an in-out parameter. Supply the name and |
145 // parent_id; supply data_path if you want it to be used as a source from | 163 // parent_id; data_path is ignored. On success, data_path will |
146 // which to COPY data--otherwise leave it empty. On success, data_path will | 164 // always be set to the relative path [from the root of the type-specific |
147 // always be set to the full path of a NEW backing file, and handle, if | 165 // filesystem directory] of a NEW backing file, and handle, if supplied, will |
148 // supplied, will hold open PlatformFile for the backing file, which the | 166 // hold open PlatformFile for the backing file, which the caller is |
149 // caller is responsible for closing. | 167 // responsible for closing. If you supply a path in source_path, it will be |
| 168 // used as a source from which to COPY data. |
150 // Caveat: do not supply handle if you're also supplying a data path. It was | 169 // Caveat: do not supply handle if you're also supplying a data path. It was |
151 // easier not to support this, and no code has needed it so far, so it will | 170 // easier not to support this, and no code has needed it so far, so it will |
152 // DCHECK and handle will hold base::kInvalidPlatformFileValue. | 171 // DCHECK and handle will hold base::kInvalidPlatformFileValue. |
153 base::PlatformFileError CreateFile( | 172 base::PlatformFileError CreateFile( |
154 FileSystemOperationContext* context, | 173 FileSystemOperationContext* context, |
155 const GURL& origin_url, FileSystemType type, | 174 const GURL& origin_url, FileSystemType type, |
156 FileInfo* file_info, | 175 const FilePath& source_path, FileInfo* file_info, |
157 int file_flags, base::PlatformFile* handle); | 176 int file_flags, base::PlatformFile* handle); |
158 // Given the filesystem's root URL and a virtual path, produces a real, full | 177 // Given the filesystem's root URL and a virtual path, produces a real, full |
159 // local path to the underlying data file. | 178 // local path to the underlying data file. This does a database lookup, and |
| 179 // verifies that the file exists. |
160 FilePath GetLocalPath( | 180 FilePath GetLocalPath( |
161 const GURL& origin_url, | 181 const GURL& origin_url, |
162 FileSystemType type, | 182 FileSystemType type, |
163 const FilePath& virtual_path); | 183 const FilePath& virtual_path); |
| 184 // This converts from a relative path [as is stored in the FileInfo.data_path |
| 185 // field] to an absolute local path that can be given to the operating system. |
| 186 // It does no checks as to whether the file actually exists; it's pure path |
| 187 // manipulation. |
| 188 FilePath DataPathToLocalPath( |
| 189 const GURL& origin, FileSystemType type, const FilePath& data_path); |
| 190 // This does the reverse of DataPathToLocalPath. |
| 191 FilePath LocalPathToDataPath( |
| 192 const GURL& origin, FileSystemType type, const FilePath& local_path); |
164 FileSystemDirectoryDatabase* GetDirectoryDatabase( | 193 FileSystemDirectoryDatabase* GetDirectoryDatabase( |
165 const GURL& origin_url, FileSystemType type); | 194 const GURL& origin_url, FileSystemType type); |
166 void MarkUsed(); | 195 void MarkUsed(); |
167 void DropDatabases(); | 196 void DropDatabases(); |
| 197 bool DestroyDirectoryDatabase(const GURL& origin, FileSystemType type); |
168 | 198 |
169 typedef std::map<std::string, FileSystemDirectoryDatabase*> DirectoryMap; | 199 typedef std::map<std::string, FileSystemDirectoryDatabase*> DirectoryMap; |
170 DirectoryMap directories_; | 200 DirectoryMap directories_; |
171 scoped_ptr<FileSystemOriginDatabase> origin_database_; | 201 scoped_ptr<FileSystemOriginDatabase> origin_database_; |
172 FilePath file_system_directory_; | 202 FilePath file_system_directory_; |
173 base::OneShotTimer<ObfuscatedFileSystemFileUtil> timer_; | 203 base::OneShotTimer<ObfuscatedFileSystemFileUtil> timer_; |
174 | 204 |
175 DISALLOW_COPY_AND_ASSIGN(ObfuscatedFileSystemFileUtil); | 205 DISALLOW_COPY_AND_ASSIGN(ObfuscatedFileSystemFileUtil); |
176 }; | 206 }; |
177 | 207 |
178 } // namespace fileapi | 208 } // namespace fileapi |
179 | 209 |
180 #endif // WEBKIT_FILEAPI_OBFUSCATED_FILE_SYSTEM_FILE_UTIL_H_ | 210 #endif // WEBKIT_FILEAPI_OBFUSCATED_FILE_SYSTEM_FILE_UTIL_H_ |
OLD | NEW |