| OLD | NEW |
| 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 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 <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| 11 #include "base/file_util_proxy.h" | 11 #include "base/file_util_proxy.h" |
| 12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_callback_factory.h" | 14 #include "base/memory/scoped_callback_factory.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/memory/weak_ptr.h" | |
| 17 #include "base/message_loop_proxy.h" | 16 #include "base/message_loop_proxy.h" |
| 18 #include "base/platform_file.h" | 17 #include "base/platform_file.h" |
| 19 #include "base/process.h" | 18 #include "base/process.h" |
| 20 #include "googleurl/src/gurl.h" | 19 #include "googleurl/src/gurl.h" |
| 21 #include "webkit/fileapi/file_system_operation_context.h" | 20 #include "webkit/fileapi/file_system_operation_context.h" |
| 22 #include "webkit/fileapi/file_system_types.h" | 21 #include "webkit/fileapi/file_system_types.h" |
| 23 #include "webkit/quota/quota_manager.h" | 22 #include "webkit/quota/quota_manager.h" |
| 24 | 23 |
| 25 namespace base { | 24 namespace base { |
| 26 class Time; | 25 class Time; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 38 class FileSystemCallbackDispatcher; | 37 class FileSystemCallbackDispatcher; |
| 39 class FileSystemContext; | 38 class FileSystemContext; |
| 40 class FileWriterDelegate; | 39 class FileWriterDelegate; |
| 41 class FileSystemOperationTest; | 40 class FileSystemOperationTest; |
| 42 class FileSystemQuotaUtil; | 41 class FileSystemQuotaUtil; |
| 43 | 42 |
| 44 // This class is designed to serve one-time file system operation per instance. | 43 // This class is designed to serve one-time file system operation per instance. |
| 45 // Only one method(CreateFile, CreateDirectory, Copy, Move, DirectoryExists, | 44 // Only one method(CreateFile, CreateDirectory, Copy, Move, DirectoryExists, |
| 46 // GetMetadata, ReadDirectory and Remove) may be called during the lifetime of | 45 // GetMetadata, ReadDirectory and Remove) may be called during the lifetime of |
| 47 // this object and it should be called no more than once. | 46 // this object and it should be called no more than once. |
| 48 // This class is self-destructed and an instance automatically gets deleted | 47 // This class is self-destructed, or get deleted via base::Owned() fater the |
| 49 // when its operation is finished. | 48 // operation finishes and completion callback is called. |
| 50 class FileSystemOperation { | 49 class FileSystemOperation { |
| 51 public: | 50 public: |
| 52 // |dispatcher| will be owned by this class. | 51 // |dispatcher| will be owned by this class. |
| 53 FileSystemOperation(FileSystemCallbackDispatcher* dispatcher, | 52 FileSystemOperation(FileSystemCallbackDispatcher* dispatcher, |
| 54 scoped_refptr<base::MessageLoopProxy> proxy, | 53 scoped_refptr<base::MessageLoopProxy> proxy, |
| 55 FileSystemContext* file_system_context); | 54 FileSystemContext* file_system_context); |
| 56 virtual ~FileSystemOperation(); | 55 virtual ~FileSystemOperation(); |
| 57 | 56 |
| 58 void OpenFileSystem(const GURL& origin_url, | 57 void OpenFileSystem(const GURL& origin_url, |
| 59 fileapi::FileSystemType type, | 58 fileapi::FileSystemType type, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 // operation. If it is given it will not be overwritten by the class. | 112 // operation. If it is given it will not be overwritten by the class. |
| 114 void set_override_file_util(FileSystemFileUtil* file_util) { | 113 void set_override_file_util(FileSystemFileUtil* file_util) { |
| 115 operation_context_.set_src_file_util(file_util); | 114 operation_context_.set_src_file_util(file_util); |
| 116 operation_context_.set_dest_file_util(file_util); | 115 operation_context_.set_dest_file_util(file_util); |
| 117 } | 116 } |
| 118 | 117 |
| 119 void GetUsageAndQuotaThenCallback( | 118 void GetUsageAndQuotaThenCallback( |
| 120 const GURL& origin_url, | 119 const GURL& origin_url, |
| 121 const quota::QuotaManager::GetUsageAndQuotaCallback& callback); | 120 const quota::QuotaManager::GetUsageAndQuotaCallback& callback); |
| 122 | 121 |
| 123 void DelayedCreateFileForQuota(quota::QuotaStatusCode status, | 122 void DelayedCreateFileForQuota(bool exclusive, |
| 123 quota::QuotaStatusCode status, |
| 124 int64 usage, int64 quota); | 124 int64 usage, int64 quota); |
| 125 void DelayedCreateDirectoryForQuota(quota::QuotaStatusCode status, | 125 void DelayedCreateDirectoryForQuota(bool exclusive, bool recursive, |
| 126 quota::QuotaStatusCode status, |
| 126 int64 usage, int64 quota); | 127 int64 usage, int64 quota); |
| 127 void DelayedCopyForQuota(quota::QuotaStatusCode status, | 128 void DelayedCopyForQuota(quota::QuotaStatusCode status, |
| 128 int64 usage, int64 quota); | 129 int64 usage, int64 quota); |
| 129 void DelayedMoveForQuota(quota::QuotaStatusCode status, | 130 void DelayedMoveForQuota(quota::QuotaStatusCode status, |
| 130 int64 usage, int64 quota); | 131 int64 usage, int64 quota); |
| 131 void DelayedWriteForQuota(quota::QuotaStatusCode status, | 132 void DelayedWriteForQuota(quota::QuotaStatusCode status, |
| 132 int64 usage, int64 quota); | 133 int64 usage, int64 quota); |
| 133 void DelayedTruncateForQuota(quota::QuotaStatusCode status, | 134 void DelayedTruncateForQuota(int64 length, |
| 135 quota::QuotaStatusCode status, |
| 134 int64 usage, int64 quota); | 136 int64 usage, int64 quota); |
| 135 void DelayedOpenFileForQuota(quota::QuotaStatusCode status, | 137 void DelayedOpenFileForQuota(int file_flags, |
| 138 quota::QuotaStatusCode status, |
| 136 int64 usage, int64 quota); | 139 int64 usage, int64 quota); |
| 137 | 140 |
| 138 // A callback used for OpenFileSystem. | 141 // A callback used for OpenFileSystem. |
| 139 void DidGetRootPath(bool success, | 142 void DidGetRootPath(bool success, |
| 140 const FilePath& path, | 143 const FilePath& path, |
| 141 const std::string& name); | 144 const std::string& name); |
| 142 | 145 |
| 143 // Callback for CreateFile for |exclusive|=true cases. | 146 // Callback for CreateFile for |exclusive|=true cases. |
| 144 void DidEnsureFileExistsExclusive(base::PlatformFileError rv, | 147 void DidEnsureFileExistsExclusive(base::PlatformFileError rv, |
| 145 bool created); | 148 bool created); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 kOperationCancel, | 247 kOperationCancel, |
| 245 }; | 248 }; |
| 246 | 249 |
| 247 // A flag to make sure we call operation only once per instance. | 250 // A flag to make sure we call operation only once per instance. |
| 248 OperationType pending_operation_; | 251 OperationType pending_operation_; |
| 249 #endif | 252 #endif |
| 250 | 253 |
| 251 // Proxy for calling file_util_proxy methods. | 254 // Proxy for calling file_util_proxy methods. |
| 252 scoped_refptr<base::MessageLoopProxy> proxy_; | 255 scoped_refptr<base::MessageLoopProxy> proxy_; |
| 253 | 256 |
| 257 // This can be NULL if the operation is cancelled on the way. |
| 254 scoped_ptr<FileSystemCallbackDispatcher> dispatcher_; | 258 scoped_ptr<FileSystemCallbackDispatcher> dispatcher_; |
| 255 | 259 |
| 256 FileSystemOperationContext operation_context_; | 260 FileSystemOperationContext operation_context_; |
| 257 | 261 |
| 258 base::WeakPtrFactory<FileSystemOperation> weak_factory_; | |
| 259 | |
| 260 scoped_ptr<ScopedQuotaUtilHelper> quota_util_helper_; | 262 scoped_ptr<ScopedQuotaUtilHelper> quota_util_helper_; |
| 261 | 263 |
| 262 // These are all used only by Write(). | 264 // These are all used only by Write(). |
| 263 friend class FileWriterDelegate; | 265 friend class FileWriterDelegate; |
| 264 scoped_ptr<FileWriterDelegate> file_writer_delegate_; | 266 scoped_ptr<FileWriterDelegate> file_writer_delegate_; |
| 265 scoped_ptr<net::URLRequest> blob_request_; | 267 scoped_ptr<net::URLRequest> blob_request_; |
| 266 scoped_ptr<FileSystemOperation> cancel_operation_; | 268 scoped_ptr<FileSystemOperation> cancel_operation_; |
| 267 | 269 |
| 268 // Used only by OpenFile, in order to clone the file handle back to the | 270 // Used only by OpenFile, in order to clone the file handle back to the |
| 269 // requesting process. | 271 // requesting process. |
| 270 base::ProcessHandle peer_handle_; | 272 base::ProcessHandle peer_handle_; |
| 271 | 273 |
| 272 // Used to keep a virtual path around while we check for quota. | 274 // Used to keep a virtual path around while we check for quota. |
| 273 // If an operation needs only one path, use src_virtual_path_, even if it's a | 275 // If an operation needs only one path, use src_virtual_path_, even if it's a |
| 274 // write. | 276 // write. |
| 275 FilePath src_virtual_path_; | 277 FilePath src_virtual_path_; |
| 276 FilePath dest_virtual_path_; | 278 FilePath dest_virtual_path_; |
| 277 | 279 |
| 278 // Options for CreateFile and CreateDirectory. | |
| 279 bool exclusive_; | |
| 280 bool recursive_; | |
| 281 | |
| 282 // Options for OpenFile. | |
| 283 int file_flags_; | |
| 284 | |
| 285 // Length to be truncated. | |
| 286 int64 length_; | |
| 287 | |
| 288 DISALLOW_COPY_AND_ASSIGN(FileSystemOperation); | 280 DISALLOW_COPY_AND_ASSIGN(FileSystemOperation); |
| 289 }; | 281 }; |
| 290 | 282 |
| 291 } // namespace fileapi | 283 } // namespace fileapi |
| 292 | 284 |
| 293 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_H_ | 285 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_H_ |
| OLD | NEW |