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_FILEAPI_LOCAL_FILE_SYSTEM_OPERATION_H_ | 5 #ifndef WEBKIT_FILEAPI_LOCAL_FILE_SYSTEM_OPERATION_H_ |
6 #define WEBKIT_FILEAPI_LOCAL_FILE_SYSTEM_OPERATION_H_ | 6 #define WEBKIT_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/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
13 #include "webkit/fileapi/file_system_file_util.h" | 13 #include "webkit/fileapi/file_system_file_util.h" |
14 #include "webkit/fileapi/file_system_operation.h" | 14 #include "webkit/fileapi/file_system_operation.h" |
15 #include "webkit/fileapi/file_system_operation_context.h" | 15 #include "webkit/fileapi/file_system_operation_context.h" |
16 #include "webkit/fileapi/file_system_url.h" | 16 #include "webkit/fileapi/file_system_url.h" |
17 #include "webkit/fileapi/file_writer_delegate.h" | 17 #include "webkit/fileapi/file_writer_delegate.h" |
18 #include "webkit/quota/quota_types.h" | 18 #include "webkit/quota/quota_types.h" |
19 #include "webkit/storage/webkit_storage_export.h" | 19 #include "webkit/storage/webkit_storage_export.h" |
20 | 20 |
21 namespace chromeos { | 21 namespace chromeos { |
22 class CrosMountPointProvider; | 22 class CrosMountPointProvider; |
23 } | 23 } |
24 | 24 |
25 namespace fileapi { | 25 namespace fileapi { |
26 | 26 |
27 class FileSystemContext; | 27 class FileSystemContext; |
| 28 class RemoveOperationDelegate; |
28 | 29 |
29 // FileSystemOperation implementation for local file systems. | 30 // FileSystemOperation implementation for local file systems. |
30 class WEBKIT_STORAGE_EXPORT LocalFileSystemOperation | 31 class WEBKIT_STORAGE_EXPORT LocalFileSystemOperation |
31 : public NON_EXPORTED_BASE(FileSystemOperation) { | 32 : public NON_EXPORTED_BASE(FileSystemOperation) { |
32 public: | 33 public: |
33 virtual ~LocalFileSystemOperation(); | 34 virtual ~LocalFileSystemOperation(); |
34 | 35 |
35 // FileSystemOperation overrides. | 36 // FileSystemOperation overrides. |
36 virtual void CreateFile(const FileSystemURL& url, | 37 virtual void CreateFile(const FileSystemURL& url, |
37 bool exclusive, | 38 bool exclusive, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 int file_flags, | 72 int file_flags, |
72 base::ProcessHandle peer_handle, | 73 base::ProcessHandle peer_handle, |
73 const OpenFileCallback& callback) OVERRIDE; | 74 const OpenFileCallback& callback) OVERRIDE; |
74 virtual void NotifyCloseFile(const FileSystemURL& url) OVERRIDE; | 75 virtual void NotifyCloseFile(const FileSystemURL& url) OVERRIDE; |
75 virtual void Cancel(const StatusCallback& cancel_callback) OVERRIDE; | 76 virtual void Cancel(const StatusCallback& cancel_callback) OVERRIDE; |
76 virtual LocalFileSystemOperation* AsLocalFileSystemOperation() OVERRIDE; | 77 virtual LocalFileSystemOperation* AsLocalFileSystemOperation() OVERRIDE; |
77 virtual void CreateSnapshotFile( | 78 virtual void CreateSnapshotFile( |
78 const FileSystemURL& path, | 79 const FileSystemURL& path, |
79 const SnapshotFileCallback& callback) OVERRIDE; | 80 const SnapshotFileCallback& callback) OVERRIDE; |
80 | 81 |
| 82 // Copies in a single file from a different filesystem. |
| 83 // |
| 84 // This returns: |
| 85 // - PLATFORM_FILE_ERROR_NOT_FOUND if |src_file_path| |
| 86 // or the parent directory of |dest_url| does not exist. |
| 87 // - PLATFORM_FILE_ERROR_INVALID_OPERATION if |dest_url| exists and |
| 88 // is not a file. |
| 89 // - PLATFORM_FILE_ERROR_FAILED if |dest_url| does not exist and |
| 90 // its parent path is a file. |
| 91 // |
81 void CopyInForeignFile(const FilePath& src_local_disk_path, | 92 void CopyInForeignFile(const FilePath& src_local_disk_path, |
82 const FileSystemURL& dest_url, | 93 const FileSystemURL& dest_url, |
83 const StatusCallback& callback); | 94 const StatusCallback& callback); |
84 | 95 |
| 96 // Removes a single file. |
| 97 // |
| 98 // This returns: |
| 99 // - PLATFORM_FILE_ERROR_NOT_FOUND if |url| does not exist. |
| 100 // - PLATFORM_FILE_ERROR_NOT_A_FILE if |url| is not a file. |
| 101 // |
| 102 void RemoveFile(const FileSystemURL& url, |
| 103 const StatusCallback& callback); |
| 104 |
| 105 // Removes a single empty directory. |
| 106 // |
| 107 // This returns: |
| 108 // - PLATFORM_FILE_ERROR_NOT_FOUND if |url| does not exist. |
| 109 // - PLATFORM_FILE_ERROR_NOT_A_DIRECTORY if |url| is not a directory. |
| 110 // - PLATFORM_FILE_ERROR_NOT_EMPTY if |url| is not empty. |
| 111 // |
| 112 void RemoveDirectory(const FileSystemURL& url, |
| 113 const StatusCallback& callback); |
| 114 |
85 // Synchronously gets the platform path for the given |url|. | 115 // Synchronously gets the platform path for the given |url|. |
86 void SyncGetPlatformPath(const FileSystemURL& url, FilePath* platform_path); | 116 void SyncGetPlatformPath(const FileSystemURL& url, FilePath* platform_path); |
87 | 117 |
88 private: | 118 private: |
89 class ScopedUpdateNotifier; | 119 class ScopedUpdateNotifier; |
90 | 120 |
91 enum SetUpMode { | 121 enum SetUpMode { |
92 SETUP_FOR_READ, | 122 SETUP_FOR_READ, |
93 SETUP_FOR_WRITE, | 123 SETUP_FOR_WRITE, |
94 SETUP_FOR_CREATE, | 124 SETUP_FOR_CREATE, |
95 }; | 125 }; |
96 | 126 |
97 // Only MountPointProviders or testing class can create a | 127 // Only MountPointProviders or testing class can create a |
98 // new operation directly. | 128 // new operation directly. |
99 friend class FileSystemTestHelper; | 129 friend class FileSystemTestHelper; |
100 friend class IsolatedMountPointProvider; | 130 friend class IsolatedMountPointProvider; |
101 friend class SandboxMountPointProvider; | 131 friend class SandboxMountPointProvider; |
102 friend class TestMountPointProvider; | 132 friend class TestMountPointProvider; |
103 friend class chromeos::CrosMountPointProvider; | 133 friend class chromeos::CrosMountPointProvider; |
104 | 134 |
105 friend class LocalFileSystemOperationTest; | 135 friend class LocalFileSystemOperationTest; |
106 friend class LocalFileSystemOperationWriteTest; | 136 friend class LocalFileSystemOperationWriteTest; |
107 friend class FileWriterDelegateTest; | 137 friend class FileWriterDelegateTest; |
108 friend class FileSystemQuotaTest; | 138 friend class FileSystemQuotaTest; |
109 friend class LocalFileSystemTestOriginHelper; | 139 friend class LocalFileSystemTestOriginHelper; |
110 | 140 |
| 141 friend class RemoveOperationDelegate; |
111 friend class SyncableFileSystemOperation; | 142 friend class SyncableFileSystemOperation; |
112 | 143 |
113 LocalFileSystemOperation( | 144 LocalFileSystemOperation( |
114 FileSystemContext* file_system_context, | 145 FileSystemContext* file_system_context, |
115 scoped_ptr<FileSystemOperationContext> operation_context); | 146 scoped_ptr<FileSystemOperationContext> operation_context); |
116 | 147 |
117 FileSystemContext* file_system_context() const { | 148 FileSystemContext* file_system_context() const { |
118 return file_system_context_; | 149 return file_system_context_; |
119 } | 150 } |
120 | 151 |
121 FileSystemOperationContext* operation_context() const { | 152 FileSystemOperationContext* operation_context() const { |
| 153 if (overriding_operation_context_) |
| 154 return overriding_operation_context_; |
122 return operation_context_.get(); | 155 return operation_context_.get(); |
123 } | 156 } |
124 | 157 |
125 // Queries the quota and usage and then runs the given |task|. | 158 // Queries the quota and usage and then runs the given |task|. |
126 // If an error occurs during the quota query it runs |error_callback| instead. | 159 // If an error occurs during the quota query it runs |error_callback| instead. |
127 void GetUsageAndQuotaThenRunTask( | 160 void GetUsageAndQuotaThenRunTask( |
128 const FileSystemURL& url, | 161 const FileSystemURL& url, |
129 const base::Closure& task, | 162 const base::Closure& task, |
130 const base::Closure& error_callback); | 163 const base::Closure& error_callback); |
131 | 164 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 | 213 |
181 // Callback for CreateFile for |exclusive|=false cases. | 214 // Callback for CreateFile for |exclusive|=false cases. |
182 void DidEnsureFileExistsNonExclusive(const StatusCallback& callback, | 215 void DidEnsureFileExistsNonExclusive(const StatusCallback& callback, |
183 base::PlatformFileError rv, | 216 base::PlatformFileError rv, |
184 bool created); | 217 bool created); |
185 | 218 |
186 // Generic callback that translates platform errors to WebKit error codes. | 219 // Generic callback that translates platform errors to WebKit error codes. |
187 void DidFinishFileOperation(const StatusCallback& callback, | 220 void DidFinishFileOperation(const StatusCallback& callback, |
188 base::PlatformFileError rv); | 221 base::PlatformFileError rv); |
189 | 222 |
| 223 // Generic callback when we delegated the operation. |
| 224 void DidFinishDelegatedOperation(const StatusCallback& callback, |
| 225 base::PlatformFileError rv); |
| 226 |
190 void DidDirectoryExists(const StatusCallback& callback, | 227 void DidDirectoryExists(const StatusCallback& callback, |
191 base::PlatformFileError rv, | 228 base::PlatformFileError rv, |
192 const base::PlatformFileInfo& file_info, | 229 const base::PlatformFileInfo& file_info, |
193 const FilePath& unused); | 230 const FilePath& unused); |
194 void DidFileExists(const StatusCallback& callback, | 231 void DidFileExists(const StatusCallback& callback, |
195 base::PlatformFileError rv, | 232 base::PlatformFileError rv, |
196 const base::PlatformFileInfo& file_info, | 233 const base::PlatformFileInfo& file_info, |
197 const FilePath& unused); | 234 const FilePath& unused); |
198 void DidGetMetadata(const GetMetadataCallback& callback, | 235 void DidGetMetadata(const GetMetadataCallback& callback, |
199 base::PlatformFileError rv, | 236 base::PlatformFileError rv, |
(...skipping 23 matching lines...) Expand all Loading... |
223 // Checks the validity of a given |url| and populates |file_util| for |mode|. | 260 // Checks the validity of a given |url| and populates |file_util| for |mode|. |
224 base::PlatformFileError SetUp( | 261 base::PlatformFileError SetUp( |
225 const FileSystemURL& url, | 262 const FileSystemURL& url, |
226 FileSystemFileUtil** file_util, | 263 FileSystemFileUtil** file_util, |
227 SetUpMode mode); | 264 SetUpMode mode); |
228 | 265 |
229 // Used only for internal assertions. | 266 // Used only for internal assertions. |
230 // Returns false if there's another inflight pending operation. | 267 // Returns false if there's another inflight pending operation. |
231 bool SetPendingOperationType(OperationType type); | 268 bool SetPendingOperationType(OperationType type); |
232 | 269 |
| 270 // Overrides this operation's operation context by given |context|. |
| 271 // This operation won't own |context| and the |context| needs to outlive |
| 272 // this operation. |
| 273 // |
| 274 // Called only from operation delegates when they create sub-operations |
| 275 // for performing a recursive operation. |
| 276 void set_overriding_operation_context(FileSystemOperationContext* context) { |
| 277 overriding_operation_context_ = context; |
| 278 } |
| 279 |
| 280 // Sets a termination callback which is called when this instance goes away |
| 281 // (indicates the operation is finished). |
| 282 void set_termination_callback(const base::Closure& closure) { |
| 283 termination_callback_ = closure; |
| 284 } |
| 285 |
233 scoped_refptr<FileSystemContext> file_system_context_; | 286 scoped_refptr<FileSystemContext> file_system_context_; |
234 | 287 |
235 scoped_ptr<FileSystemOperationContext> operation_context_; | 288 scoped_ptr<FileSystemOperationContext> operation_context_; |
236 FileSystemFileUtil* src_util_; // Not owned. | 289 FileSystemFileUtil* src_util_; // Not owned. |
237 FileSystemFileUtil* dest_util_; // Not owned. | 290 FileSystemFileUtil* dest_util_; // Not owned. |
238 | 291 |
| 292 FileSystemOperationContext* overriding_operation_context_; |
| 293 |
| 294 // A callback that is called when this instance goes away. |
| 295 base::Closure termination_callback_; |
| 296 |
239 // Indicates if this operation is for cross filesystem operation or not. | 297 // Indicates if this operation is for cross filesystem operation or not. |
240 // TODO(kinuko): This should be cleaned up. | 298 // TODO(kinuko): This should be cleaned up. |
241 bool is_cross_operation_; | 299 bool is_cross_operation_; |
242 | 300 |
243 // This is set before any write operations to dispatch | 301 // This is set before any write operations to dispatch |
244 // FileUpdateObserver::StartUpdate and FileUpdateObserver::EndUpdate. | 302 // FileUpdateObserver::StartUpdate and FileUpdateObserver::EndUpdate. |
245 ScopedVector<ScopedUpdateNotifier> scoped_update_notifiers_; | 303 ScopedVector<ScopedUpdateNotifier> scoped_update_notifiers_; |
246 | 304 |
247 // These are all used only by Write(). | 305 // These are all used only by Write(). |
248 friend class FileWriterDelegate; | 306 friend class FileWriterDelegate; |
249 scoped_ptr<FileWriterDelegate> file_writer_delegate_; | 307 scoped_ptr<FileWriterDelegate> file_writer_delegate_; |
250 | 308 |
| 309 scoped_ptr<RemoveOperationDelegate> remove_operation_delegate_; |
| 310 |
251 // write_callback is kept in this class for so that we can dispatch it when | 311 // write_callback is kept in this class for so that we can dispatch it when |
252 // the operation is cancelled. calcel_callback is kept for canceling a | 312 // the operation is cancelled. calcel_callback is kept for canceling a |
253 // Truncate() operation. We can't actually stop Truncate in another thread; | 313 // Truncate() operation. We can't actually stop Truncate in another thread; |
254 // after it resumed from the working thread, cancellation takes place. | 314 // after it resumed from the working thread, cancellation takes place. |
255 WriteCallback write_callback_; | 315 WriteCallback write_callback_; |
256 StatusCallback cancel_callback_; | 316 StatusCallback cancel_callback_; |
257 | 317 |
258 // Used only by OpenFile, in order to clone the file handle back to the | 318 // Used only by OpenFile, in order to clone the file handle back to the |
259 // requesting process. | 319 // requesting process. |
260 base::ProcessHandle peer_handle_; | 320 base::ProcessHandle peer_handle_; |
261 | 321 |
262 // A flag to make sure we call operation only once per instance. | 322 // A flag to make sure we call operation only once per instance. |
263 OperationType pending_operation_; | 323 OperationType pending_operation_; |
264 | 324 |
265 // LocalFileSystemOperation instance is usually deleted upon completion but | 325 // LocalFileSystemOperation instance is usually deleted upon completion but |
266 // could be deleted while it has inflight callbacks when Cancel is called. | 326 // could be deleted while it has inflight callbacks when Cancel is called. |
267 base::WeakPtrFactory<LocalFileSystemOperation> weak_factory_; | 327 base::WeakPtrFactory<LocalFileSystemOperation> weak_factory_; |
268 | 328 |
269 DISALLOW_COPY_AND_ASSIGN(LocalFileSystemOperation); | 329 DISALLOW_COPY_AND_ASSIGN(LocalFileSystemOperation); |
270 }; | 330 }; |
271 | 331 |
272 } // namespace fileapi | 332 } // namespace fileapi |
273 | 333 |
274 #endif // WEBKIT_FILEAPI_LOCAL_FILE_SYSTEM_OPERATION_H_ | 334 #endif // WEBKIT_FILEAPI_LOCAL_FILE_SYSTEM_OPERATION_H_ |
OLD | NEW |