| 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 RecursiveOperationDelegate; |
| 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 |
| 115 // Copies a local file from |src_url| to |dest_url|. |
| 116 // This must be called for the files that belong to the same filesystem |
| 117 // (i.e. the type() and the origin() of the |src_url| and |dest_url| must |
| 118 // match). |
| 119 // |
| 120 // This returns: |
| 121 // - PLATFORM_FILE_ERROR_NOT_FOUND if |src_url| |
| 122 // or the parent directory of |dest_url| does not exist. |
| 123 // - PLATFORM_FILE_ERROR_NOT_A_FILE if |src_url| exists but is not a file. |
| 124 // - PLATFORM_FILE_ERROR_INVALID_OPERATION if |dest_url| exists and |
| 125 // is not a file. |
| 126 // - PLATFORM_FILE_ERROR_FAILED if |dest_url| does not exist and |
| 127 // its parent path is a file. |
| 128 // |
| 129 void CopyLocalFile(const FileSystemURL& src_url, |
| 130 const FileSystemURL& dest_url, |
| 131 const StatusCallback& callback); |
| 132 |
| 133 // Moves a local file from |src_url| to |dest_url|. |
| 134 // This must be called for the files that belong to the same filesystem |
| 135 // (i.e. the type() and the origin() of the |src_url| and |dest_url| must |
| 136 // match). |
| 137 // |
| 138 // This returns: |
| 139 // - PLATFORM_FILE_ERROR_NOT_FOUND if |src_url| |
| 140 // or the parent directory of |dest_url| does not exist. |
| 141 // - PLATFORM_FILE_ERROR_NOT_A_FILE if |src_url| exists but is not a file. |
| 142 // - PLATFORM_FILE_ERROR_INVALID_OPERATION if |dest_url| exists and |
| 143 // is not a file. |
| 144 // - PLATFORM_FILE_ERROR_FAILED if |dest_url| does not exist and |
| 145 // its parent path is a file. |
| 146 // |
| 147 void MoveLocalFile(const FileSystemURL& src_url, |
| 148 const FileSystemURL& dest_url, |
| 149 const StatusCallback& callback); |
| 150 |
| 85 // Synchronously gets the platform path for the given |url|. | 151 // Synchronously gets the platform path for the given |url|. |
| 86 void SyncGetPlatformPath(const FileSystemURL& url, FilePath* platform_path); | 152 void SyncGetPlatformPath(const FileSystemURL& url, FilePath* platform_path); |
| 87 | 153 |
| 88 private: | 154 private: |
| 89 class ScopedUpdateNotifier; | 155 class ScopedUpdateNotifier; |
| 90 | 156 |
| 91 enum SetUpMode { | 157 enum SetUpMode { |
| 92 SETUP_FOR_READ, | 158 SETUP_FOR_READ, |
| 93 SETUP_FOR_WRITE, | 159 SETUP_FOR_WRITE, |
| 94 SETUP_FOR_CREATE, | 160 SETUP_FOR_CREATE, |
| 95 }; | 161 }; |
| 96 | 162 |
| 97 // Only MountPointProviders or testing class can create a | 163 // Only MountPointProviders or testing class can create a |
| 98 // new operation directly. | 164 // new operation directly. |
| 99 friend class FileSystemTestHelper; | 165 friend class FileSystemTestHelper; |
| 100 friend class IsolatedMountPointProvider; | 166 friend class IsolatedMountPointProvider; |
| 101 friend class SandboxMountPointProvider; | 167 friend class SandboxMountPointProvider; |
| 102 friend class TestMountPointProvider; | 168 friend class TestMountPointProvider; |
| 103 friend class chromeos::CrosMountPointProvider; | 169 friend class chromeos::CrosMountPointProvider; |
| 104 | 170 |
| 105 friend class LocalFileSystemOperationTest; | 171 friend class LocalFileSystemOperationTest; |
| 106 friend class LocalFileSystemOperationWriteTest; | 172 friend class LocalFileSystemOperationWriteTest; |
| 107 friend class FileWriterDelegateTest; | 173 friend class FileWriterDelegateTest; |
| 108 friend class FileSystemQuotaTest; | 174 friend class FileSystemQuotaTest; |
| 109 friend class LocalFileSystemTestOriginHelper; | 175 friend class LocalFileSystemTestOriginHelper; |
| 110 | 176 |
| 177 friend class RecursiveOperationDelegate; |
| 178 friend class CrossOperationDelegate; |
| 111 friend class SyncableFileSystemOperation; | 179 friend class SyncableFileSystemOperation; |
| 112 | 180 |
| 113 LocalFileSystemOperation( | 181 LocalFileSystemOperation( |
| 114 FileSystemContext* file_system_context, | 182 FileSystemContext* file_system_context, |
| 115 scoped_ptr<FileSystemOperationContext> operation_context); | 183 scoped_ptr<FileSystemOperationContext> operation_context); |
| 116 | 184 |
| 117 FileSystemContext* file_system_context() const { | 185 FileSystemContext* file_system_context() const { |
| 118 return operation_context_->file_system_context(); | 186 return operation_context()->file_system_context(); |
| 119 } | 187 } |
| 120 | 188 |
| 121 FileSystemOperationContext* operation_context() const { | 189 FileSystemOperationContext* operation_context() const { |
| 190 if (overriding_operation_context_) |
| 191 return overriding_operation_context_; |
| 122 return operation_context_.get(); | 192 return operation_context_.get(); |
| 123 } | 193 } |
| 124 | 194 |
| 125 // The unit tests that need to specify and control the lifetime of the | 195 // The unit tests that need to specify and control the lifetime of the |
| 126 // file_util on their own should call this before performing the actual | 196 // file_util on their own should call this before performing the actual |
| 127 // operation. If it is given it will not be overwritten by the class. | 197 // operation. If it is given it will not be overwritten by the class. |
| 128 void set_override_file_util(FileSystemFileUtil* file_util) { | 198 void set_override_file_util(FileSystemFileUtil* file_util) { |
| 129 src_util_ = file_util; | 199 file_util_ = file_util; |
| 130 dest_util_ = file_util; | |
| 131 } | 200 } |
| 132 | 201 |
| 133 // Queries the quota and usage and then runs the given |task|. | 202 // Queries the quota and usage and then runs the given |task|. |
| 134 // If an error occurs during the quota query it runs |error_callback| instead. | 203 // If an error occurs during the quota query it runs |error_callback| instead. |
| 135 void GetUsageAndQuotaThenRunTask( | 204 void GetUsageAndQuotaThenRunTask( |
| 136 const FileSystemURL& url, | 205 const FileSystemURL& url, |
| 137 const base::Closure& task, | 206 const base::Closure& task, |
| 138 const base::Closure& error_callback); | 207 const base::Closure& error_callback); |
| 139 | 208 |
| 140 // Called after the quota info is obtained from the quota manager | 209 // Called after the quota info is obtained from the quota manager |
| (...skipping 19 matching lines...) Expand all Loading... |
| 160 base::PlatformFileError result); | 229 base::PlatformFileError result); |
| 161 | 230 |
| 162 // The 'body' methods that perform the actual work (i.e. posting the | 231 // The 'body' methods that perform the actual work (i.e. posting the |
| 163 // file task on proxy_) after the quota check. | 232 // file task on proxy_) after the quota check. |
| 164 void DoCreateFile(const FileSystemURL& url, | 233 void DoCreateFile(const FileSystemURL& url, |
| 165 const StatusCallback& callback, bool exclusive); | 234 const StatusCallback& callback, bool exclusive); |
| 166 void DoCreateDirectory(const FileSystemURL& url, | 235 void DoCreateDirectory(const FileSystemURL& url, |
| 167 const StatusCallback& callback, | 236 const StatusCallback& callback, |
| 168 bool exclusive, | 237 bool exclusive, |
| 169 bool recursive); | 238 bool recursive); |
| 170 void DoCopy(const FileSystemURL& src, | 239 void DoCopyLocalFile(const FileSystemURL& src, |
| 171 const FileSystemURL& dest, | 240 const FileSystemURL& dest, |
| 172 const StatusCallback& callback); | 241 const StatusCallback& callback); |
| 242 void DoMoveLocalFile(const FileSystemURL& src, |
| 243 const FileSystemURL& dest, |
| 244 const StatusCallback& callback); |
| 173 void DoCopyInForeignFile(const FilePath& src_local_disk_file_path, | 245 void DoCopyInForeignFile(const FilePath& src_local_disk_file_path, |
| 174 const FileSystemURL& dest, | 246 const FileSystemURL& dest, |
| 175 const StatusCallback& callback); | 247 const StatusCallback& callback); |
| 176 void DoMove(const FileSystemURL& src, | |
| 177 const FileSystemURL& dest, | |
| 178 const StatusCallback& callback); | |
| 179 void DoTruncate(const FileSystemURL& url, | 248 void DoTruncate(const FileSystemURL& url, |
| 180 const StatusCallback& callback, int64 length); | 249 const StatusCallback& callback, int64 length); |
| 181 void DoOpenFile(const FileSystemURL& url, | 250 void DoOpenFile(const FileSystemURL& url, |
| 182 const OpenFileCallback& callback, int file_flags); | 251 const OpenFileCallback& callback, int file_flags); |
| 183 | 252 |
| 184 // Callback for CreateFile for |exclusive|=true cases. | 253 // Callback for CreateFile for |exclusive|=true cases. |
| 185 void DidEnsureFileExistsExclusive(const StatusCallback& callback, | 254 void DidEnsureFileExistsExclusive(const StatusCallback& callback, |
| 186 base::PlatformFileError rv, | 255 base::PlatformFileError rv, |
| 187 bool created); | 256 bool created); |
| 188 | 257 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 // Checks the validity of a given |url| and populates |file_util| for |mode|. | 300 // Checks the validity of a given |url| and populates |file_util| for |mode|. |
| 232 base::PlatformFileError SetUp( | 301 base::PlatformFileError SetUp( |
| 233 const FileSystemURL& url, | 302 const FileSystemURL& url, |
| 234 FileSystemFileUtil** file_util, | 303 FileSystemFileUtil** file_util, |
| 235 SetUpMode mode); | 304 SetUpMode mode); |
| 236 | 305 |
| 237 // Used only for internal assertions. | 306 // Used only for internal assertions. |
| 238 // Returns false if there's another inflight pending operation. | 307 // Returns false if there's another inflight pending operation. |
| 239 bool SetPendingOperationType(OperationType type); | 308 bool SetPendingOperationType(OperationType type); |
| 240 | 309 |
| 310 // Overrides this operation's operation context by given |context|. |
| 311 // This operation won't own |context| and the |context| needs to outlive |
| 312 // this operation. |
| 313 // |
| 314 // Called only from operation delegates when they create sub-operations |
| 315 // for performing a recursive operation. |
| 316 void set_overriding_operation_context(FileSystemOperationContext* context) { |
| 317 overriding_operation_context_ = context; |
| 318 } |
| 319 |
| 241 scoped_ptr<FileSystemOperationContext> operation_context_; | 320 scoped_ptr<FileSystemOperationContext> operation_context_; |
| 242 FileSystemFileUtil* src_util_; // Not owned. | 321 FileSystemFileUtil* file_util_; // Not owned. |
| 243 FileSystemFileUtil* dest_util_; // Not owned. | |
| 244 | 322 |
| 245 // Indicates if this operation is for cross filesystem operation or not. | 323 FileSystemOperationContext* overriding_operation_context_; |
| 246 // TODO(kinuko): This should be cleaned up. | |
| 247 bool is_cross_operation_; | |
| 248 | 324 |
| 249 // This is set before any write operations to dispatch | 325 // This is set before any write operations to dispatch |
| 250 // FileUpdateObserver::StartUpdate and FileUpdateObserver::EndUpdate. | 326 // FileUpdateObserver::StartUpdate and FileUpdateObserver::EndUpdate. |
| 251 ScopedVector<ScopedUpdateNotifier> scoped_update_notifiers_; | 327 ScopedVector<ScopedUpdateNotifier> scoped_update_notifiers_; |
| 252 | 328 |
| 253 // These are all used only by Write(). | 329 // These are all used only by Write(). |
| 254 friend class FileWriterDelegate; | 330 friend class FileWriterDelegate; |
| 255 scoped_ptr<FileWriterDelegate> file_writer_delegate_; | 331 scoped_ptr<FileWriterDelegate> file_writer_delegate_; |
| 256 | 332 |
| 333 scoped_ptr<RecursiveOperationDelegate> recursive_operation_delegate_; |
| 334 |
| 257 // write_callback is kept in this class for so that we can dispatch it when | 335 // write_callback is kept in this class for so that we can dispatch it when |
| 258 // the operation is cancelled. calcel_callback is kept for canceling a | 336 // the operation is cancelled. calcel_callback is kept for canceling a |
| 259 // Truncate() operation. We can't actually stop Truncate in another thread; | 337 // Truncate() operation. We can't actually stop Truncate in another thread; |
| 260 // after it resumed from the working thread, cancellation takes place. | 338 // after it resumed from the working thread, cancellation takes place. |
| 261 WriteCallback write_callback_; | 339 WriteCallback write_callback_; |
| 262 StatusCallback cancel_callback_; | 340 StatusCallback cancel_callback_; |
| 263 | 341 |
| 264 // Used only by OpenFile, in order to clone the file handle back to the | 342 // Used only by OpenFile, in order to clone the file handle back to the |
| 265 // requesting process. | 343 // requesting process. |
| 266 base::ProcessHandle peer_handle_; | 344 base::ProcessHandle peer_handle_; |
| 267 | 345 |
| 268 // A flag to make sure we call operation only once per instance. | 346 // A flag to make sure we call operation only once per instance. |
| 269 OperationType pending_operation_; | 347 OperationType pending_operation_; |
| 270 | 348 |
| 271 // LocalFileSystemOperation instance is usually deleted upon completion but | 349 // LocalFileSystemOperation instance is usually deleted upon completion but |
| 272 // could be deleted while it has inflight callbacks when Cancel is called. | 350 // could be deleted while it has inflight callbacks when Cancel is called. |
| 273 base::WeakPtrFactory<LocalFileSystemOperation> weak_factory_; | 351 base::WeakPtrFactory<LocalFileSystemOperation> weak_factory_; |
| 274 | 352 |
| 275 DISALLOW_COPY_AND_ASSIGN(LocalFileSystemOperation); | 353 DISALLOW_COPY_AND_ASSIGN(LocalFileSystemOperation); |
| 276 }; | 354 }; |
| 277 | 355 |
| 278 } // namespace fileapi | 356 } // namespace fileapi |
| 279 | 357 |
| 280 #endif // WEBKIT_FILEAPI_LOCAL_FILE_SYSTEM_OPERATION_H_ | 358 #endif // WEBKIT_FILEAPI_LOCAL_FILE_SYSTEM_OPERATION_H_ |
| OLD | NEW |