| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_BROWSER_FILEAPI_FILE_SYSTEM_OPERATION_RUNNER_H_ | 5 #ifndef WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_OPERATION_RUNNER_H_ |
| 6 #define WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_OPERATION_RUNNER_H_ | 6 #define WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_OPERATION_RUNNER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 public: | 36 public: |
| 37 typedef FileSystemOperation::GetMetadataCallback GetMetadataCallback; | 37 typedef FileSystemOperation::GetMetadataCallback GetMetadataCallback; |
| 38 typedef FileSystemOperation::ReadDirectoryCallback ReadDirectoryCallback; | 38 typedef FileSystemOperation::ReadDirectoryCallback ReadDirectoryCallback; |
| 39 typedef FileSystemOperation::SnapshotFileCallback SnapshotFileCallback; | 39 typedef FileSystemOperation::SnapshotFileCallback SnapshotFileCallback; |
| 40 typedef FileSystemOperation::StatusCallback StatusCallback; | 40 typedef FileSystemOperation::StatusCallback StatusCallback; |
| 41 typedef FileSystemOperation::WriteCallback WriteCallback; | 41 typedef FileSystemOperation::WriteCallback WriteCallback; |
| 42 typedef FileSystemOperation::OpenFileCallback OpenFileCallback; | 42 typedef FileSystemOperation::OpenFileCallback OpenFileCallback; |
| 43 | 43 |
| 44 typedef int OperationID; | 44 typedef int OperationID; |
| 45 | 45 |
| 46 static const OperationID kErrorOperationID; | |
| 47 | |
| 48 virtual ~FileSystemOperationRunner(); | 46 virtual ~FileSystemOperationRunner(); |
| 49 | 47 |
| 50 // Cancels all inflight operations. | 48 // Cancels all inflight operations. |
| 51 void Shutdown(); | 49 void Shutdown(); |
| 52 | 50 |
| 53 // Creates a file at |url|. If |exclusive| is true, an error is raised | 51 // Creates a file at |url|. If |exclusive| is true, an error is raised |
| 54 // in case a file is already present at the URL. | 52 // in case a file is already present at the URL. |
| 55 OperationID CreateFile(const FileSystemURL& url, | 53 OperationID CreateFile(const FileSystemURL& url, |
| 56 bool exclusive, | 54 bool exclusive, |
| 57 const StatusCallback& callback); | 55 const StatusCallback& callback); |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 const FileSystemURL& dest_url, | 213 const FileSystemURL& dest_url, |
| 216 const StatusCallback& callback); | 214 const StatusCallback& callback); |
| 217 | 215 |
| 218 // This is called only by pepper plugin as of writing to synchronously get | 216 // This is called only by pepper plugin as of writing to synchronously get |
| 219 // the underlying platform path to upload a file in the sandboxed filesystem | 217 // the underlying platform path to upload a file in the sandboxed filesystem |
| 220 // (e.g. TEMPORARY or PERSISTENT). | 218 // (e.g. TEMPORARY or PERSISTENT). |
| 221 base::PlatformFileError SyncGetPlatformPath(const FileSystemURL& url, | 219 base::PlatformFileError SyncGetPlatformPath(const FileSystemURL& url, |
| 222 base::FilePath* platform_path); | 220 base::FilePath* platform_path); |
| 223 | 221 |
| 224 private: | 222 private: |
| 223 class BeginOperationScoper; |
| 224 |
| 225 struct OperationHandle { |
| 226 OperationID id; |
| 227 base::WeakPtr<BeginOperationScoper> scope; |
| 228 |
| 229 OperationHandle(); |
| 230 ~OperationHandle(); |
| 231 }; |
| 232 |
| 225 friend class FileSystemContext; | 233 friend class FileSystemContext; |
| 226 explicit FileSystemOperationRunner(FileSystemContext* file_system_context); | 234 explicit FileSystemOperationRunner(FileSystemContext* file_system_context); |
| 227 | 235 |
| 228 void DidFinish(OperationID id, | 236 void DidFinish(const OperationHandle& handle, |
| 229 const StatusCallback& callback, | 237 const StatusCallback& callback, |
| 230 base::PlatformFileError rv); | 238 base::PlatformFileError rv); |
| 231 void DidGetMetadata(OperationID id, | 239 void DidGetMetadata(const OperationHandle& handle, |
| 232 const GetMetadataCallback& callback, | 240 const GetMetadataCallback& callback, |
| 233 base::PlatformFileError rv, | 241 base::PlatformFileError rv, |
| 234 const base::PlatformFileInfo& file_info); | 242 const base::PlatformFileInfo& file_info); |
| 235 void DidReadDirectory(OperationID id, | 243 void DidReadDirectory(const OperationHandle& handle, |
| 236 const ReadDirectoryCallback& callback, | 244 const ReadDirectoryCallback& callback, |
| 237 base::PlatformFileError rv, | 245 base::PlatformFileError rv, |
| 238 const std::vector<DirectoryEntry>& entries, | 246 const std::vector<DirectoryEntry>& entries, |
| 239 bool has_more); | 247 bool has_more); |
| 240 void DidWrite(OperationID id, | 248 void DidWrite(const OperationHandle& handle, |
| 241 const WriteCallback& callback, | 249 const WriteCallback& callback, |
| 242 base::PlatformFileError rv, | 250 base::PlatformFileError rv, |
| 243 int64 bytes, | 251 int64 bytes, |
| 244 bool complete); | 252 bool complete); |
| 245 void DidOpenFile( | 253 void DidOpenFile( |
| 246 OperationID id, | 254 const OperationHandle& handle, |
| 247 const OpenFileCallback& callback, | 255 const OpenFileCallback& callback, |
| 248 base::PlatformFileError rv, | 256 base::PlatformFileError rv, |
| 249 base::PlatformFile file, | 257 base::PlatformFile file, |
| 250 const base::Closure& on_close_callback, | 258 const base::Closure& on_close_callback, |
| 251 base::ProcessHandle peer_handle); | 259 base::ProcessHandle peer_handle); |
| 252 void DidCreateSnapshot( | 260 void DidCreateSnapshot( |
| 253 OperationID id, | 261 const OperationHandle& handle, |
| 254 const SnapshotFileCallback& callback, | 262 const SnapshotFileCallback& callback, |
| 255 base::PlatformFileError rv, | 263 base::PlatformFileError rv, |
| 256 const base::PlatformFileInfo& file_info, | 264 const base::PlatformFileInfo& file_info, |
| 257 const base::FilePath& platform_path, | 265 const base::FilePath& platform_path, |
| 258 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref); | 266 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref); |
| 259 | 267 |
| 260 void PrepareForWrite(OperationID id, const FileSystemURL& url); | 268 void PrepareForWrite(OperationID id, const FileSystemURL& url); |
| 261 void PrepareForRead(OperationID id, const FileSystemURL& url); | 269 void PrepareForRead(OperationID id, const FileSystemURL& url); |
| 262 | 270 |
| 263 // This must be called at the end of any async operations. | 271 // These must be called at the beginning and end of any async operations. |
| 272 OperationHandle BeginOperation(FileSystemOperation* operation, |
| 273 base::WeakPtr<BeginOperationScoper> scope); |
| 264 void FinishOperation(OperationID id); | 274 void FinishOperation(OperationID id); |
| 265 | 275 |
| 266 // Not owned; file_system_context owns this. | 276 // Not owned; file_system_context owns this. |
| 267 FileSystemContext* file_system_context_; | 277 FileSystemContext* file_system_context_; |
| 268 | 278 |
| 269 // IDMap<FileSystemOperation, IDMapOwnPointer> operations_; | 279 // IDMap<FileSystemOperation, IDMapOwnPointer> operations_; |
| 270 IDMap<FileSystemOperation, IDMapOwnPointer> operations_; | 280 IDMap<FileSystemOperation, IDMapOwnPointer> operations_; |
| 271 | 281 |
| 272 // We keep track of the file to be modified by each operation so that | 282 // We keep track of the file to be modified by each operation so that |
| 273 // we can notify observers when we're done. | 283 // we can notify observers when we're done. |
| 274 typedef std::map<OperationID, FileSystemURLSet> OperationToURLSet; | 284 typedef std::map<OperationID, FileSystemURLSet> OperationToURLSet; |
| 275 OperationToURLSet write_target_urls_; | 285 OperationToURLSet write_target_urls_; |
| 276 | 286 |
| 287 // Operations that are finished but not yet fire their callbacks. |
| 288 std::set<OperationID> finished_operations_; |
| 289 |
| 290 // Callbacks for stray cancels whose target operation is already finished. |
| 291 std::map<OperationID, StatusCallback> stray_cancel_callbacks_; |
| 292 |
| 277 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationRunner); | 293 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationRunner); |
| 278 }; | 294 }; |
| 279 | 295 |
| 280 } // namespace fileapi | 296 } // namespace fileapi |
| 281 | 297 |
| 282 #endif // WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_OPERATION_RUNNER_H_ | 298 #endif // WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_OPERATION_RUNNER_H_ |
| OLD | NEW |