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

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

Issue 9380040: Revert 121620 - Refactor FileSystemOperation to take callback for each method. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 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) 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_OPERATION_H_ 5 #ifndef WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_H_
6 #define WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_H_ 6 #define WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 21 matching lines...) Expand all
32 32
33 namespace net { 33 namespace net {
34 class URLRequest; 34 class URLRequest;
35 class URLRequestContext; 35 class URLRequestContext;
36 } // namespace net 36 } // namespace net
37 37
38 class GURL; 38 class GURL;
39 39
40 namespace fileapi { 40 namespace fileapi {
41 41
42 class FileSystemCallbackDispatcher;
42 class FileSystemContext; 43 class FileSystemContext;
43 class FileWriterDelegate; 44 class FileWriterDelegate;
44 class FileSystemOperationTest; 45 class FileSystemOperationTest;
45 46
46 // FileSystemOperation implementation for local file systems. 47 // FileSystemOperation implementation for local file systems.
47 class FileSystemOperation : public FileSystemOperationInterface { 48 class FileSystemOperation : public FileSystemOperationInterface {
48 public: 49 public:
49 virtual ~FileSystemOperation(); 50 virtual ~FileSystemOperation();
50 51
51 // FileSystemOperation overrides. 52 // FileSystemOperation overrides.
52 virtual void CreateFile(const GURL& path, 53 virtual void CreateFile(const GURL& path,
53 bool exclusive, 54 bool exclusive) OVERRIDE;
54 const StatusCallback& callback) OVERRIDE;
55 virtual void CreateDirectory(const GURL& path, 55 virtual void CreateDirectory(const GURL& path,
56 bool exclusive, 56 bool exclusive,
57 bool recursive, 57 bool recursive) OVERRIDE;
58 const StatusCallback& callback) OVERRIDE;
59 virtual void Copy(const GURL& src_path, 58 virtual void Copy(const GURL& src_path,
60 const GURL& dest_path, 59 const GURL& dest_path) OVERRIDE;
61 const StatusCallback& callback) OVERRIDE;
62 virtual void Move(const GURL& src_path, 60 virtual void Move(const GURL& src_path,
63 const GURL& dest_path, 61 const GURL& dest_path) OVERRIDE;
64 const StatusCallback& callback) OVERRIDE; 62 virtual void DirectoryExists(const GURL& path) OVERRIDE;
65 virtual void DirectoryExists(const GURL& path, 63 virtual void FileExists(const GURL& path) OVERRIDE;
66 const StatusCallback& callback) OVERRIDE; 64 virtual void GetMetadata(const GURL& path) OVERRIDE;
67 virtual void FileExists(const GURL& path, 65 virtual void ReadDirectory(const GURL& path) OVERRIDE;
68 const StatusCallback& callback) OVERRIDE; 66 virtual void Remove(const GURL& path, bool recursive) OVERRIDE;
69 virtual void GetMetadata(const GURL& path,
70 const GetMetadataCallback& callback) OVERRIDE;
71 virtual void ReadDirectory(const GURL& path,
72 const ReadDirectoryCallback& callback) OVERRIDE;
73 virtual void Remove(const GURL& path, bool recursive,
74 const StatusCallback& callback) OVERRIDE;
75 virtual void Write(const net::URLRequestContext* url_request_context, 67 virtual void Write(const net::URLRequestContext* url_request_context,
76 const GURL& path, 68 const GURL& path,
77 const GURL& blob_url, 69 const GURL& blob_url,
78 int64 offset, 70 int64 offset) OVERRIDE;
79 const WriteCallback& callback) OVERRIDE; 71 virtual void Truncate(const GURL& path, int64 length) OVERRIDE;
80 virtual void Truncate(const GURL& path, int64 length,
81 const StatusCallback& callback) OVERRIDE;
82 virtual void TouchFile(const GURL& path, 72 virtual void TouchFile(const GURL& path,
83 const base::Time& last_access_time, 73 const base::Time& last_access_time,
84 const base::Time& last_modified_time, 74 const base::Time& last_modified_time) OVERRIDE;
85 const StatusCallback& callback) OVERRIDE; 75 virtual void OpenFile(
86 virtual void OpenFile(const GURL& path, 76 const GURL& path,
87 int file_flags, 77 int file_flags,
88 base::ProcessHandle peer_handle, 78 base::ProcessHandle peer_handle) OVERRIDE;
89 const OpenFileCallback& callback) OVERRIDE; 79 virtual void Cancel(
90 virtual void Cancel(const StatusCallback& cancel_callback) OVERRIDE; 80 scoped_ptr<FileSystemCallbackDispatcher> cancel_dispatcher) OVERRIDE;
91 virtual FileSystemOperation* AsFileSystemOperation() OVERRIDE; 81 virtual FileSystemOperation* AsFileSystemOperation() OVERRIDE;
92 82
93 // Synchronously gets the platform path for the given |path|. 83 // Synchronously gets the platform path for the given |path|.
94 void SyncGetPlatformPath(const GURL& path, FilePath* platform_path); 84 void SyncGetPlatformPath(const GURL& path, FilePath* platform_path);
95 85
96 private: 86 private:
97 class ScopedQuotaUtilHelper; 87 class ScopedQuotaUtilHelper;
98 88
99 // Only MountPointProviders or testing class can create a 89 // Only MountPointProviders or testing class can create a
100 // new operation directly. 90 // new operation directly.
101 friend class SandboxMountPointProvider; 91 friend class SandboxMountPointProvider;
102 friend class FileSystemTestHelper; 92 friend class FileSystemTestHelper;
103 friend class chromeos::CrosMountPointProvider; 93 friend class chromeos::CrosMountPointProvider;
104 94
105 FileSystemOperation(scoped_refptr<base::MessageLoopProxy> proxy, 95 FileSystemOperation(scoped_ptr<FileSystemCallbackDispatcher> dispatcher,
96 scoped_refptr<base::MessageLoopProxy> proxy,
106 FileSystemContext* file_system_context); 97 FileSystemContext* file_system_context);
107 98
108 FileSystemContext* file_system_context() const { 99 FileSystemContext* file_system_context() const {
109 return operation_context_.file_system_context(); 100 return operation_context_.file_system_context();
110 } 101 }
111 102
112 FileSystemOperationContext* file_system_operation_context() { 103 FileSystemOperationContext* file_system_operation_context() {
113 return &operation_context_; 104 return &operation_context_;
114 } 105 }
115 106
116 friend class FileSystemOperationTest; 107 friend class FileSystemOperationTest;
117 friend class FileSystemOperationWriteTest; 108 friend class FileSystemOperationWriteTest;
118 friend class FileWriterDelegateTest; 109 friend class FileWriterDelegateTest;
119 friend class FileSystemTestOriginHelper; 110 friend class FileSystemTestOriginHelper;
120 friend class FileSystemQuotaTest; 111 friend class FileSystemQuotaTest;
121 112
122 // The unit tests that need to specify and control the lifetime of the 113 // The unit tests that need to specify and control the lifetime of the
123 // file_util on their own should call this before performing the actual 114 // file_util on their own should call this before performing the actual
124 // operation. If it is given it will not be overwritten by the class. 115 // operation. If it is given it will not be overwritten by the class.
125 void set_override_file_util(FileSystemFileUtil* file_util) { 116 void set_override_file_util(FileSystemFileUtil* file_util) {
126 operation_context_.set_src_file_util(file_util); 117 operation_context_.set_src_file_util(file_util);
127 operation_context_.set_dest_file_util(file_util); 118 operation_context_.set_dest_file_util(file_util);
128 } 119 }
129 120
130 void GetUsageAndQuotaThenCallback( 121 void GetUsageAndQuotaThenCallback(
131 const GURL& origin_url, 122 const GURL& origin_url,
132 const quota::QuotaManager::GetUsageAndQuotaCallback& callback); 123 const quota::QuotaManager::GetUsageAndQuotaCallback& callback);
133 124
134 void DelayedCreateFileForQuota(const StatusCallback& callback, 125 void DelayedCreateFileForQuota(bool exclusive,
135 bool exclusive,
136 quota::QuotaStatusCode status, 126 quota::QuotaStatusCode status,
137 int64 usage, int64 quota); 127 int64 usage, int64 quota);
138 void DelayedCreateDirectoryForQuota(const StatusCallback& callback, 128 void DelayedCreateDirectoryForQuota(bool exclusive, bool recursive,
139 bool exclusive, bool recursive,
140 quota::QuotaStatusCode status, 129 quota::QuotaStatusCode status,
141 int64 usage, int64 quota); 130 int64 usage, int64 quota);
142 void DelayedCopyForQuota(const StatusCallback& callback, 131 void DelayedCopyForQuota(quota::QuotaStatusCode status,
143 quota::QuotaStatusCode status,
144 int64 usage, int64 quota); 132 int64 usage, int64 quota);
145 void DelayedMoveForQuota(const StatusCallback& callback, 133 void DelayedMoveForQuota(quota::QuotaStatusCode status,
146 quota::QuotaStatusCode status,
147 int64 usage, int64 quota); 134 int64 usage, int64 quota);
148 void DelayedWriteForQuota(quota::QuotaStatusCode status, 135 void DelayedWriteForQuota(quota::QuotaStatusCode status,
149 int64 usage, int64 quota); 136 int64 usage, int64 quota);
150 void DelayedTruncateForQuota(const StatusCallback& callback, 137 void DelayedTruncateForQuota(int64 length,
151 int64 length,
152 quota::QuotaStatusCode status, 138 quota::QuotaStatusCode status,
153 int64 usage, int64 quota); 139 int64 usage, int64 quota);
154 void DelayedOpenFileForQuota(const OpenFileCallback& callback, 140 void DelayedOpenFileForQuota(int file_flags,
155 int file_flags,
156 quota::QuotaStatusCode status, 141 quota::QuotaStatusCode status,
157 int64 usage, int64 quota); 142 int64 usage, int64 quota);
158 143
159 // Callback for CreateFile for |exclusive|=true cases. 144 // Callback for CreateFile for |exclusive|=true cases.
160 void DidEnsureFileExistsExclusive(const StatusCallback& callback, 145 void DidEnsureFileExistsExclusive(base::PlatformFileError rv,
161 base::PlatformFileError rv,
162 bool created); 146 bool created);
163 147
164 // Callback for CreateFile for |exclusive|=false cases. 148 // Callback for CreateFile for |exclusive|=false cases.
165 void DidEnsureFileExistsNonExclusive(const StatusCallback& callback, 149 void DidEnsureFileExistsNonExclusive(base::PlatformFileError rv,
166 base::PlatformFileError rv,
167 bool created); 150 bool created);
168 151
169 // Generic callback that translates platform errors to WebKit error codes. 152 // Generic callback that translates platform errors to WebKit error codes.
170 void DidFinishFileOperation(const StatusCallback& callback, 153 void DidFinishFileOperation(base::PlatformFileError rv);
171 base::PlatformFileError rv);
172 154
173 void DidDirectoryExists(const StatusCallback& callback, 155 void DidDirectoryExists(base::PlatformFileError rv,
174 base::PlatformFileError rv,
175 const base::PlatformFileInfo& file_info, 156 const base::PlatformFileInfo& file_info,
176 const FilePath& unused); 157 const FilePath& unused);
177 void DidFileExists(const StatusCallback& callback, 158 void DidFileExists(base::PlatformFileError rv,
178 base::PlatformFileError rv,
179 const base::PlatformFileInfo& file_info, 159 const base::PlatformFileInfo& file_info,
180 const FilePath& unused); 160 const FilePath& unused);
181 void DidGetMetadata(const GetMetadataCallback& callback, 161 void DidGetMetadata(base::PlatformFileError rv,
182 base::PlatformFileError rv,
183 const base::PlatformFileInfo& file_info, 162 const base::PlatformFileInfo& file_info,
184 const FilePath& platform_path); 163 const FilePath& platform_path);
185 void DidReadDirectory( 164 void DidReadDirectory(
186 const ReadDirectoryCallback& callback,
187 base::PlatformFileError rv, 165 base::PlatformFileError rv,
188 const std::vector<base::FileUtilProxy::Entry>& entries); 166 const std::vector<base::FileUtilProxy::Entry>& entries);
189 void DidWrite(base::PlatformFileError rv, 167 void DidWrite(
190 int64 bytes, 168 base::PlatformFileError rv,
191 bool complete); 169 int64 bytes,
192 void DidTouchFile(const StatusCallback& callback, 170 bool complete);
193 base::PlatformFileError rv); 171 void DidTouchFile(base::PlatformFileError rv);
194 void DidOpenFile(const OpenFileCallback& callback, 172 void DidOpenFile(
195 base::PlatformFileError rv, 173 base::PlatformFileError rv,
196 base::PassPlatformFile file, 174 base::PassPlatformFile file,
197 bool created); 175 bool created);
198 176
199 // Helper for Write(). 177 // Helper for Write().
200 void OnFileOpenedForWrite(base::PlatformFileError rv, 178 void OnFileOpenedForWrite(
201 base::PassPlatformFile file, 179 base::PlatformFileError rv,
202 bool created); 180 base::PassPlatformFile file,
181 bool created);
203 182
204 // Checks the validity of a given |path| for reading, cracks the path into 183 // Checks the validity of a given |path| for reading, cracks the path into
205 // root URL and virtual path components, and returns the correct 184 // root URL and virtual path components, and returns the correct
206 // FileSystemFileUtil subclass for this type. 185 // FileSystemFileUtil subclass for this type.
207 // Returns true if the given |path| is a valid FileSystem path. 186 // Returns true if the given |path| is a valid FileSystem path.
208 // Otherwise it calls dispatcher's DidFail method with 187 // Otherwise it calls dispatcher's DidFail method with
209 // PLATFORM_FILE_ERROR_SECURITY and returns false. 188 // PLATFORM_FILE_ERROR_SECURITY and returns false.
210 // (Note: this doesn't delete this when it calls DidFail and returns false; 189 // (Note: this doesn't delete this when it calls DidFail and returns false;
211 // it's the caller's responsibility.) 190 // it's the caller's responsibility.)
212 base::PlatformFileError VerifyFileSystemPathForRead( 191 bool VerifyFileSystemPathForRead(const GURL& path,
213 const GURL& path, 192 GURL* root_url,
214 GURL* root_url, 193 FileSystemType* type,
215 FileSystemType* type, 194 FilePath* virtual_path,
216 FilePath* virtual_path, 195 FileSystemFileUtil** file_util);
217 FileSystemFileUtil** file_util);
218 196
219 // Checks the validity of a given |path| for writing, cracks the path into 197 // Checks the validity of a given |path| for writing, cracks the path into
220 // root URL and virtual path components, and returns the correct 198 // root URL and virtual path components, and returns the correct
221 // FileSystemFileUtil subclass for this type. 199 // FileSystemFileUtil subclass for this type.
222 // Returns true if the given |path| is a valid FileSystem path, and 200 // Returns true if the given |path| is a valid FileSystem path, and
223 // its origin embedded in the path has the right to write. 201 // its origin embedded in the path has the right to write.
224 // Otherwise it fires dispatcher's DidFail method with 202 // Otherwise it fires dispatcher's DidFail method with
225 // PLATFORM_FILE_ERROR_SECURITY if the path is not valid for writing, 203 // PLATFORM_FILE_ERROR_SECURITY if the path is not valid for writing,
226 // or with PLATFORM_FILE_ERROR_NO_SPACE if the origin is not allowed to 204 // or with PLATFORM_FILE_ERROR_NO_SPACE if the origin is not allowed to
227 // write to the storage. 205 // write to the storage.
228 // In either case it returns false after firing DidFail. 206 // In either case it returns false after firing DidFail.
229 // If |create| flag is true this also checks if the |path| contains 207 // If |create| flag is true this also checks if the |path| contains
230 // any restricted names and chars. If it does, the call fires dispatcher's 208 // any restricted names and chars. If it does, the call fires dispatcher's
231 // DidFail with PLATFORM_FILE_ERROR_SECURITY and returns false. 209 // DidFail with PLATFORM_FILE_ERROR_SECURITY and returns false.
232 // (Note: this doesn't delete this when it calls DidFail and returns false; 210 // (Note: this doesn't delete this when it calls DidFail and returns false;
233 // it's the caller's responsibility.) 211 // it's the caller's responsibility.)
234 base::PlatformFileError VerifyFileSystemPathForWrite( 212 bool VerifyFileSystemPathForWrite(const GURL& path,
235 const GURL& path, 213 bool create,
236 bool create, 214 GURL* root_url,
237 GURL* root_url, 215 FileSystemType* type,
238 FileSystemType* type, 216 FilePath* virtual_path,
239 FilePath* virtual_path, 217 FileSystemFileUtil** file_util);
240 FileSystemFileUtil** file_util);
241 218
242 // Common internal routine for VerifyFileSystemPathFor{Read,Write}. 219 // Common internal routine for VerifyFileSystemPathFor{Read,Write}.
243 base::PlatformFileError VerifyFileSystemPath(const GURL& path, 220 bool VerifyFileSystemPath(const GURL& path,
244 GURL* root_url, 221 GURL* root_url,
245 FileSystemType* type, 222 FileSystemType* type,
246 FilePath* virtual_path, 223 FilePath* virtual_path,
247 FileSystemFileUtil** file_util); 224 FileSystemFileUtil** file_util);
248 225
249 // Setup*Context*() functions will call the appropriate VerifyFileSystem 226 // Setup*Context*() functions will call the appropriate VerifyFileSystem
250 // function and store the results to operation_context_ and 227 // function and store the results to operation_context_ and
251 // *_virtual_path_. 228 // *_virtual_path_.
252 // Return the result of VerifyFileSystem*(). 229 // Return the result of VerifyFileSystem*().
253 base::PlatformFileError SetupSrcContextForRead(const GURL& path); 230 bool SetupSrcContextForRead(const GURL& path);
254 base::PlatformFileError SetupSrcContextForWrite(const GURL& path, 231 bool SetupSrcContextForWrite(const GURL& path, bool create);
255 bool create); 232 bool SetupDestContextForWrite(const GURL& path, bool create);
256 base::PlatformFileError SetupDestContextForWrite(const GURL& path,
257 bool create);
258 233
259 #ifndef NDEBUG 234 #ifndef NDEBUG
260 enum OperationType { 235 enum OperationType {
261 kOperationNone, 236 kOperationNone,
262 kOperationCreateFile, 237 kOperationCreateFile,
263 kOperationCreateDirectory, 238 kOperationCreateDirectory,
264 kOperationCopy, 239 kOperationCopy,
265 kOperationMove, 240 kOperationMove,
266 kOperationDirectoryExists, 241 kOperationDirectoryExists,
267 kOperationFileExists, 242 kOperationFileExists,
268 kOperationGetMetadata, 243 kOperationGetMetadata,
269 kOperationReadDirectory, 244 kOperationReadDirectory,
270 kOperationRemove, 245 kOperationRemove,
271 kOperationWrite, 246 kOperationWrite,
272 kOperationTruncate, 247 kOperationTruncate,
273 kOperationTouchFile, 248 kOperationTouchFile,
274 kOperationOpenFile, 249 kOperationOpenFile,
275 kOperationGetLocalPath, 250 kOperationGetLocalPath,
276 kOperationCancel, 251 kOperationCancel,
277 }; 252 };
278 253
279 // A flag to make sure we call operation only once per instance. 254 // A flag to make sure we call operation only once per instance.
280 OperationType pending_operation_; 255 OperationType pending_operation_;
281 #endif 256 #endif
282 257
283 // Proxy for calling file_util_proxy methods. 258 // Proxy for calling file_util_proxy methods.
284 scoped_refptr<base::MessageLoopProxy> proxy_; 259 scoped_refptr<base::MessageLoopProxy> proxy_;
285 260
261 // This can be NULL if the operation is cancelled on the way.
262 scoped_ptr<FileSystemCallbackDispatcher> dispatcher_;
263
286 FileSystemOperationContext operation_context_; 264 FileSystemOperationContext operation_context_;
287 265
288 scoped_ptr<ScopedQuotaUtilHelper> quota_util_helper_; 266 scoped_ptr<ScopedQuotaUtilHelper> quota_util_helper_;
289 267
290 // These are all used only by Write(). 268 // These are all used only by Write().
291 friend class FileWriterDelegate; 269 friend class FileWriterDelegate;
292 scoped_ptr<FileWriterDelegate> file_writer_delegate_; 270 scoped_ptr<FileWriterDelegate> file_writer_delegate_;
293 scoped_ptr<net::URLRequest> blob_request_; 271 scoped_ptr<net::URLRequest> blob_request_;
294 272 scoped_ptr<FileSystemCallbackDispatcher> cancel_dispatcher_;
295 // write_callback is kept in this class for so that we can dispatch it when
296 // the operation is cancelled. calcel_callback is kept for canceling a
297 // Truncate() operation. We can't actually stop Truncate in another thread;
298 // after it resumed from the working thread, cancellation takes place.
299 WriteCallback write_callback_;
300 StatusCallback cancel_callback_;
301 void set_write_callback(const WriteCallback& write_callback) {
302 write_callback_ = write_callback;
303 }
304 273
305 // Used only by OpenFile, in order to clone the file handle back to the 274 // Used only by OpenFile, in order to clone the file handle back to the
306 // requesting process. 275 // requesting process.
307 base::ProcessHandle peer_handle_; 276 base::ProcessHandle peer_handle_;
308 277
309 // Used to keep a virtual path around while we check for quota. 278 // Used to keep a virtual path around while we check for quota.
310 // If an operation needs only one path, use src_virtual_path_, even if it's a 279 // If an operation needs only one path, use src_virtual_path_, even if it's a
311 // write. 280 // write.
312 FilePath src_virtual_path_; 281 FilePath src_virtual_path_;
313 FilePath dest_virtual_path_; 282 FilePath dest_virtual_path_;
314 283
315 DISALLOW_COPY_AND_ASSIGN(FileSystemOperation); 284 DISALLOW_COPY_AND_ASSIGN(FileSystemOperation);
316 }; 285 };
317 286
318 } // namespace fileapi 287 } // namespace fileapi
319 288
320 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_H_ 289 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_H_
OLDNEW
« no previous file with comments | « webkit/fileapi/file_system_mount_point_provider.h ('k') | webkit/fileapi/file_system_operation.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698