| 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 class RecursiveOperationDelegate; |
| 29 | 29 |
| 30 // FileSystemOperation implementation for local file systems. | 30 // FileSystemOperation implementation for local file systems. |
| 31 class WEBKIT_STORAGE_EXPORT LocalFileSystemOperation | 31 class WEBKIT_STORAGE_EXPORT LocalFileSystemOperation |
| 32 : public NON_EXPORTED_BASE(FileSystemOperation) { | 32 : public NON_EXPORTED_BASE(FileSystemOperation) { |
| 33 public: | 33 public: |
| 34 virtual ~LocalFileSystemOperation(); | 34 virtual ~LocalFileSystemOperation(); |
| 35 | 35 |
| 36 // FileSystemOperation overrides. | 36 // FileSystemOperation overrides. |
| 37 virtual void CreateFile(const FileSystemURL& url, | 37 virtual void CreateFile(const FileSystemURL& url, |
| 38 bool exclusive, | 38 bool exclusive, |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 // Removes a single empty directory. | 105 // Removes a single empty directory. |
| 106 // | 106 // |
| 107 // This returns: | 107 // This returns: |
| 108 // - PLATFORM_FILE_ERROR_NOT_FOUND if |url| does not exist. | 108 // - PLATFORM_FILE_ERROR_NOT_FOUND if |url| does not exist. |
| 109 // - PLATFORM_FILE_ERROR_NOT_A_DIRECTORY if |url| is not a directory. | 109 // - PLATFORM_FILE_ERROR_NOT_A_DIRECTORY if |url| is not a directory. |
| 110 // - PLATFORM_FILE_ERROR_NOT_EMPTY if |url| is not empty. | 110 // - PLATFORM_FILE_ERROR_NOT_EMPTY if |url| is not empty. |
| 111 // | 111 // |
| 112 void RemoveDirectory(const FileSystemURL& url, | 112 void RemoveDirectory(const FileSystemURL& url, |
| 113 const StatusCallback& callback); | 113 const StatusCallback& callback); |
| 114 | 114 |
| 115 // Copies a file from |src_url| to |dest_url|. |
| 116 // This must be called for files that belong to the same filesystem |
| 117 // (i.e. type() and origin() of the |src_url| and |dest_url| must match). |
| 118 // |
| 119 // This returns: |
| 120 // - PLATFORM_FILE_ERROR_NOT_FOUND if |src_url| |
| 121 // or the parent directory of |dest_url| does not exist. |
| 122 // - PLATFORM_FILE_ERROR_NOT_A_FILE if |src_url| exists but is not a file. |
| 123 // - PLATFORM_FILE_ERROR_INVALID_OPERATION if |dest_url| exists and |
| 124 // is not a file. |
| 125 // - PLATFORM_FILE_ERROR_FAILED if |dest_url| does not exist and |
| 126 // its parent path is a file. |
| 127 // |
| 128 void CopyFileLocal(const FileSystemURL& src_url, |
| 129 const FileSystemURL& dest_url, |
| 130 const StatusCallback& callback); |
| 131 |
| 132 // Moves a local file from |src_url| to |dest_url|. |
| 133 // This must be called for files that belong to the same filesystem |
| 134 // (i.e. type() and origin() of the |src_url| and |dest_url| must match). |
| 135 // |
| 136 // This returns: |
| 137 // - PLATFORM_FILE_ERROR_NOT_FOUND if |src_url| |
| 138 // or the parent directory of |dest_url| does not exist. |
| 139 // - PLATFORM_FILE_ERROR_NOT_A_FILE if |src_url| exists but is not a file. |
| 140 // - PLATFORM_FILE_ERROR_INVALID_OPERATION if |dest_url| exists and |
| 141 // is not a file. |
| 142 // - PLATFORM_FILE_ERROR_FAILED if |dest_url| does not exist and |
| 143 // its parent path is a file. |
| 144 // |
| 145 void MoveFileLocal(const FileSystemURL& src_url, |
| 146 const FileSystemURL& dest_url, |
| 147 const StatusCallback& callback); |
| 148 |
| 115 // Synchronously gets the platform path for the given |url|. | 149 // Synchronously gets the platform path for the given |url|. |
| 116 void SyncGetPlatformPath(const FileSystemURL& url, FilePath* platform_path); | 150 void SyncGetPlatformPath(const FileSystemURL& url, FilePath* platform_path); |
| 117 | 151 |
| 118 private: | 152 private: |
| 119 class ScopedUpdateNotifier; | 153 class ScopedUpdateNotifier; |
| 120 | 154 |
| 121 enum SetUpMode { | 155 enum SetUpMode { |
| 122 SETUP_FOR_READ, | 156 SETUP_FOR_READ, |
| 123 SETUP_FOR_WRITE, | 157 SETUP_FOR_WRITE, |
| 124 SETUP_FOR_CREATE, | 158 SETUP_FOR_CREATE, |
| 125 }; | 159 }; |
| 126 | 160 |
| 127 // Only MountPointProviders or testing class can create a | 161 // Only MountPointProviders or testing class can create a |
| 128 // new operation directly. | 162 // new operation directly. |
| 129 friend class FileSystemTestHelper; | 163 friend class FileSystemTestHelper; |
| 130 friend class IsolatedMountPointProvider; | 164 friend class IsolatedMountPointProvider; |
| 131 friend class SandboxMountPointProvider; | 165 friend class SandboxMountPointProvider; |
| 132 friend class TestMountPointProvider; | 166 friend class TestMountPointProvider; |
| 133 friend class chromeos::CrosMountPointProvider; | 167 friend class chromeos::CrosMountPointProvider; |
| 134 | 168 |
| 135 friend class LocalFileSystemOperationTest; | 169 friend class LocalFileSystemOperationTest; |
| 136 friend class LocalFileSystemOperationWriteTest; | 170 friend class LocalFileSystemOperationWriteTest; |
| 137 friend class FileWriterDelegateTest; | 171 friend class FileWriterDelegateTest; |
| 138 friend class FileSystemQuotaTest; | 172 friend class FileSystemQuotaTest; |
| 139 friend class LocalFileSystemTestOriginHelper; | 173 friend class LocalFileSystemTestOriginHelper; |
| 140 | 174 |
| 141 friend class RemoveOperationDelegate; | 175 friend class RecursiveOperationDelegate; |
| 176 friend class CrossOperationDelegate; |
| 142 friend class SyncableFileSystemOperation; | 177 friend class SyncableFileSystemOperation; |
| 143 | 178 |
| 144 LocalFileSystemOperation( | 179 LocalFileSystemOperation( |
| 145 FileSystemContext* file_system_context, | 180 FileSystemContext* file_system_context, |
| 146 scoped_ptr<FileSystemOperationContext> operation_context); | 181 scoped_ptr<FileSystemOperationContext> operation_context); |
| 147 | 182 |
| 148 FileSystemContext* file_system_context() const { | 183 FileSystemContext* file_system_context() const { |
| 149 return file_system_context_; | 184 return file_system_context_; |
| 150 } | 185 } |
| 151 | 186 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 base::PlatformFileError result); | 220 base::PlatformFileError result); |
| 186 | 221 |
| 187 // The 'body' methods that perform the actual work (i.e. posting the | 222 // The 'body' methods that perform the actual work (i.e. posting the |
| 188 // file task on proxy_) after the quota check. | 223 // file task on proxy_) after the quota check. |
| 189 void DoCreateFile(const FileSystemURL& url, | 224 void DoCreateFile(const FileSystemURL& url, |
| 190 const StatusCallback& callback, bool exclusive); | 225 const StatusCallback& callback, bool exclusive); |
| 191 void DoCreateDirectory(const FileSystemURL& url, | 226 void DoCreateDirectory(const FileSystemURL& url, |
| 192 const StatusCallback& callback, | 227 const StatusCallback& callback, |
| 193 bool exclusive, | 228 bool exclusive, |
| 194 bool recursive); | 229 bool recursive); |
| 195 void DoCopy(const FileSystemURL& src, | 230 void DoCopyFileLocal(const FileSystemURL& src, |
| 196 const FileSystemURL& dest, | 231 const FileSystemURL& dest, |
| 197 const StatusCallback& callback); | 232 const StatusCallback& callback); |
| 233 void DoMoveFileLocal(const FileSystemURL& src, |
| 234 const FileSystemURL& dest, |
| 235 const StatusCallback& callback); |
| 198 void DoCopyInForeignFile(const FilePath& src_local_disk_file_path, | 236 void DoCopyInForeignFile(const FilePath& src_local_disk_file_path, |
| 199 const FileSystemURL& dest, | 237 const FileSystemURL& dest, |
| 200 const StatusCallback& callback); | 238 const StatusCallback& callback); |
| 201 void DoMove(const FileSystemURL& src, | |
| 202 const FileSystemURL& dest, | |
| 203 const StatusCallback& callback); | |
| 204 void DoTruncate(const FileSystemURL& url, | 239 void DoTruncate(const FileSystemURL& url, |
| 205 const StatusCallback& callback, int64 length); | 240 const StatusCallback& callback, int64 length); |
| 206 void DoOpenFile(const FileSystemURL& url, | 241 void DoOpenFile(const FileSystemURL& url, |
| 207 const OpenFileCallback& callback, int file_flags); | 242 const OpenFileCallback& callback, int file_flags); |
| 208 | 243 |
| 209 // Callback for CreateFile for |exclusive|=true cases. | 244 // Callback for CreateFile for |exclusive|=true cases. |
| 210 void DidEnsureFileExistsExclusive(const StatusCallback& callback, | 245 void DidEnsureFileExistsExclusive(const StatusCallback& callback, |
| 211 base::PlatformFileError rv, | 246 base::PlatformFileError rv, |
| 212 bool created); | 247 bool created); |
| 213 | 248 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 | 314 |
| 280 // Sets a termination callback which is called when this instance goes away | 315 // Sets a termination callback which is called when this instance goes away |
| 281 // (indicates the operation is finished). | 316 // (indicates the operation is finished). |
| 282 void set_termination_callback(const base::Closure& closure) { | 317 void set_termination_callback(const base::Closure& closure) { |
| 283 termination_callback_ = closure; | 318 termination_callback_ = closure; |
| 284 } | 319 } |
| 285 | 320 |
| 286 scoped_refptr<FileSystemContext> file_system_context_; | 321 scoped_refptr<FileSystemContext> file_system_context_; |
| 287 | 322 |
| 288 scoped_ptr<FileSystemOperationContext> operation_context_; | 323 scoped_ptr<FileSystemOperationContext> operation_context_; |
| 289 FileSystemFileUtil* src_util_; // Not owned. | 324 FileSystemFileUtil* file_util_; // Not owned. |
| 290 FileSystemFileUtil* dest_util_; // Not owned. | |
| 291 | 325 |
| 292 FileSystemOperationContext* overriding_operation_context_; | 326 FileSystemOperationContext* overriding_operation_context_; |
| 293 | 327 |
| 294 // A callback that is called when this instance goes away. | 328 // A callback that is called when this instance goes away. |
| 295 base::Closure termination_callback_; | 329 base::Closure termination_callback_; |
| 296 | 330 |
| 297 // Indicates if this operation is for cross filesystem operation or not. | |
| 298 // TODO(kinuko): This should be cleaned up. | |
| 299 bool is_cross_operation_; | |
| 300 | |
| 301 // This is set before any write operations to dispatch | 331 // This is set before any write operations to dispatch |
| 302 // FileUpdateObserver::StartUpdate and FileUpdateObserver::EndUpdate. | 332 // FileUpdateObserver::StartUpdate and FileUpdateObserver::EndUpdate. |
| 303 ScopedVector<ScopedUpdateNotifier> scoped_update_notifiers_; | 333 ScopedVector<ScopedUpdateNotifier> scoped_update_notifiers_; |
| 304 | 334 |
| 305 // These are all used only by Write(). | 335 // These are all used only by Write(). |
| 306 friend class FileWriterDelegate; | 336 friend class FileWriterDelegate; |
| 307 scoped_ptr<FileWriterDelegate> file_writer_delegate_; | 337 scoped_ptr<FileWriterDelegate> file_writer_delegate_; |
| 308 | 338 |
| 309 scoped_ptr<RemoveOperationDelegate> remove_operation_delegate_; | 339 scoped_ptr<RecursiveOperationDelegate> recursive_operation_delegate_; |
| 310 | 340 |
| 311 // write_callback is kept in this class for so that we can dispatch it when | 341 // write_callback is kept in this class for so that we can dispatch it when |
| 312 // the operation is cancelled. calcel_callback is kept for canceling a | 342 // the operation is cancelled. calcel_callback is kept for canceling a |
| 313 // Truncate() operation. We can't actually stop Truncate in another thread; | 343 // Truncate() operation. We can't actually stop Truncate in another thread; |
| 314 // after it resumed from the working thread, cancellation takes place. | 344 // after it resumed from the working thread, cancellation takes place. |
| 315 WriteCallback write_callback_; | 345 WriteCallback write_callback_; |
| 316 StatusCallback cancel_callback_; | 346 StatusCallback cancel_callback_; |
| 317 | 347 |
| 318 // Used only by OpenFile, in order to clone the file handle back to the | 348 // Used only by OpenFile, in order to clone the file handle back to the |
| 319 // requesting process. | 349 // requesting process. |
| 320 base::ProcessHandle peer_handle_; | 350 base::ProcessHandle peer_handle_; |
| 321 | 351 |
| 322 // A flag to make sure we call operation only once per instance. | 352 // A flag to make sure we call operation only once per instance. |
| 323 OperationType pending_operation_; | 353 OperationType pending_operation_; |
| 324 | 354 |
| 325 // LocalFileSystemOperation instance is usually deleted upon completion but | 355 // LocalFileSystemOperation instance is usually deleted upon completion but |
| 326 // could be deleted while it has inflight callbacks when Cancel is called. | 356 // could be deleted while it has inflight callbacks when Cancel is called. |
| 327 base::WeakPtrFactory<LocalFileSystemOperation> weak_factory_; | 357 base::WeakPtrFactory<LocalFileSystemOperation> weak_factory_; |
| 328 | 358 |
| 329 DISALLOW_COPY_AND_ASSIGN(LocalFileSystemOperation); | 359 DISALLOW_COPY_AND_ASSIGN(LocalFileSystemOperation); |
| 330 }; | 360 }; |
| 331 | 361 |
| 332 } // namespace fileapi | 362 } // namespace fileapi |
| 333 | 363 |
| 334 #endif // WEBKIT_FILEAPI_LOCAL_FILE_SYSTEM_OPERATION_H_ | 364 #endif // WEBKIT_FILEAPI_LOCAL_FILE_SYSTEM_OPERATION_H_ |
| OLD | NEW |