Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(431)

Side by Side Diff: webkit/fileapi/obfuscated_file_util.h

Issue 7470037: [Refactor] to rename and re-layer the file_util stack layers. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Reflected the comments. Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_UTIL_H_
6 #define WEBKIT_FILEAPI_OBFUSCATED_FILE_SYSTEM_FILE_UTIL_H_ 6 #define WEBKIT_FILEAPI_OBFUSCATED_FILE_UTIL_H_
7 7
8 #include <map> 8 #include <map>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/file_path.h" 11 #include "base/file_path.h"
12 #include "base/file_util_proxy.h" 12 #include "base/file_util_proxy.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/platform_file.h" 14 #include "base/platform_file.h"
15 #include "base/timer.h" 15 #include "base/timer.h"
16 #include "webkit/fileapi/file_system_directory_database.h" 16 #include "webkit/fileapi/file_system_directory_database.h"
(...skipping 20 matching lines...) Expand all
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 // 44 //
45 // TODO(ericu): We don't ever update directory mtimes; which operations should 45 // TODO(ericu): We don't ever update directory mtimes; which operations should
46 // do that? 46 // do that?
47 class ObfuscatedFileSystemFileUtil : public FileSystemFileUtil, 47 class ObfuscatedFileUtil : public FileSystemFileUtil,
48 public base::RefCountedThreadSafe<ObfuscatedFileSystemFileUtil> { 48 public base::RefCountedThreadSafe<ObfuscatedFileUtil> {
49 public: 49 public:
50 // Origin enumerator interface.
51 // An instance of this interface is assumed to be called on the file thread.
52 class AbstractOriginEnumerator {
kinuko 2011/08/29 07:20:00 I think this question is to Eric: It's not related
Dai Mikurube (NOT FULLTIME) 2011/08/30 07:47:28 Ah, I was considering it, too. What do you think,
53 public:
54 virtual ~AbstractOriginEnumerator() {}
55
56 // Returns the next origin. Returns empty if there are no more origins.
57 virtual GURL Next() = 0;
58
59 // Returns the current origin's information.
60 virtual bool HasFileSystemType(FileSystemType type) const = 0;
61 };
62
50 // |underlying_file_util| is owned by the instance. It will be deleted by 63 // |underlying_file_util| is owned by the instance. It will be deleted by
51 // the owner instance. For example, it can be instanciated as follows: 64 // the owner instance. For example, it can be instanciated as follows:
52 // FileSystemFileUtil* file_system_file_util = 65 // FileSystemFileUtil* file_util =
53 // new ObfuscatedFileSystemFileUtil(new FileSystemFileUtil()); 66 // new ObfuscatedFileUtil(new NativeFileUtil());
54 ObfuscatedFileSystemFileUtil( 67 ObfuscatedFileUtil(const FilePath& file_system_directory,
55 const FilePath& file_system_directory, 68 FileSystemFileUtil* underlying_file_util);
56 FileSystemFileUtil* underlying_file_util); 69 virtual ~ObfuscatedFileUtil();
57 virtual ~ObfuscatedFileSystemFileUtil();
58 70
59 virtual base::PlatformFileError CreateOrOpen( 71 virtual base::PlatformFileError CreateOrOpen(
60 FileSystemOperationContext* context, 72 FileSystemOperationContext* context,
61 const FilePath& file_path, 73 const FilePath& file_path,
62 int file_flags, 74 int file_flags,
63 base::PlatformFile* file_handle, 75 base::PlatformFile* file_handle,
64 bool* created) OVERRIDE; 76 bool* created) OVERRIDE;
65 77
66 virtual base::PlatformFileError EnsureFileExists( 78 virtual base::PlatformFileError EnsureFileExists(
67 FileSystemOperationContext* context, 79 FileSystemOperationContext* context,
68 const FilePath& file_path, bool* created) OVERRIDE; 80 const FilePath& file_path, bool* created) OVERRIDE;
69 81
70 virtual base::PlatformFileError GetLocalFilePath( 82 virtual base::PlatformFileError CreateDirectory(
71 FileSystemOperationContext* context, 83 FileSystemOperationContext* context,
72 const FilePath& virtual_file, 84 const FilePath& file_path,
73 FilePath* local_path) OVERRIDE; 85 bool exclusive,
86 bool recursive) OVERRIDE;
74 87
75 virtual base::PlatformFileError GetFileInfo( 88 virtual base::PlatformFileError GetFileInfo(
76 FileSystemOperationContext* context, 89 FileSystemOperationContext* context,
77 const FilePath& file, 90 const FilePath& file,
78 base::PlatformFileInfo* file_info, 91 base::PlatformFileInfo* file_info,
79 FilePath* platform_file) OVERRIDE; 92 FilePath* platform_file) OVERRIDE;
80 93
81 virtual base::PlatformFileError ReadDirectory( 94 virtual base::PlatformFileError ReadDirectory(
82 FileSystemOperationContext* context, 95 FileSystemOperationContext* context,
83 const FilePath& file_path, 96 const FilePath& file_path,
84 std::vector<base::FileUtilProxy::Entry>* entries) OVERRIDE; 97 std::vector<base::FileUtilProxy::Entry>* entries) OVERRIDE;
85 98
86 virtual base::PlatformFileError CreateDirectory( 99 virtual AbstractFileEnumerator* CreateFileEnumerator(
87 FileSystemOperationContext* context, 100 FileSystemOperationContext* context,
88 const FilePath& file_path, 101 const FilePath& root_path) OVERRIDE;
89 bool exclusive,
90 bool recursive) OVERRIDE;
91 102
92 virtual base::PlatformFileError CopyOrMoveFile( 103 virtual base::PlatformFileError GetLocalFilePath(
93 FileSystemOperationContext* context, 104 FileSystemOperationContext* context,
94 const FilePath& src_file_path, 105 const FilePath& virtual_file,
95 const FilePath& dest_file_path, 106 FilePath* local_path) OVERRIDE;
96 bool copy) OVERRIDE;
97
98 virtual PlatformFileError CopyInForeignFile(
99 FileSystemOperationContext* context,
100 const FilePath& src_file_path,
101 const FilePath& dest_file_path) OVERRIDE;
102
103 virtual base::PlatformFileError DeleteFile(
104 FileSystemOperationContext* context,
105 const FilePath& file_path) OVERRIDE;
106
107 virtual base::PlatformFileError DeleteSingleDirectory(
108 FileSystemOperationContext* context,
109 const FilePath& file_path) OVERRIDE;
110 107
111 virtual base::PlatformFileError Touch( 108 virtual base::PlatformFileError Touch(
112 FileSystemOperationContext* context, 109 FileSystemOperationContext* context,
113 const FilePath& file_path, 110 const FilePath& file_path,
114 const base::Time& last_access_time, 111 const base::Time& last_access_time,
115 const base::Time& last_modified_time) OVERRIDE; 112 const base::Time& last_modified_time) OVERRIDE;
116 113
117 virtual base::PlatformFileError Truncate( 114 virtual base::PlatformFileError Truncate(
118 FileSystemOperationContext* context, 115 FileSystemOperationContext* context,
119 const FilePath& path, 116 const FilePath& path,
120 int64 length) OVERRIDE; 117 int64 length) OVERRIDE;
121 118
122 virtual bool PathExists( 119 virtual bool PathExists(
123 FileSystemOperationContext* context, 120 FileSystemOperationContext* context,
124 const FilePath& file_path) OVERRIDE; 121 const FilePath& file_path) OVERRIDE;
125 122
126 virtual bool DirectoryExists( 123 virtual bool DirectoryExists(
127 FileSystemOperationContext* context, 124 FileSystemOperationContext* context,
128 const FilePath& file_path) OVERRIDE; 125 const FilePath& file_path) OVERRIDE;
129 126
130 virtual bool IsDirectoryEmpty( 127 virtual bool IsDirectoryEmpty(
131 FileSystemOperationContext* context, 128 FileSystemOperationContext* context,
132 const FilePath& file_path) OVERRIDE; 129 const FilePath& file_path) OVERRIDE;
133 130
131 virtual base::PlatformFileError CopyOrMoveFile(
132 FileSystemOperationContext* context,
133 const FilePath& src_file_path,
134 const FilePath& dest_file_path,
135 bool copy) OVERRIDE;
136
137 virtual PlatformFileError CopyInForeignFile(
138 FileSystemOperationContext* context,
139 const FilePath& src_file_path,
140 const FilePath& dest_file_path) OVERRIDE;
141
142 virtual base::PlatformFileError DeleteFile(
143 FileSystemOperationContext* context,
144 const FilePath& file_path) OVERRIDE;
145
146 virtual base::PlatformFileError DeleteSingleDirectory(
147 FileSystemOperationContext* context,
148 const FilePath& file_path) OVERRIDE;
149
134 // Gets the topmost directory specific to this origin and type. This will 150 // Gets the topmost directory specific to this origin and type. This will
135 // contain both the directory database's files and all the backing file 151 // contain both the directory database's files and all the backing file
136 // subdirectories. 152 // subdirectories.
137 FilePath GetDirectoryForOriginAndType( 153 FilePath GetDirectoryForOriginAndType(
138 const GURL& origin, FileSystemType type, bool create); 154 const GURL& origin, FileSystemType type, bool create);
139 155
140 // Deletes the topmost directory specific to this origin and type. This will 156 // Deletes the topmost directory specific to this origin and type. This will
141 // delete its directory database. 157 // delete its directory database.
142 bool DeleteDirectoryForOriginAndType(const GURL& origin, FileSystemType type); 158 bool DeleteDirectoryForOriginAndType(const GURL& origin, FileSystemType type);
143 159
144 // This will migrate a filesystem from the old passthrough sandbox into the 160 // This will migrate a filesystem from the old passthrough sandbox into the
145 // new obfuscated one. It won't obfuscate the old filenames [it will maintain 161 // new obfuscated one. It won't obfuscate the old filenames [it will maintain
146 // the old structure, but move it to a new root], but any new files created 162 // the old structure, but move it to a new root], but any new files created
147 // will go into the new standard locations. This will be completely 163 // will go into the new standard locations. This will be completely
148 // transparent to the user. This migration is atomic in that it won't alter 164 // transparent to the user. This migration is atomic in that it won't alter
149 // the source data until it's done, and that will be with a single directory 165 // the source data until it's done, and that will be with a single directory
150 // move [the directory with the unguessable name will move into the new 166 // move [the directory with the unguessable name will move into the new
151 // filesystem storage directory]. However, if this fails partway through, it 167 // filesystem storage directory]. However, if this fails partway through, it
152 // might leave a seemingly-valid database for this origin. When it starts up, 168 // might leave a seemingly-valid database for this origin. When it starts up,
153 // it will clear any such database, just in case. 169 // it will clear any such database, just in case.
154 bool MigrateFromOldSandbox( 170 bool MigrateFromOldSandbox(
155 const GURL& origin, FileSystemType type, const FilePath& root); 171 const GURL& origin, FileSystemType type, const FilePath& root);
156 172
157 // TODO(ericu): This doesn't really feel like it belongs in this class. 173 // TODO(ericu): This doesn't really feel like it belongs in this class.
158 // The previous version lives in FileSystemPathManager, but perhaps 174 // The previous version lives in FileSystemPathManager, but perhaps
159 // SandboxMountPointProvider would be better? 175 // SandboxMountPointProvider would be better?
160 static FilePath::StringType GetDirectoryNameForType(FileSystemType type); 176 static FilePath::StringType GetDirectoryNameForType(FileSystemType type);
161 177
162 // Origin enumerator interface.
163 // An instance of this interface is assumed to be called on the file thread.
164 class AbstractOriginEnumerator {
165 public:
166 virtual ~AbstractOriginEnumerator() {}
167
168 // Returns the next origin. Returns empty if there are no more origins.
169 virtual GURL Next() = 0;
170
171 // Returns the current origin's information.
172 virtual bool HasFileSystemType(FileSystemType type) const = 0;
173 };
174
175 // This method and all methods of its returned class must be called only on 178 // This method and all methods of its returned class must be called only on
176 // the FILE thread. The caller is responsible for deleting the returned 179 // the FILE thread. The caller is responsible for deleting the returned
177 // object. 180 // object.
178 AbstractOriginEnumerator* CreateOriginEnumerator(); 181 AbstractOriginEnumerator* CreateOriginEnumerator();
179 182
180 virtual AbstractFileEnumerator* CreateFileEnumerator(
181 FileSystemOperationContext* context,
182 const FilePath& root_path) OVERRIDE;
183
184 // Deletes a directory database from the database list in the ObfuscatedFSFU 183 // Deletes a directory database from the database list in the ObfuscatedFSFU
185 // and destroys the database on the disk. 184 // and destroys the database on the disk.
186 bool DestroyDirectoryDatabase(const GURL& origin, FileSystemType type); 185 bool DestroyDirectoryDatabase(const GURL& origin, FileSystemType type);
187 186
188 // Computes a cost for storing a given file in the obfuscated FSFU. 187 // Computes a cost for storing a given file in the obfuscated FSFU.
189 // As the cost of a file is independent of the cost of its parent directories, 188 // As the cost of a file is independent of the cost of its parent directories,
190 // this ignores all but the BaseName of the supplied path. In order to 189 // this ignores all but the BaseName of the supplied path. In order to
191 // compute the cost of adding a multi-segment directory recursively, call this 190 // compute the cost of adding a multi-segment directory recursively, call this
192 // on each path segment and add the results. 191 // on each path segment and add the results.
193 static int64 ComputeFilePathCost(const FilePath& path); 192 static int64 ComputeFilePathCost(const FilePath& path);
(...skipping 19 matching lines...) Expand all
213 // responsible for closing. If you supply a path in source_path, it will be 212 // responsible for closing. If you supply a path in source_path, it will be
214 // used as a source from which to COPY data. 213 // used as a source from which to COPY data.
215 // Caveat: do not supply handle if you're also supplying a data path. It was 214 // Caveat: do not supply handle if you're also supplying a data path. It was
216 // easier not to support this, and no code has needed it so far, so it will 215 // easier not to support this, and no code has needed it so far, so it will
217 // DCHECK and handle will hold base::kInvalidPlatformFileValue. 216 // DCHECK and handle will hold base::kInvalidPlatformFileValue.
218 base::PlatformFileError CreateFile( 217 base::PlatformFileError CreateFile(
219 FileSystemOperationContext* context, 218 FileSystemOperationContext* context,
220 const GURL& origin_url, FileSystemType type, 219 const GURL& origin_url, FileSystemType type,
221 const FilePath& source_path, FileInfo* file_info, 220 const FilePath& source_path, FileInfo* file_info,
222 int file_flags, base::PlatformFile* handle); 221 int file_flags, base::PlatformFile* handle);
222
223 // Given the filesystem's root URL and a virtual path, produces a real, full 223 // Given the filesystem's root URL and a virtual path, produces a real, full
224 // local path to the underlying data file. This does a database lookup, and 224 // local path to the underlying data file. This does a database lookup, and
225 // verifies that the file exists. 225 // verifies that the file exists.
226 FilePath GetLocalPath( 226 FilePath GetLocalPath(
227 const GURL& origin_url, 227 const GURL& origin_url,
228 FileSystemType type, 228 FileSystemType type,
229 const FilePath& virtual_path); 229 const FilePath& virtual_path);
230
230 // This converts from a relative path [as is stored in the FileInfo.data_path 231 // This converts from a relative path [as is stored in the FileInfo.data_path
231 // field] to an absolute local path that can be given to the operating system. 232 // field] to an absolute local path that can be given to the operating system.
232 // It does no checks as to whether the file actually exists; it's pure path 233 // It does no checks as to whether the file actually exists; it's pure path
233 // manipulation. 234 // manipulation.
234 FilePath DataPathToLocalPath( 235 FilePath DataPathToLocalPath(
235 const GURL& origin, FileSystemType type, const FilePath& data_path); 236 const GURL& origin, FileSystemType type, const FilePath& data_path);
237
236 // This does the reverse of DataPathToLocalPath. 238 // This does the reverse of DataPathToLocalPath.
237 FilePath LocalPathToDataPath( 239 FilePath LocalPathToDataPath(
238 const GURL& origin, FileSystemType type, const FilePath& local_path); 240 const GURL& origin, FileSystemType type, const FilePath& local_path);
241
239 // This returns NULL if |create| flag is false and a filesystem does not 242 // This returns NULL if |create| flag is false and a filesystem does not
240 // exist for the given |origin_url| and |type|. 243 // exist for the given |origin_url| and |type|.
241 // For read operations |create| should be false. 244 // For read operations |create| should be false.
242 FileSystemDirectoryDatabase* GetDirectoryDatabase( 245 FileSystemDirectoryDatabase* GetDirectoryDatabase(
243 const GURL& origin_url, FileSystemType type, bool create); 246 const GURL& origin_url, FileSystemType type, bool create);
247
244 // Gets the topmost directory specific to this origin. This will 248 // Gets the topmost directory specific to this origin. This will
245 // contain both the filesystem type subdirectories. 249 // contain both the filesystem type subdirectories.
246 FilePath GetDirectoryForOrigin(const GURL& origin, bool create); 250 FilePath GetDirectoryForOrigin(const GURL& origin, bool create);
251
247 void MarkUsed(); 252 void MarkUsed();
248 void DropDatabases(); 253 void DropDatabases();
249 bool InitOriginDatabase(bool create); 254 bool InitOriginDatabase(bool create);
250 255
251 typedef std::map<std::string, FileSystemDirectoryDatabase*> DirectoryMap; 256 typedef std::map<std::string, FileSystemDirectoryDatabase*> DirectoryMap;
252 DirectoryMap directories_; 257 DirectoryMap directories_;
253 scoped_ptr<FileSystemOriginDatabase> origin_database_; 258 scoped_ptr<FileSystemOriginDatabase> origin_database_;
254 FilePath file_system_directory_; 259 FilePath file_system_directory_;
255 base::OneShotTimer<ObfuscatedFileSystemFileUtil> timer_; 260 base::OneShotTimer<ObfuscatedFileUtil> timer_;
256 scoped_ptr<FileSystemFileUtil> underlying_file_util_;
257 261
258 DISALLOW_COPY_AND_ASSIGN(ObfuscatedFileSystemFileUtil); 262 DISALLOW_COPY_AND_ASSIGN(ObfuscatedFileUtil);
259 }; 263 };
260 264
261 } // namespace fileapi 265 } // namespace fileapi
262 266
263 #endif // WEBKIT_FILEAPI_OBFUSCATED_FILE_SYSTEM_FILE_UTIL_H_ 267 #endif // WEBKIT_FILEAPI_OBFUSCATED_FILE_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698