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

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

Issue 9562005: Cleanup: Updating FileSystemFileUtil comments (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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
« no previous file with comments | « no previous file | webkit/fileapi/file_system_file_util_proxy.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_FILE_SYSTEM_FILE_UTIL_H_ 5 #ifndef WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_H_
6 #define WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_H_ 6 #define WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_H_
7 7
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/file_util_proxy.h" 9 #include "base/file_util_proxy.h"
10 #include "base/platform_file.h" 10 #include "base/platform_file.h"
11 #include "webkit/fileapi/file_system_path.h" 11 #include "webkit/fileapi/file_system_path.h"
12 12
13 namespace base { 13 namespace base {
14 class Time; 14 class Time;
15 } 15 }
16 16
17 namespace fileapi { 17 namespace fileapi {
18 18
19 using base::PlatformFile; 19 using base::PlatformFile;
20 using base::PlatformFileError; 20 using base::PlatformFileError;
21 class FileSystemOperationContext; 21 class FileSystemOperationContext;
22 22
23 // A large part of this implementation is taken from base::FileUtilProxy. 23 // A file utility interface that provides basic file utility methods for
24 // FileSystem API.
24 // 25 //
25 // The default implementations of the virtual methods below (*1) assume the 26 // TODO(kinuko): Move all the default implementation out of this class
26 // given paths are native ones for the host platform. The subclasses that 27 // and make this class pure abstract class.
27 // perform local path translation/obfuscation must override them.
28 // (*1) All virtual methods which receive FilePath as their arguments:
29 // CreateOrOpen, EnsureFileExists, GetLocalFilePath, GetFileInfo,
30 // ReadDirectory, CreateDirectory, CopyOrMoveFile, DeleteFile,
31 // DeleteSingleDirectory, Touch, Truncate, PathExists, DirectoryExists,
32 // IsDirectoryEmpty and CreateFileEnumerator.
33 //
34 // The methods below (*2) assume the given paths may not be native ones for the
35 // host platform. The subclasses should not override them. They provide basic
36 // meta logic by using other virtual methods.
37 // (*2) All non-virtual methods: Copy, Move, Delete, DeleteDirectoryRecursive,
38 // PerformCommonCheckAndPreparationForMoveAndCopy and CopyOrMoveDirectory.
39 class FileSystemFileUtil { 28 class FileSystemFileUtil {
40 public: 29 public:
41 // It will be implemented by each subclass such as FileSystemFileEnumerator. 30 // It will be implemented by each subclass such as FileSystemFileEnumerator.
42 class AbstractFileEnumerator { 31 class AbstractFileEnumerator {
43 public: 32 public:
44 virtual ~AbstractFileEnumerator() {} 33 virtual ~AbstractFileEnumerator() {}
45 34
46 // Returns an empty string if there are no more results. 35 // Returns an empty string if there are no more results.
47 virtual FilePath Next() = 0; 36 virtual FilePath Next() = 0;
48 37
(...skipping 11 matching lines...) Expand all
60 49
61 // Deletes a file or a directory. 50 // Deletes a file or a directory.
62 // It is an error to delete a non-empty directory with recursive=false. 51 // It is an error to delete a non-empty directory with recursive=false.
63 // 52 //
64 // This method calls one of the following methods depending on whether the 53 // This method calls one of the following methods depending on whether the
65 // target is a directory or not, and whether the |recursive| flag is given or 54 // target is a directory or not, and whether the |recursive| flag is given or
66 // not. 55 // not.
67 // - (virtual) DeleteFile, 56 // - (virtual) DeleteFile,
68 // - (virtual) DeleteSingleDirectory or 57 // - (virtual) DeleteSingleDirectory or
69 // - (non-virtual) DeleteDirectoryRecursive which calls two methods above. 58 // - (non-virtual) DeleteDirectoryRecursive which calls two methods above.
59 //
60 // TODO(kinuko): Move this implementation outside FileSystemFileUtil.
70 PlatformFileError Delete( 61 PlatformFileError Delete(
71 FileSystemOperationContext* context, 62 FileSystemOperationContext* context,
72 const FileSystemPath& path, 63 const FileSystemPath& path,
73 bool recursive); 64 bool recursive);
74 65
75 // Creates or opens a file with the given flags. 66 // Creates or opens a file with the given flags.
76 // If PLATFORM_FILE_CREATE is set in |file_flags| it always tries to create 67 // If PLATFORM_FILE_CREATE is set in |file_flags| it always tries to create
77 // a new file at the given |path| and calls back with 68 // a new file at the given |path| and calls back with
78 // PLATFORM_FILE_ERROR_FILE_EXISTS if the |path| already exists. 69 // PLATFORM_FILE_ERROR_FILE_EXISTS if the |path| already exists.
79 virtual PlatformFileError CreateOrOpen( 70 virtual PlatformFileError CreateOrOpen(
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 const FileSystemPath& root_path); 125 const FileSystemPath& root_path);
135 126
136 // Maps |virtual_path| given |context| into |local_file_path| which represents 127 // Maps |virtual_path| given |context| into |local_file_path| which represents
137 // physical file location on the host OS. 128 // physical file location on the host OS.
138 // This may not always make sense for all subclasses. 129 // This may not always make sense for all subclasses.
139 virtual PlatformFileError GetLocalFilePath( 130 virtual PlatformFileError GetLocalFilePath(
140 FileSystemOperationContext* context, 131 FileSystemOperationContext* context,
141 const FileSystemPath& file_system_path, 132 const FileSystemPath& file_system_path,
142 FilePath* local_file_path); 133 FilePath* local_file_path);
143 134
144 // Touches a file. 135 // Updates the file metadata information. Unlike posix's touch, it does
145 // If the file doesn't exist, this fails with PLATFORM_FILE_ERROR_NOT_FOUND. 136 // not create a file even if |path| does not exist, but instead fails
137 // with PLATFORM_FILE_ERROR_NOT_FOUND.
146 virtual PlatformFileError Touch( 138 virtual PlatformFileError Touch(
147 FileSystemOperationContext* context, 139 FileSystemOperationContext* context,
148 const FileSystemPath& path, 140 const FileSystemPath& path,
149 const base::Time& last_access_time, 141 const base::Time& last_access_time,
150 const base::Time& last_modified_time); 142 const base::Time& last_modified_time);
151 143
152 // Truncates a file to the given length. If |length| is greater than the 144 // Truncates a file to the given length. If |length| is greater than the
153 // current length of the file, the file will be extended with zeroes. 145 // current length of the file, the file will be extended with zeroes.
154 virtual PlatformFileError Truncate( 146 virtual PlatformFileError Truncate(
155 FileSystemOperationContext* context, 147 FileSystemOperationContext* context,
156 const FileSystemPath& path, 148 const FileSystemPath& path,
157 int64 length); 149 int64 length);
158 150
151 // Returns true if a given |path| exists.
159 virtual bool PathExists( 152 virtual bool PathExists(
160 FileSystemOperationContext* context, 153 FileSystemOperationContext* context,
161 const FileSystemPath& path); 154 const FileSystemPath& path);
162 155
156 // Returns true if a given |path| exists and is a directory.
163 virtual bool DirectoryExists( 157 virtual bool DirectoryExists(
164 FileSystemOperationContext* context, 158 FileSystemOperationContext* context,
165 const FileSystemPath& path); 159 const FileSystemPath& path);
166 160
161 // Returns true if a given |path| is an empty directory.
167 virtual bool IsDirectoryEmpty( 162 virtual bool IsDirectoryEmpty(
168 FileSystemOperationContext* context, 163 FileSystemOperationContext* context,
169 const FileSystemPath& path); 164 const FileSystemPath& path);
170 165
166 // Copies or moves a single file from |src_path| to |dest_path|.
171 virtual PlatformFileError CopyOrMoveFile( 167 virtual PlatformFileError CopyOrMoveFile(
172 FileSystemOperationContext* context, 168 FileSystemOperationContext* context,
173 const FileSystemPath& src_path, 169 const FileSystemPath& src_path,
174 const FileSystemPath& dest_path, 170 const FileSystemPath& dest_path,
175 bool copy); 171 bool copy);
176 172
177 // Copies in a single file from a different filesystem. The 173 // Copies in a single file from a different filesystem. The
178 // underlying_src_path is a local path which can be handled by the 174 // |underlying_src_path| is a local path which can be handled by the
179 // underlying filesystem. 175 // underlying filesystem.
180 virtual PlatformFileError CopyInForeignFile( 176 virtual PlatformFileError CopyInForeignFile(
181 FileSystemOperationContext* context, 177 FileSystemOperationContext* context,
182 const FileSystemPath& underlying_src_path, 178 const FileSystemPath& underlying_src_path,
183 const FileSystemPath& dest_path); 179 const FileSystemPath& dest_path);
184 180
185 // Deletes a single file. 181 // Deletes a single file.
186 // It assumes the given path points a file. 182 // It assumes the given path points a file.
187 //
188 // This method is called from DeleteDirectoryRecursive and Delete (both are
189 // non-virtual).
190 virtual PlatformFileError DeleteFile( 183 virtual PlatformFileError DeleteFile(
191 FileSystemOperationContext* context, 184 FileSystemOperationContext* context,
192 const FileSystemPath& path); 185 const FileSystemPath& path);
193 186
194 // Deletes a single empty directory. 187 // Deletes a single empty directory.
195 // It assumes the given path points an empty directory. 188 // It assumes the given path points an empty directory.
196 //
197 // This method is called from DeleteDirectoryRecursive and Delete (both are
198 // non-virtual).
199 virtual PlatformFileError DeleteSingleDirectory( 189 virtual PlatformFileError DeleteSingleDirectory(
200 FileSystemOperationContext* context, 190 FileSystemOperationContext* context,
201 const FileSystemPath& path); 191 const FileSystemPath& path);
202 192
203 protected: 193 protected:
204 FileSystemFileUtil(); 194 FileSystemFileUtil();
205 explicit FileSystemFileUtil(FileSystemFileUtil* underlying_file_util); 195 explicit FileSystemFileUtil(FileSystemFileUtil* underlying_file_util);
206 196
207 // Deletes a directory and all entries under the directory. 197 // Deletes a directory and all entries under the directory.
208 // 198 //
209 // This method is called from Delete. It internally calls two following 199 // This method is called from Delete. It internally calls two following
210 // virtual methods, 200 // virtual methods,
211 // - (virtual) DeleteFile to delete files, and 201 // - (virtual) DeleteFile to delete files, and
212 // - (virtual) DeleteSingleDirectory to delete empty directories after all 202 // - (virtual) DeleteSingleDirectory to delete empty directories after all
213 // the files are deleted. 203 // the files are deleted.
204 //
205 // TODO(kinuko): Move this method out of this class.
214 PlatformFileError DeleteDirectoryRecursive( 206 PlatformFileError DeleteDirectoryRecursive(
215 FileSystemOperationContext* context, 207 FileSystemOperationContext* context,
216 const FileSystemPath& path); 208 const FileSystemPath& path);
217 209
210 // TODO(kinuko): We should stop FileUtil layering.
218 FileSystemFileUtil* underlying_file_util() const { 211 FileSystemFileUtil* underlying_file_util() const {
219 return underlying_file_util_.get(); 212 return underlying_file_util_.get();
220 } 213 }
221 214
222 private: 215 private:
223 scoped_ptr<FileSystemFileUtil> underlying_file_util_; 216 scoped_ptr<FileSystemFileUtil> underlying_file_util_;
224 217
225 DISALLOW_COPY_AND_ASSIGN(FileSystemFileUtil); 218 DISALLOW_COPY_AND_ASSIGN(FileSystemFileUtil);
226 }; 219 };
227 220
228 } // namespace fileapi 221 } // namespace fileapi
229 222
230 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_H_ 223 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_H_
OLDNEW
« no previous file with comments | « no previous file | webkit/fileapi/file_system_file_util_proxy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698