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; supply data_path if you want it to be used as a source from |
146 // which to COPY data--otherwise leave it empty. On success, data_path will | 164 // which to COPY data--otherwise leave it empty. On success, data_path will |
michaeln
2011/05/20 02:15:16
please fixup this comment
* make it clear that fi
ericu
2011/05/20 02:23:25
Done, thanks for catching that.
| |
147 // always be set to the full path of a NEW backing file, and handle, if | 165 // always be set to the full path of a NEW backing file, and handle, if |
148 // supplied, will hold open PlatformFile for the backing file, which the | 166 // supplied, will hold open PlatformFile for the backing file, which the |
149 // caller is responsible for closing. | 167 // caller is responsible for closing. |
150 // Caveat: do not supply handle if you're also supplying a data path. It was | 168 // 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 | 169 // easier not to support this, and no code has needed it so far, so it will |
152 // DCHECK and handle will hold base::kInvalidPlatformFileValue. | 170 // DCHECK and handle will hold base::kInvalidPlatformFileValue. |
153 base::PlatformFileError CreateFile( | 171 base::PlatformFileError CreateFile( |
154 FileSystemOperationContext* context, | 172 FileSystemOperationContext* context, |
155 const GURL& origin_url, FileSystemType type, | 173 const GURL& origin_url, FileSystemType type, |
156 FileInfo* file_info, | 174 const FilePath& source_path, FileInfo* file_info, |
157 int file_flags, base::PlatformFile* handle); | 175 int file_flags, base::PlatformFile* handle); |
158 // Given the filesystem's root URL and a virtual path, produces a real, full | 176 // Given the filesystem's root URL and a virtual path, produces a real, full |
159 // local path to the underlying data file. | 177 // local path to the underlying data file. This does a database lookup, and |
178 // verifies that the file exists. | |
160 FilePath GetLocalPath( | 179 FilePath GetLocalPath( |
161 const GURL& origin_url, | 180 const GURL& origin_url, |
162 FileSystemType type, | 181 FileSystemType type, |
163 const FilePath& virtual_path); | 182 const FilePath& virtual_path); |
183 // This converts from a relative path [as is stored in the FileInfo.data_path | |
184 // field] to an absolute local path that can be given to the operating system. | |
185 // It does no checks as to whether the file actually exists; it's pure path | |
186 // manipulation. | |
187 FilePath DataPathToLocalPath( | |
188 const GURL& origin, FileSystemType type, const FilePath& virtual_path); | |
michaeln
2011/05/20 02:15:16
virtual_path s/b data_path in the arg list
ericu
2011/05/20 02:23:25
Done.
| |
189 // This does the reverse of DataPathToLocalPath. | |
190 FilePath LocalPathToDataPath( | |
191 const GURL& origin, FileSystemType type, const FilePath& data_path); | |
164 FileSystemDirectoryDatabase* GetDirectoryDatabase( | 192 FileSystemDirectoryDatabase* GetDirectoryDatabase( |
165 const GURL& origin_url, FileSystemType type); | 193 const GURL& origin_url, FileSystemType type); |
166 void MarkUsed(); | 194 void MarkUsed(); |
167 void DropDatabases(); | 195 void DropDatabases(); |
196 bool DestroyDirectoryDatabase(const GURL& origin, FileSystemType type); | |
168 | 197 |
169 typedef std::map<std::string, FileSystemDirectoryDatabase*> DirectoryMap; | 198 typedef std::map<std::string, FileSystemDirectoryDatabase*> DirectoryMap; |
170 DirectoryMap directories_; | 199 DirectoryMap directories_; |
171 scoped_ptr<FileSystemOriginDatabase> origin_database_; | 200 scoped_ptr<FileSystemOriginDatabase> origin_database_; |
172 FilePath file_system_directory_; | 201 FilePath file_system_directory_; |
173 base::OneShotTimer<ObfuscatedFileSystemFileUtil> timer_; | 202 base::OneShotTimer<ObfuscatedFileSystemFileUtil> timer_; |
174 | 203 |
175 DISALLOW_COPY_AND_ASSIGN(ObfuscatedFileSystemFileUtil); | 204 DISALLOW_COPY_AND_ASSIGN(ObfuscatedFileSystemFileUtil); |
176 }; | 205 }; |
177 | 206 |
178 } // namespace fileapi | 207 } // namespace fileapi |
179 | 208 |
180 #endif // WEBKIT_FILEAPI_OBFUSCATED_FILE_SYSTEM_FILE_UTIL_H_ | 209 #endif // WEBKIT_FILEAPI_OBFUSCATED_FILE_SYSTEM_FILE_UTIL_H_ |
OLD | NEW |