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/message_loop_proxy.h" | 16 #include "base/message_loop_proxy.h" |
17 #include "base/platform_file.h" | 17 #include "base/platform_file.h" |
18 #include "base/process.h" | 18 #include "base/process.h" |
19 #include "googleurl/src/gurl.h" | 19 #include "googleurl/src/gurl.h" |
| 20 #include "webkit/fileapi/file_system_operation_context.h" |
20 #include "webkit/fileapi/file_system_types.h" | 21 #include "webkit/fileapi/file_system_types.h" |
21 #include "webkit/fileapi/file_system_operation_context.h" | |
22 #include "webkit/quota/quota_manager.h" | 22 #include "webkit/quota/quota_manager.h" |
23 | 23 |
24 namespace base { | 24 namespace base { |
25 class Time; | 25 class Time; |
26 } | 26 } |
27 | 27 |
28 namespace net { | 28 namespace net { |
29 class URLRequest; | 29 class URLRequest; |
30 class URLRequestContext; | 30 class URLRequestContext; |
31 } // namespace net | 31 } // namespace net |
32 | 32 |
33 class GURL; | 33 class GURL; |
34 | 34 |
35 namespace fileapi { | 35 namespace fileapi { |
36 | 36 |
37 class FileSystemCallbackDispatcher; | 37 class FileSystemCallbackDispatcher; |
38 class FileSystemContext; | 38 class FileSystemContext; |
39 class FileWriterDelegate; | 39 class FileWriterDelegate; |
40 class FileSystemOperationTest; | 40 class FileSystemOperationTest; |
| 41 class FileSystemQuotaUtil; |
41 | 42 |
42 // 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. |
43 // Only one method(CreateFile, CreateDirectory, Copy, Move, DirectoryExists, | 44 // Only one method(CreateFile, CreateDirectory, Copy, Move, DirectoryExists, |
44 // GetMetadata, ReadDirectory and Remove) may be called during the lifetime of | 45 // GetMetadata, ReadDirectory and Remove) may be called during the lifetime of |
45 // this object and it should be called no more than once. | 46 // this object and it should be called no more than once. |
46 // This class is self-destructed and an instance automatically gets deleted | 47 // This class is self-destructed and an instance automatically gets deleted |
47 // when its operation is finished. | 48 // when its operation is finished. |
48 class FileSystemOperation { | 49 class FileSystemOperation { |
49 public: | 50 public: |
50 // |dispatcher| will be owned by this class. | 51 // |dispatcher| will be owned by this class. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 const GURL& path, | 86 const GURL& path, |
86 int file_flags, | 87 int file_flags, |
87 base::ProcessHandle peer_handle); | 88 base::ProcessHandle peer_handle); |
88 | 89 |
89 // Try to cancel the current operation [we support cancelling write or | 90 // Try to cancel the current operation [we support cancelling write or |
90 // truncate only]. Report failure for the current operation, then tell the | 91 // truncate only]. Report failure for the current operation, then tell the |
91 // passed-in operation to report success. | 92 // passed-in operation to report success. |
92 void Cancel(FileSystemOperation* cancel_operation); | 93 void Cancel(FileSystemOperation* cancel_operation); |
93 | 94 |
94 private: | 95 private: |
| 96 class ScopedQuotaUtilHelper { |
| 97 public: |
| 98 explicit ScopedQuotaUtilHelper(FileSystemContext* context, |
| 99 const GURL& origin_url, |
| 100 FileSystemType type); |
| 101 ~ScopedQuotaUtilHelper(); |
| 102 |
| 103 private: |
| 104 FileSystemQuotaUtil* quota_util_; |
| 105 const GURL& origin_url_; |
| 106 FileSystemType type_; |
| 107 DISALLOW_COPY_AND_ASSIGN(ScopedQuotaUtilHelper); |
| 108 }; |
| 109 |
95 FileSystemContext* file_system_context() const { | 110 FileSystemContext* file_system_context() const { |
96 return file_system_operation_context_.file_system_context(); | 111 return file_system_operation_context_.file_system_context(); |
97 } | 112 } |
98 | 113 |
99 FileSystemOperationContext* file_system_operation_context() { | 114 FileSystemOperationContext* file_system_operation_context() { |
100 return &file_system_operation_context_; | 115 return &file_system_operation_context_; |
101 } | 116 } |
102 | 117 |
103 friend class FileSystemOperationTest; | 118 friend class FileSystemOperationTest; |
104 friend class FileSystemOperationWriteTest; | 119 friend class FileSystemOperationWriteTest; |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 | 247 |
233 // Proxy for calling file_util_proxy methods. | 248 // Proxy for calling file_util_proxy methods. |
234 scoped_refptr<base::MessageLoopProxy> proxy_; | 249 scoped_refptr<base::MessageLoopProxy> proxy_; |
235 | 250 |
236 scoped_ptr<FileSystemCallbackDispatcher> dispatcher_; | 251 scoped_ptr<FileSystemCallbackDispatcher> dispatcher_; |
237 | 252 |
238 FileSystemOperationContext file_system_operation_context_; | 253 FileSystemOperationContext file_system_operation_context_; |
239 | 254 |
240 base::ScopedCallbackFactory<FileSystemOperation> callback_factory_; | 255 base::ScopedCallbackFactory<FileSystemOperation> callback_factory_; |
241 | 256 |
| 257 scoped_ptr<ScopedQuotaUtilHelper> quota_util_helper_; |
| 258 |
242 // These are all used only by Write(). | 259 // These are all used only by Write(). |
243 friend class FileWriterDelegate; | 260 friend class FileWriterDelegate; |
244 scoped_ptr<FileWriterDelegate> file_writer_delegate_; | 261 scoped_ptr<FileWriterDelegate> file_writer_delegate_; |
245 scoped_ptr<net::URLRequest> blob_request_; | 262 scoped_ptr<net::URLRequest> blob_request_; |
246 scoped_ptr<FileSystemOperation> cancel_operation_; | 263 scoped_ptr<FileSystemOperation> cancel_operation_; |
247 | 264 |
248 // Used only by OpenFile, in order to clone the file handle back to the | 265 // Used only by OpenFile, in order to clone the file handle back to the |
249 // requesting process. | 266 // requesting process. |
250 base::ProcessHandle peer_handle_; | 267 base::ProcessHandle peer_handle_; |
251 | 268 |
252 // Options for CreateFile and CreateDirectory. | 269 // Options for CreateFile and CreateDirectory. |
253 bool exclusive_; | 270 bool exclusive_; |
254 bool recursive_; | 271 bool recursive_; |
255 | 272 |
256 // Options for OpenFile. | 273 // Options for OpenFile. |
257 int file_flags_; | 274 int file_flags_; |
258 | 275 |
259 // Length to be truncated. | 276 // Length to be truncated. |
260 int64 length_; | 277 int64 length_; |
261 | 278 |
262 DISALLOW_COPY_AND_ASSIGN(FileSystemOperation); | 279 DISALLOW_COPY_AND_ASSIGN(FileSystemOperation); |
263 }; | 280 }; |
264 | 281 |
265 } // namespace fileapi | 282 } // namespace fileapi |
266 | 283 |
267 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_H_ | 284 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_H_ |
OLD | NEW |