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

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

Issue 6286038: Add initial code to do filename munging in the FileSystem.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 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 BASE_FILE_UTIL_PROXY_H_ 5 #ifndef WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_PROXY_H_
6 #define BASE_FILE_UTIL_PROXY_H_ 6 #define WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_PROXY_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/file_path.h" 11 #include "base/file_path.h"
12 #include "base/file_util.h" 12 #include "base/file_util_proxy.h"
13 #include "base/platform_file.h" 13 #include "base/platform_file.h"
14 #include "base/ref_counted.h" 14 #include "base/ref_counted.h"
15 #include "base/tracked_objects.h" 15 #include "base/tracked_objects.h"
16 16
17 namespace base { 17 namespace base {
18
19 class MessageLoopProxy; 18 class MessageLoopProxy;
20 class Time; 19 class Time;
20 }
21 21
22 // This class provides asynchronous access to common file routines. 22 namespace fileapi {
23 class FileUtilProxy { 23
24 class FileSystemOperationContext;
25
26 using base::MessageLoopProxy;
27 using base::PlatformFile;
28
29 // This class provides asynchronous access to common file routines for the
30 // FileSystem API.
31 class FileSystemFileUtilProxy {
24 public: 32 public:
25 // Holds metadata for file or directory entry. Used by ReadDirectoryCallback. 33 typedef base::FileUtilProxy::Entry Entry;
26 struct Entry { 34 typedef base::FileUtilProxy::StatusCallback StatusCallback;
27 FilePath::StringType name; 35 typedef base::FileUtilProxy::CreateOrOpenCallback CreateOrOpenCallback;
28 bool is_directory; 36 typedef base::FileUtilProxy::EnsureFileExistsCallback
29 }; 37 EnsureFileExistsCallback;
30 38 typedef base::FileUtilProxy::GetFileInfoCallback GetFileInfoCallback;
31 // This callback is used by methods that report only an error code. It is 39 typedef base::FileUtilProxy::ReadDirectoryCallback ReadDirectoryCallback;
32 // valid to pass NULL as the callback parameter to any function that takes a
33 // StatusCallback, in which case the operation will complete silently.
34 typedef Callback1<PlatformFileError /* error code */>::Type StatusCallback;
35
36 typedef Callback3<PlatformFileError /* error code */,
37 PassPlatformFile,
38 bool /* created */>::Type CreateOrOpenCallback;
39 typedef Callback3<PlatformFileError /* error code */,
40 PassPlatformFile,
41 FilePath>::Type CreateTemporaryCallback;
42 typedef Callback2<PlatformFileError /* error code */,
43 bool /* created */>::Type EnsureFileExistsCallback;
44 typedef Callback2<PlatformFileError /* error code */,
45 const PlatformFileInfo& /* file_info */
46 >::Type GetFileInfoCallback;
47 typedef Callback2<PlatformFileError /* error code */,
48 const std::vector<Entry>&>::Type ReadDirectoryCallback;
49 typedef Callback3<PlatformFileError /* error code */,
50 const char* /* data */,
51 int /* bytes read/written */>::Type ReadCallback;
52 typedef Callback2<PlatformFileError /* error code */,
53 int /* bytes written */>::Type WriteCallback;
54 40
55 // Creates or opens a file with the given flags. It is invalid to pass NULL 41 // Creates or opens a file with the given flags. It is invalid to pass NULL
56 // for the callback. 42 // for the callback.
57 // If PLATFORM_FILE_CREATE is set in |file_flags| it always tries to create 43 // If PLATFORM_FILE_CREATE is set in |file_flags| it always tries to create
58 // a new file at the given |file_path| and calls back with 44 // a new file at the given |file_path| and calls back with
59 // PLATFORM_FILE_ERROR_FILE_EXISTS if the |file_path| already exists. 45 // PLATFORM_FILE_ERROR_FILE_EXISTS if the |file_path| already exists.
60 static bool CreateOrOpen(scoped_refptr<MessageLoopProxy> message_loop_proxy, 46 static bool CreateOrOpen(FileSystemOperationContext* context,
47 scoped_refptr<MessageLoopProxy> message_loop_proxy,
61 const FilePath& file_path, 48 const FilePath& file_path,
62 int file_flags, 49 int file_flags,
63 CreateOrOpenCallback* callback); 50 CreateOrOpenCallback* callback);
64 51
65 // Creates a temporary file for writing. The path and an open file handle
66 // are returned. It is invalid to pass NULL for the callback.
67 static bool CreateTemporary(
68 scoped_refptr<MessageLoopProxy> message_loop_proxy,
69 CreateTemporaryCallback* callback);
70
71 // Close the given file handle. 52 // Close the given file handle.
72 static bool Close(scoped_refptr<MessageLoopProxy> message_loop_proxy, 53 static bool Close(FileSystemOperationContext* context,
54 scoped_refptr<MessageLoopProxy> message_loop_proxy,
73 PlatformFile, 55 PlatformFile,
74 StatusCallback* callback); 56 StatusCallback* callback);
75 57
76 // Ensures that the given |file_path| exist. This creates a empty new file 58 // Ensures that the given |file_path| exist. This creates a empty new file
77 // at |file_path| if the |file_path| does not exist. 59 // at |file_path| if the |file_path| does not exist.
78 // If a new file han not existed and is created at the |file_path|, 60 // If a new file han not existed and is created at the |file_path|,
79 // |created| of the callback argument is set true and |error code| 61 // |created| of the callback argument is set true and |error code|
80 // is set PLATFORM_FILE_OK. 62 // is set PLATFORM_FILE_OK.
81 // If the file already exists, |created| is set false and |error code| 63 // If the file already exists, |created| is set false and |error code|
82 // is set PLATFORM_FILE_OK. 64 // is set PLATFORM_FILE_OK.
83 // If the file hasn't existed but it couldn't be created for some other 65 // If the file hasn't existed but it couldn't be created for some other
84 // reasons, |created| is set false and |error code| indicates the error. 66 // reasons, |created| is set false and |error code| indicates the error.
85 static bool EnsureFileExists( 67 static bool EnsureFileExists(
68 FileSystemOperationContext* context,
86 scoped_refptr<MessageLoopProxy> message_loop_proxy, 69 scoped_refptr<MessageLoopProxy> message_loop_proxy,
87 const FilePath& file_path, 70 const FilePath& file_path,
88 EnsureFileExistsCallback* callback); 71 EnsureFileExistsCallback* callback);
89 72
90 // Retrieves the information about a file. It is invalid to pass NULL for the 73 // Retrieves the information about a file. It is invalid to pass NULL for the
91 // callback. 74 // callback.
92 static bool GetFileInfo( 75 static bool GetFileInfo(
76 FileSystemOperationContext* context,
93 scoped_refptr<MessageLoopProxy> message_loop_proxy, 77 scoped_refptr<MessageLoopProxy> message_loop_proxy,
94 const FilePath& file_path, 78 const FilePath& file_path,
95 GetFileInfoCallback* callback); 79 GetFileInfoCallback* callback);
96 80
97 static bool GetFileInfoFromPlatformFile( 81 static bool ReadDirectory(FileSystemOperationContext* context,
98 scoped_refptr<MessageLoopProxy> message_loop_proxy, 82 scoped_refptr<MessageLoopProxy> message_loop_proxy,
99 PlatformFile file,
100 GetFileInfoCallback* callback);
101
102 static bool ReadDirectory(scoped_refptr<MessageLoopProxy> message_loop_proxy,
103 const FilePath& file_path, 83 const FilePath& file_path,
104 ReadDirectoryCallback* callback); 84 ReadDirectoryCallback* callback);
105 85
106 // Creates directory at given path. It's an error to create 86 // Creates directory at given path. It's an error to create
107 // if |exclusive| is true and dir already exists. 87 // if |exclusive| is true and dir already exists.
108 static bool CreateDirectory( 88 static bool CreateDirectory(
89 FileSystemOperationContext* context,
109 scoped_refptr<MessageLoopProxy> message_loop_proxy, 90 scoped_refptr<MessageLoopProxy> message_loop_proxy,
110 const FilePath& file_path, 91 const FilePath& file_path,
111 bool exclusive, 92 bool exclusive,
112 bool recursive,
113 StatusCallback* callback); 93 StatusCallback* callback);
114 94
115 // Copies a file or a directory from |src_file_path| to |dest_file_path| 95 // Copies a file or a directory from |src_file_path| to |dest_file_path|
116 // Error cases: 96 // Error cases:
117 // If destination file doesn't exist or destination's parent 97 // If destination file doesn't exist or destination's parent
118 // doesn't exists. 98 // doesn't exists.
119 // If source dir exists but destination path is an existing file. 99 // If source dir exists but destination path is an existing file.
120 // If source file exists but destination path is an existing directory. 100 // If source file exists but destination path is an existing directory.
121 // If source is a parent of destination. 101 // If source is a parent of destination.
122 // If source doesn't exists. 102 // If source doesn't exists.
123 static bool Copy(scoped_refptr<MessageLoopProxy> message_loop_proxy, 103 static bool Copy(FileSystemOperationContext* context,
104 scoped_refptr<MessageLoopProxy> message_loop_proxy,
124 const FilePath& src_file_path, 105 const FilePath& src_file_path,
125 const FilePath& dest_file_path, 106 const FilePath& dest_file_path,
126 StatusCallback* callback); 107 StatusCallback* callback);
127 108
128 // Moves a file or a directory from src_file_path to dest_file_path. 109 // Moves a file or a directory from src_file_path to dest_file_path.
129 // Error cases are similar to Copy method's error cases. 110 // Error cases are similar to Copy method's error cases.
130 static bool Move( 111 static bool Move(
112 FileSystemOperationContext* context,
131 scoped_refptr<MessageLoopProxy> message_loop_proxy, 113 scoped_refptr<MessageLoopProxy> message_loop_proxy,
132 const FilePath& src_file_path, 114 const FilePath& src_file_path,
133 const FilePath& dest_file_path, 115 const FilePath& dest_file_path,
134 StatusCallback* callback); 116 StatusCallback* callback);
135 117
136 // Deletes a file or a directory. 118 // Deletes a file or a directory.
137 // It is an error to delete a non-empty directory with recursive=false. 119 // It is an error to delete a non-empty directory with recursive=false.
138 static bool Delete(scoped_refptr<MessageLoopProxy> message_loop_proxy, 120 static bool Delete(FileSystemOperationContext* context,
121 scoped_refptr<MessageLoopProxy> message_loop_proxy,
139 const FilePath& file_path, 122 const FilePath& file_path,
140 bool recursive, 123 bool recursive,
141 StatusCallback* callback); 124 StatusCallback* callback);
142 125
143 // Deletes a directory and all of its contents. 126 // Touches a file. The callback can be NULL.
144 static bool RecursiveDelete( 127 static bool Touch(
128 FileSystemOperationContext* context,
145 scoped_refptr<MessageLoopProxy> message_loop_proxy, 129 scoped_refptr<MessageLoopProxy> message_loop_proxy,
146 const FilePath& file_path, 130 const FilePath& file_path,
147 StatusCallback* callback); 131 const base::Time& last_access_time,
148 132 const base::Time& last_modified_time,
149 // Reads from a file. On success, the file pointer is moved to position
150 // |offset + bytes_to_read| in the file. The callback can be NULL.
151 static bool Read(
152 scoped_refptr<MessageLoopProxy> message_loop_proxy,
153 PlatformFile file,
154 int64 offset,
155 int bytes_to_read,
156 ReadCallback* callback);
157
158 // Writes to a file. If |offset| is greater than the length of the file,
159 // |false| is returned. On success, the file pointer is moved to position
160 // |offset + bytes_to_write| in the file. The callback can be NULL.
161 static bool Write(
162 scoped_refptr<MessageLoopProxy> message_loop_proxy,
163 PlatformFile file,
164 int64 offset,
165 const char* buffer,
166 int bytes_to_write,
167 WriteCallback* callback);
168
169 // Touches a file. The callback can be NULL.
170 static bool Touch(
171 scoped_refptr<MessageLoopProxy> message_loop_proxy,
172 PlatformFile file,
173 const Time& last_access_time,
174 const Time& last_modified_time,
175 StatusCallback* callback);
176
177 // Touches a file. The callback can be NULL.
178 static bool Touch(
179 scoped_refptr<MessageLoopProxy> message_loop_proxy,
180 const FilePath& file_path,
181 const Time& last_access_time,
182 const Time& last_modified_time,
183 StatusCallback* callback); 133 StatusCallback* callback);
184 134
185 // Truncates a file to the given length. If |length| is greater than the 135 // Truncates a file to the given length. If |length| is greater than the
186 // current length of the file, the file will be extended with zeroes. 136 // current length of the file, the file will be extended with zeroes.
187 // The callback can be NULL. 137 // The callback can be NULL.
188 static bool Truncate( 138 static bool Truncate(
189 scoped_refptr<MessageLoopProxy> message_loop_proxy, 139 FileSystemOperationContext* context,
190 PlatformFile file,
191 int64 length,
192 StatusCallback* callback);
193
194 // Truncates a file to the given length. If |length| is greater than the
195 // current length of the file, the file will be extended with zeroes.
196 // The callback can be NULL.
197 static bool Truncate(
198 scoped_refptr<MessageLoopProxy> message_loop_proxy, 140 scoped_refptr<MessageLoopProxy> message_loop_proxy,
199 const FilePath& path, 141 const FilePath& path,
200 int64 length, 142 int64 length,
201 StatusCallback* callback); 143 StatusCallback* callback);
202 144
203 // Flushes a file. The callback can be NULL.
204 static bool Flush(
205 scoped_refptr<MessageLoopProxy> message_loop_proxy,
206 PlatformFile file,
207 StatusCallback* callback);
208
209 private: 145 private:
210 DISALLOW_IMPLICIT_CONSTRUCTORS(FileUtilProxy); 146 DISALLOW_IMPLICIT_CONSTRUCTORS(FileSystemFileUtilProxy);
211 }; 147 };
212 148
213 } // namespace base 149 } // namespace fileapi
214 150
215 #endif // BASE_FILE_UTIL_PROXY_H_ 151 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_PROXY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698