| OLD | NEW |
| 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_BROWSER_FILEAPI_LOCAL_FILE_SYSTEM_OPERATION_H_ | 5 #ifndef WEBKIT_BROWSER_FILEAPI_LOCAL_FILE_SYSTEM_OPERATION_H_ |
| 6 #define WEBKIT_BROWSER_FILEAPI_LOCAL_FILE_SYSTEM_OPERATION_H_ | 6 #define WEBKIT_BROWSER_FILEAPI_LOCAL_FILE_SYSTEM_OPERATION_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/weak_ptr.h" |
| 12 #include "webkit/browser/fileapi/file_system_operation.h" | 13 #include "webkit/browser/fileapi/file_system_operation.h" |
| 14 #include "webkit/browser/fileapi/file_system_operation_context.h" |
| 13 #include "webkit/browser/fileapi/file_system_url.h" | 15 #include "webkit/browser/fileapi/file_system_url.h" |
| 14 #include "webkit/browser/fileapi/file_writer_delegate.h" | 16 #include "webkit/browser/fileapi/file_writer_delegate.h" |
| 15 #include "webkit/common/blob/scoped_file.h" | 17 #include "webkit/common/blob/scoped_file.h" |
| 16 #include "webkit/common/quota/quota_types.h" | 18 #include "webkit/common/quota/quota_types.h" |
| 17 #include "webkit/storage/webkit_storage_export.h" | 19 #include "webkit/storage/webkit_storage_export.h" |
| 18 | 20 |
| 19 namespace chromeos { | 21 namespace chromeos { |
| 20 class CrosMountPointProvider; | 22 class CrosMountPointProvider; |
| 21 } | 23 } |
| 22 | 24 |
| 23 namespace sync_file_system { | 25 namespace sync_file_system { |
| 24 class SyncableFileSystemOperation; | 26 class SyncableFileSystemOperation; |
| 25 } | 27 } |
| 26 | 28 |
| 27 namespace fileapi { | 29 namespace fileapi { |
| 28 | 30 |
| 29 class AsyncFileUtil; | 31 class AsyncFileUtil; |
| 30 class FileSystemContext; | 32 class FileSystemContext; |
| 31 class RecursiveOperationDelegate; | 33 class RecursiveOperationDelegate; |
| 32 | 34 |
| 33 // FileSystemOperation implementation for local file systems. | 35 // FileSystemOperation implementation for local file systems. |
| 34 class WEBKIT_STORAGE_EXPORT LocalFileSystemOperation | 36 class WEBKIT_STORAGE_EXPORT LocalFileSystemOperation |
| 35 : public NON_EXPORTED_BASE(FileSystemOperation) { | 37 : public NON_EXPORTED_BASE(FileSystemOperation), |
| 38 public base::SupportsWeakPtr<LocalFileSystemOperation> { |
| 36 public: | 39 public: |
| 37 // NOTE: This constructor should not be called outside MountPointProviders; | 40 // NOTE: This constructor should not be called outside MountPointProviders; |
| 38 // instead please consider using | 41 // instead please consider using |
| 39 // file_system_context->CreateFileSystemOperation() to instantiate | 42 // file_system_context->CreateFileSystemOperation() to instantiate |
| 40 // an appropriate FileSystemOperation. | 43 // an appropriate FileSystemOperation. |
| 41 LocalFileSystemOperation( | 44 LocalFileSystemOperation( |
| 42 const FileSystemURL& url, | 45 const FileSystemURL& url, |
| 43 FileSystemContext* file_system_context, | 46 FileSystemContext* file_system_context, |
| 44 scoped_ptr<FileSystemOperationContext> operation_context); | 47 scoped_ptr<FileSystemOperationContext> operation_context); |
| 45 | 48 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 const StatusCallback& callback); | 161 const StatusCallback& callback); |
| 159 | 162 |
| 160 // Synchronously gets the platform path for the given |url|. | 163 // Synchronously gets the platform path for the given |url|. |
| 161 void SyncGetPlatformPath(const FileSystemURL& url, | 164 void SyncGetPlatformPath(const FileSystemURL& url, |
| 162 base::FilePath* platform_path); | 165 base::FilePath* platform_path); |
| 163 | 166 |
| 164 FileSystemContext* file_system_context() const { | 167 FileSystemContext* file_system_context() const { |
| 165 return file_system_context_.get(); | 168 return file_system_context_.get(); |
| 166 } | 169 } |
| 167 | 170 |
| 168 FileSystemOperationContext* operation_context() const { | |
| 169 return operation_context_.get(); | |
| 170 } | |
| 171 | |
| 172 private: | 171 private: |
| 173 friend class sync_file_system::SyncableFileSystemOperation; | 172 friend class sync_file_system::SyncableFileSystemOperation; |
| 174 | 173 |
| 175 // Queries the quota and usage and then runs the given |task|. | 174 // Queries the quota and usage and then runs the given |task|. |
| 176 // If an error occurs during the quota query it runs |error_callback| instead. | 175 // If an error occurs during the quota query it runs |error_callback| instead. |
| 177 void GetUsageAndQuotaThenRunTask( | 176 void GetUsageAndQuotaThenRunTask( |
| 178 const FileSystemURL& url, | 177 const FileSystemURL& url, |
| 179 const base::Closure& task, | 178 const base::Closure& task, |
| 180 const base::Closure& error_callback); | 179 const base::Closure& error_callback); |
| 181 | 180 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 // Callback for CreateFile for |exclusive|=true cases. | 225 // Callback for CreateFile for |exclusive|=true cases. |
| 227 void DidEnsureFileExistsExclusive(const StatusCallback& callback, | 226 void DidEnsureFileExistsExclusive(const StatusCallback& callback, |
| 228 base::PlatformFileError rv, | 227 base::PlatformFileError rv, |
| 229 bool created); | 228 bool created); |
| 230 | 229 |
| 231 // Callback for CreateFile for |exclusive|=false cases. | 230 // Callback for CreateFile for |exclusive|=false cases. |
| 232 void DidEnsureFileExistsNonExclusive(const StatusCallback& callback, | 231 void DidEnsureFileExistsNonExclusive(const StatusCallback& callback, |
| 233 base::PlatformFileError rv, | 232 base::PlatformFileError rv, |
| 234 bool created); | 233 bool created); |
| 235 | 234 |
| 236 // Generic callback that translates platform errors to WebKit error codes. | 235 void DidFinishOperation(const StatusCallback& callback, |
| 237 void DidFinishFileOperation(const StatusCallback& callback, | 236 base::PlatformFileError rv); |
| 238 base::PlatformFileError rv); | |
| 239 | |
| 240 // Generic callback when we delegated the operation. | |
| 241 void DidFinishDelegatedOperation(const StatusCallback& callback, | |
| 242 base::PlatformFileError rv); | |
| 243 | |
| 244 void DidDirectoryExists(const StatusCallback& callback, | 237 void DidDirectoryExists(const StatusCallback& callback, |
| 245 base::PlatformFileError rv, | 238 base::PlatformFileError rv, |
| 246 const base::PlatformFileInfo& file_info, | 239 const base::PlatformFileInfo& file_info, |
| 247 const base::FilePath& unused); | 240 const base::FilePath& unused); |
| 248 void DidFileExists(const StatusCallback& callback, | 241 void DidFileExists(const StatusCallback& callback, |
| 249 base::PlatformFileError rv, | 242 base::PlatformFileError rv, |
| 250 const base::PlatformFileInfo& file_info, | 243 const base::PlatformFileInfo& file_info, |
| 251 const base::FilePath& unused); | 244 const base::FilePath& unused); |
| 252 void DidGetMetadata(const GetMetadataCallback& callback, | |
| 253 base::PlatformFileError rv, | |
| 254 const base::PlatformFileInfo& file_info, | |
| 255 const base::FilePath& platform_path); | |
| 256 void DidReadDirectory(const ReadDirectoryCallback& callback, | |
| 257 base::PlatformFileError rv, | |
| 258 const std::vector<DirectoryEntry>& entries, | |
| 259 bool has_more); | |
| 260 void DidWrite(const FileSystemURL& url, | 245 void DidWrite(const FileSystemURL& url, |
| 246 const WriteCallback& callback, |
| 261 base::PlatformFileError rv, | 247 base::PlatformFileError rv, |
| 262 int64 bytes, | 248 int64 bytes, |
| 263 FileWriterDelegate::WriteProgressStatus write_status); | 249 FileWriterDelegate::WriteProgressStatus write_status); |
| 264 void DidTouchFile(const StatusCallback& callback, | |
| 265 base::PlatformFileError rv); | |
| 266 void DidOpenFile(const OpenFileCallback& callback, | 250 void DidOpenFile(const OpenFileCallback& callback, |
| 267 base::PlatformFileError rv, | 251 base::PlatformFileError rv, |
| 268 base::PassPlatformFile file, | 252 base::PassPlatformFile file, |
| 269 bool created); | 253 bool created); |
| 270 void DidCreateSnapshotFile( | |
| 271 const SnapshotFileCallback& callback, | |
| 272 base::PlatformFileError result, | |
| 273 const base::PlatformFileInfo& file_info, | |
| 274 const base::FilePath& platform_path, | |
| 275 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref); | |
| 276 | 254 |
| 277 // Used only for internal assertions. | 255 // Used only for internal assertions. |
| 278 // Returns false if there's another inflight pending operation. | 256 // Returns false if there's another inflight pending operation. |
| 279 bool SetPendingOperationType(OperationType type); | 257 bool SetPendingOperationType(OperationType type); |
| 280 | 258 |
| 281 scoped_refptr<FileSystemContext> file_system_context_; | 259 scoped_refptr<FileSystemContext> file_system_context_; |
| 282 | 260 |
| 283 scoped_ptr<FileSystemOperationContext> operation_context_; | 261 scoped_ptr<FileSystemOperationContext> operation_context_; |
| 284 AsyncFileUtil* async_file_util_; // Not owned. | 262 AsyncFileUtil* async_file_util_; // Not owned. |
| 285 | 263 |
| 286 // These are all used only by Write(). | |
| 287 friend class FileWriterDelegate; | |
| 288 scoped_ptr<FileWriterDelegate> file_writer_delegate_; | 264 scoped_ptr<FileWriterDelegate> file_writer_delegate_; |
| 289 | |
| 290 scoped_ptr<RecursiveOperationDelegate> recursive_operation_delegate_; | 265 scoped_ptr<RecursiveOperationDelegate> recursive_operation_delegate_; |
| 291 | 266 |
| 292 // write_callback is kept in this class for so that we can dispatch it when | |
| 293 // the operation is cancelled. calcel_callback is kept for canceling a | |
| 294 // Truncate() operation. We can't actually stop Truncate in another thread; | |
| 295 // after it resumed from the working thread, cancellation takes place. | |
| 296 WriteCallback write_callback_; | |
| 297 StatusCallback cancel_callback_; | 267 StatusCallback cancel_callback_; |
| 298 | 268 |
| 299 // Used only by OpenFile, in order to clone the file handle back to the | 269 // Used only by OpenFile, in order to clone the file handle back to the |
| 300 // requesting process. | 270 // requesting process. |
| 301 base::ProcessHandle peer_handle_; | 271 base::ProcessHandle peer_handle_; |
| 302 | 272 |
| 303 // A flag to make sure we call operation only once per instance. | 273 // A flag to make sure we call operation only once per instance. |
| 304 OperationType pending_operation_; | 274 OperationType pending_operation_; |
| 305 | 275 |
| 306 // LocalFileSystemOperation instance is usually deleted upon completion but | |
| 307 // could be deleted while it has inflight callbacks when Cancel is called. | |
| 308 base::WeakPtrFactory<LocalFileSystemOperation> weak_factory_; | |
| 309 | |
| 310 DISALLOW_COPY_AND_ASSIGN(LocalFileSystemOperation); | 276 DISALLOW_COPY_AND_ASSIGN(LocalFileSystemOperation); |
| 311 }; | 277 }; |
| 312 | 278 |
| 313 } // namespace fileapi | 279 } // namespace fileapi |
| 314 | 280 |
| 315 #endif // WEBKIT_BROWSER_FILEAPI_LOCAL_FILE_SYSTEM_OPERATION_H_ | 281 #endif // WEBKIT_BROWSER_FILEAPI_LOCAL_FILE_SYSTEM_OPERATION_H_ |
| OLD | NEW |