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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 // Checks the validity of a given |url| and populates |file_util| for |mode|. | 256 // Checks the validity of a given |url| and populates |file_util| for |mode|. |
224 base::PlatformFileError SetUp( | 257 base::PlatformFileError SetUp( |
225 const FileSystemURL& url, | 258 const FileSystemURL& url, |
226 FileSystemFileUtil** file_util, | 259 FileSystemFileUtil** file_util, |
227 SetUpMode mode); | 260 SetUpMode mode); |
228 | 261 |
229 // Used only for internal assertions. | 262 // Used only for internal assertions. |
230 // Returns false if there's another inflight pending operation. | 263 // Returns false if there's another inflight pending operation. |
231 bool SetPendingOperationType(OperationType type); | 264 bool SetPendingOperationType(OperationType type); |
232 | 265 |
| 266 // Overrides this operation's operation context by given |context|. |
| 267 // This operation won't own |context| and the |context| needs to outlive |
| 268 // this operation. |
| 269 // |
| 270 // Called only from operation delegates when they create sub-operations |
| 271 // for performing a recursive operation. |
| 272 void set_overriding_operation_context(FileSystemOperationContext* context) { |
| 273 overriding_operation_context_ = context; |
| 274 } |
| 275 |
233 scoped_refptr<FileSystemContext> file_system_context_; | 276 scoped_refptr<FileSystemContext> file_system_context_; |
234 | 277 |
235 scoped_ptr<FileSystemOperationContext> operation_context_; | 278 scoped_ptr<FileSystemOperationContext> operation_context_; |
236 FileSystemFileUtil* src_util_; // Not owned. | 279 FileSystemFileUtil* src_util_; // Not owned. |
237 FileSystemFileUtil* dest_util_; // Not owned. | 280 FileSystemFileUtil* dest_util_; // Not owned. |
238 | 281 |
| 282 FileSystemOperationContext* overriding_operation_context_; |
| 283 |
239 // Indicates if this operation is for cross filesystem operation or not. | 284 // Indicates if this operation is for cross filesystem operation or not. |
240 // TODO(kinuko): This should be cleaned up. | 285 // TODO(kinuko): This should be cleaned up. |
241 bool is_cross_operation_; | 286 bool is_cross_operation_; |
242 | 287 |
243 // This is set before any write operations to dispatch | 288 // This is set before any write operations to dispatch |
244 // FileUpdateObserver::StartUpdate and FileUpdateObserver::EndUpdate. | 289 // FileUpdateObserver::StartUpdate and FileUpdateObserver::EndUpdate. |
245 ScopedVector<ScopedUpdateNotifier> scoped_update_notifiers_; | 290 ScopedVector<ScopedUpdateNotifier> scoped_update_notifiers_; |
246 | 291 |
247 // These are all used only by Write(). | 292 // These are all used only by Write(). |
248 friend class FileWriterDelegate; | 293 friend class FileWriterDelegate; |
249 scoped_ptr<FileWriterDelegate> file_writer_delegate_; | 294 scoped_ptr<FileWriterDelegate> file_writer_delegate_; |
250 | 295 |
| 296 scoped_ptr<RemoveOperationDelegate> remove_operation_delegate_; |
| 297 |
251 // write_callback is kept in this class for so that we can dispatch it when | 298 // 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 | 299 // the operation is cancelled. calcel_callback is kept for canceling a |
253 // Truncate() operation. We can't actually stop Truncate in another thread; | 300 // Truncate() operation. We can't actually stop Truncate in another thread; |
254 // after it resumed from the working thread, cancellation takes place. | 301 // after it resumed from the working thread, cancellation takes place. |
255 WriteCallback write_callback_; | 302 WriteCallback write_callback_; |
256 StatusCallback cancel_callback_; | 303 StatusCallback cancel_callback_; |
257 | 304 |
258 // Used only by OpenFile, in order to clone the file handle back to the | 305 // Used only by OpenFile, in order to clone the file handle back to the |
259 // requesting process. | 306 // requesting process. |
260 base::ProcessHandle peer_handle_; | 307 base::ProcessHandle peer_handle_; |
261 | 308 |
262 // A flag to make sure we call operation only once per instance. | 309 // A flag to make sure we call operation only once per instance. |
263 OperationType pending_operation_; | 310 OperationType pending_operation_; |
264 | 311 |
265 // LocalFileSystemOperation instance is usually deleted upon completion but | 312 // LocalFileSystemOperation instance is usually deleted upon completion but |
266 // could be deleted while it has inflight callbacks when Cancel is called. | 313 // could be deleted while it has inflight callbacks when Cancel is called. |
267 base::WeakPtrFactory<LocalFileSystemOperation> weak_factory_; | 314 base::WeakPtrFactory<LocalFileSystemOperation> weak_factory_; |
268 | 315 |
269 DISALLOW_COPY_AND_ASSIGN(LocalFileSystemOperation); | 316 DISALLOW_COPY_AND_ASSIGN(LocalFileSystemOperation); |
270 }; | 317 }; |
271 | 318 |
272 } // namespace fileapi | 319 } // namespace fileapi |
273 | 320 |
274 #endif // WEBKIT_FILEAPI_LOCAL_FILE_SYSTEM_OPERATION_H_ | 321 #endif // WEBKIT_FILEAPI_LOCAL_FILE_SYSTEM_OPERATION_H_ |
OLD | NEW |