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

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

Issue 10870040: Rename FileSystemOperationInterface to FileSystemOperation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixing Created 8 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
« no previous file with comments | « webkit/fileapi/file_system_operation.h ('k') | webkit/fileapi/file_system_url_request_job.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_INTERFACE_H_
6 #define WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_INTERFACE_H_
7
8 #include <vector>
9
10 #include "base/file_util_proxy.h"
11 #include "base/platform_file.h"
12 #include "base/process.h"
13 #include "webkit/blob/shareable_file_reference.h"
14
15 namespace base {
16 class Time;
17 } // namespace base
18
19 namespace net {
20 class URLRequest;
21 class URLRequestContext;
22 } // namespace net
23
24 namespace webkit_blob {
25 class ShareableFileReference;
26 }
27
28 class GURL;
29
30 namespace fileapi {
31
32 class FileSystemURL;
33 class LocalFileSystemOperation;
34
35 // The interface class for FileSystemOperation implementations.
36 //
37 // This interface defines file system operations required to implement
38 // "File API: Directories and System"
39 // http://www.w3.org/TR/file-system-api/
40 //
41 // DESIGN NOTES
42 //
43 // This class is designed to
44 //
45 // 1) Serve one-time file system operation per instance. Only one
46 // method(CreateFile, CreateDirectory, Copy, Move, DirectoryExists,
47 // GetMetadata, ReadDirectory and Remove) may be called during the
48 // lifetime of this object and it should be called no more than once.
49 //
50 // 2) Be self-destructed, or get deleted via base::Owned() after the
51 // operation finishes and completion callback is called.
52 //
53 // 3) Deliver the results of operations to the client via the callback function
54 // passed as the last parameter of the method.
55 //
56 class FileSystemOperationInterface {
57 public:
58 virtual ~FileSystemOperationInterface() {}
59
60 // Used for CreateFile(), etc. |result| is the return code of the operation.
61 typedef base::Callback<void(base::PlatformFileError result)> StatusCallback;
62
63 // Used for GetMetadata(). |result| is the return code of the operation,
64 // |file_info| is the obtained file info, and |platform_path| is the path
65 // of the file.
66 typedef base::Callback<
67 void(base::PlatformFileError result,
68 const base::PlatformFileInfo& file_info,
69 const FilePath& platform_path)> GetMetadataCallback;
70
71 // Used for OpenFile(). |result| is the return code of the operation.
72 typedef base::Callback<
73 void(base::PlatformFileError result,
74 base::PlatformFile file,
75 base::ProcessHandle peer_handle)> OpenFileCallback;
76
77 // Used for ReadDirectoryCallback.
78 typedef std::vector<base::FileUtilProxy::Entry> FileEntryList;
79
80 // Used for ReadDirectory(). |result| is the return code of the operation,
81 // |file_list| is the list of files read, and |has_more| is true if some files
82 // are yet to be read.
83 typedef base::Callback<
84 void(base::PlatformFileError result,
85 const FileEntryList& file_list,
86 bool has_more)> ReadDirectoryCallback;
87
88 // Used for CreateSnapshotFile(). (Please see the comment at
89 // CreateSnapshotFile() below for how the method is called)
90 // |result| is the return code of the operation.
91 // |file_info| is the metadata of the snapshot file created.
92 // |platform_path| is the path to the snapshot file created.
93 //
94 // The snapshot file could simply be of the local file pointed by the given
95 // filesystem URL in local filesystem cases; remote filesystems
96 // may want to download the file into a temporary snapshot file and then
97 // return the metadata of the temporary file.
98 //
99 // |file_ref| is used to manage the lifetime of the returned
100 // snapshot file. It can be set to let the chromium backend take
101 // care of the life time of the snapshot file. Otherwise (if the returned
102 // file does not require any handling) the implementation can just
103 // return NULL. In a more complex case, the implementaiton can manage
104 // the lifetime of the snapshot file on its own (e.g. by its cache system)
105 // but also can be notified via the reference when the file becomes no
106 // longer necessary in the javascript world.
107 // Please see the comment for ShareableFileReference for details.
108 //
109 typedef base::Callback<
110 void(base::PlatformFileError result,
111 const base::PlatformFileInfo& file_info,
112 const FilePath& platform_path,
113 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref)>
114 SnapshotFileCallback;
115
116 // Used for Write().
117 typedef base::Callback<void(base::PlatformFileError result,
118 int64 bytes,
119 bool complete)> WriteCallback;
120
121 // Creates a file at |path|. If |exclusive| is true, an error is raised
122 // in case a file is already present at the URL.
123 virtual void CreateFile(const FileSystemURL& path,
124 bool exclusive,
125 const StatusCallback& callback) = 0;
126
127 // Creates a directory at |path|. If |exclusive| is true, an error is
128 // raised in case a directory is already present at the URL. If
129 // |recursive| is true, create parent directories as needed just like
130 // mkdir -p does.
131 virtual void CreateDirectory(const FileSystemURL& path,
132 bool exclusive,
133 bool recursive,
134 const StatusCallback& callback) = 0;
135
136 // Copes a file or directory from |src_path| to |dest_path|. If
137 // |src_path| is a directory, the contents of |src_path| are copied to
138 // |dest_path| recursively. A new file or directory is created at
139 // |dest_path| as needed.
140 virtual void Copy(const FileSystemURL& src_path,
141 const FileSystemURL& dest_path,
142 const StatusCallback& callback) = 0;
143
144 // Moves a file or directory from |src_path| to |dest_path|. A new file
145 // or directory is created at |dest_path| as needed.
146 virtual void Move(const FileSystemURL& src_path,
147 const FileSystemURL& dest_path,
148 const StatusCallback& callback) = 0;
149
150 // Checks if a directory is present at |path|.
151 virtual void DirectoryExists(const FileSystemURL& path,
152 const StatusCallback& callback) = 0;
153
154 // Checks if a file is present at |path|.
155 virtual void FileExists(const FileSystemURL& path,
156 const StatusCallback& callback) = 0;
157
158 // Gets the metadata of a file or directory at |path|.
159 virtual void GetMetadata(const FileSystemURL& path,
160 const GetMetadataCallback& callback) = 0;
161
162 // Reads contents of a directory at |path|.
163 virtual void ReadDirectory(const FileSystemURL& path,
164 const ReadDirectoryCallback& callback) = 0;
165
166 // Removes a file or directory at |path|. If |recursive| is true, remove
167 // all files and directories under the directory at |path| recursively.
168 virtual void Remove(const FileSystemURL& path, bool recursive,
169 const StatusCallback& callback) = 0;
170
171 // Writes contents of |blob_url| to |path| at |offset|.
172 // |url_request_context| is used to read contents in |blob_url|.
173 virtual void Write(const net::URLRequestContext* url_request_context,
174 const FileSystemURL& path,
175 const GURL& blob_url,
176 int64 offset,
177 const WriteCallback& callback) = 0;
178
179 // Truncates a file at |path| to |length|. If |length| is larger than
180 // the original file size, the file will be extended, and the extended
181 // part is filled with null bytes.
182 virtual void Truncate(const FileSystemURL& path, int64 length,
183 const StatusCallback& callback) = 0;
184
185 // Tries to cancel the current operation [we support cancelling write or
186 // truncate only]. Reports failure for the current operation, then reports
187 // success for the cancel operation itself via the |cancel_dispatcher|.
188 //
189 // E.g. a typical cancel implementation would look like:
190 //
191 // virtual void SomeOperationImpl::Cancel(
192 // const StatusCallback& cancel_callback) {
193 // // Abort the current inflight operation first.
194 // ...
195 //
196 // // Dispatch ABORT error for the current operation by invoking
197 // // the callback function for the ongoing operation,
198 // operation_callback.Run(base::PLATFORM_FILE_ERROR_ABORT, ...);
199 //
200 // // Dispatch 'success' for the cancel (or dispatch appropriate
201 // // error code with DidFail() if the cancel has somehow failed).
202 // cancel_callback.Run(base::PLATFORM_FILE_OK);
203 // }
204 //
205 // Note that, for reporting failure, the callback function passed to a
206 // cancellable operations are kept around with the operation instance
207 // (as |operation_callback_| in the code example).
208 virtual void Cancel(const StatusCallback& cancel_callback) = 0;
209
210 // Modifies timestamps of a file or directory at |path| with
211 // |last_access_time| and |last_modified_time|. The function DOES NOT
212 // create a file unlike 'touch' command on Linux.
213 //
214 // This function is used only by Pepper as of writing.
215 virtual void TouchFile(const FileSystemURL& path,
216 const base::Time& last_access_time,
217 const base::Time& last_modified_time,
218 const StatusCallback& callback) = 0;
219
220 // Opens a file at |path| with |file_flags|, where flags are OR'ed
221 // values of base::PlatformFileFlags.
222 //
223 // |peer_handle| is the process handle of a pepper plugin process, which
224 // is necessary for underlying IPC calls with Pepper plugins.
225 //
226 // This function is used only by Pepper as of writing.
227 virtual void OpenFile(const FileSystemURL& path,
228 int file_flags,
229 base::ProcessHandle peer_handle,
230 const OpenFileCallback& callback) = 0;
231
232 // Notifies a file at |path| opened by OpenFile is closed in plugin process.
233 // File system will run some cleanup task such as uploading the modified file
234 // content to a remote storage.
235 //
236 // This function is used only by Pepper as of writing.
237 virtual void NotifyCloseFile(const FileSystemURL& path) = 0;
238
239 // For downcasting to FileSystemOperation.
240 // TODO(kinuko): this hack should go away once appropriate upload-stream
241 // handling based on element types is supported.
242 virtual LocalFileSystemOperation* AsLocalFileSystemOperation() = 0;
243
244 // Creates a local snapshot file for a given |path| and returns the
245 // metadata and platform path of the snapshot file via |callback|.
246 // In local filesystem cases the implementation may simply return
247 // the metadata of the file itself (as well as GetMetadata does),
248 // while in remote filesystem case the backend may want to download the file
249 // into a temporary snapshot file and return the metadata of the
250 // temporary file. Or if the implementaiton already has the local cache
251 // data for |path| it can simply return the path to the cache.
252 virtual void CreateSnapshotFile(const FileSystemURL& path,
253 const SnapshotFileCallback& callback) = 0;
254
255 protected:
256 // Used only for internal assertions.
257 enum OperationType {
258 kOperationNone,
259 kOperationCreateFile,
260 kOperationCreateDirectory,
261 kOperationCreateSnapshotFile,
262 kOperationCopy,
263 kOperationMove,
264 kOperationDirectoryExists,
265 kOperationFileExists,
266 kOperationGetMetadata,
267 kOperationReadDirectory,
268 kOperationRemove,
269 kOperationWrite,
270 kOperationTruncate,
271 kOperationTouchFile,
272 kOperationOpenFile,
273 kOperationCloseFile,
274 kOperationGetLocalPath,
275 kOperationCancel,
276 };
277 };
278
279 } // namespace fileapi
280
281 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_INTERFACE_H_
OLDNEW
« no previous file with comments | « webkit/fileapi/file_system_operation.h ('k') | webkit/fileapi/file_system_url_request_job.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698