| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 // | 304 // |
| 270 // Called only from operation delegates when they create sub-operations | 305 // Called only from operation delegates when they create sub-operations |
| 271 // for performing a recursive operation. | 306 // for performing a recursive operation. |
| 272 void set_overriding_operation_context(FileSystemOperationContext* context) { | 307 void set_overriding_operation_context(FileSystemOperationContext* context) { |
| 273 overriding_operation_context_ = context; | 308 overriding_operation_context_ = context; |
| 274 } | 309 } |
| 275 | 310 |
| 276 scoped_refptr<FileSystemContext> file_system_context_; | 311 scoped_refptr<FileSystemContext> file_system_context_; |
| 277 | 312 |
| 278 scoped_ptr<FileSystemOperationContext> operation_context_; | 313 scoped_ptr<FileSystemOperationContext> operation_context_; |
| 279 FileSystemFileUtil* src_util_; // Not owned. | 314 FileSystemFileUtil* file_util_; // Not owned. |
| 280 FileSystemFileUtil* dest_util_; // Not owned. | |
| 281 | 315 |
| 282 FileSystemOperationContext* overriding_operation_context_; | 316 FileSystemOperationContext* overriding_operation_context_; |
| 283 | 317 |
| 284 // Indicates if this operation is for cross filesystem operation or not. | |
| 285 // TODO(kinuko): This should be cleaned up. | |
| 286 bool is_cross_operation_; | |
| 287 | |
| 288 // This is set before any write operations to dispatch | 318 // This is set before any write operations to dispatch |
| 289 // FileUpdateObserver::StartUpdate and FileUpdateObserver::EndUpdate. | 319 // FileUpdateObserver::StartUpdate and FileUpdateObserver::EndUpdate. |
| 290 ScopedVector<ScopedUpdateNotifier> scoped_update_notifiers_; | 320 ScopedVector<ScopedUpdateNotifier> scoped_update_notifiers_; |
| 291 | 321 |
| 292 // These are all used only by Write(). | 322 // These are all used only by Write(). |
| 293 friend class FileWriterDelegate; | 323 friend class FileWriterDelegate; |
| 294 scoped_ptr<FileWriterDelegate> file_writer_delegate_; | 324 scoped_ptr<FileWriterDelegate> file_writer_delegate_; |
| 295 | 325 |
| 296 scoped_ptr<RemoveOperationDelegate> remove_operation_delegate_; | 326 scoped_ptr<RecursiveOperationDelegate> recursive_operation_delegate_; |
| 297 | 327 |
| 298 // write_callback is kept in this class for so that we can dispatch it when | 328 // write_callback is kept in this class for so that we can dispatch it when |
| 299 // the operation is cancelled. calcel_callback is kept for canceling a | 329 // the operation is cancelled. calcel_callback is kept for canceling a |
| 300 // Truncate() operation. We can't actually stop Truncate in another thread; | 330 // Truncate() operation. We can't actually stop Truncate in another thread; |
| 301 // after it resumed from the working thread, cancellation takes place. | 331 // after it resumed from the working thread, cancellation takes place. |
| 302 WriteCallback write_callback_; | 332 WriteCallback write_callback_; |
| 303 StatusCallback cancel_callback_; | 333 StatusCallback cancel_callback_; |
| 304 | 334 |
| 305 // Used only by OpenFile, in order to clone the file handle back to the | 335 // Used only by OpenFile, in order to clone the file handle back to the |
| 306 // requesting process. | 336 // requesting process. |
| 307 base::ProcessHandle peer_handle_; | 337 base::ProcessHandle peer_handle_; |
| 308 | 338 |
| 309 // A flag to make sure we call operation only once per instance. | 339 // A flag to make sure we call operation only once per instance. |
| 310 OperationType pending_operation_; | 340 OperationType pending_operation_; |
| 311 | 341 |
| 312 // LocalFileSystemOperation instance is usually deleted upon completion but | 342 // LocalFileSystemOperation instance is usually deleted upon completion but |
| 313 // could be deleted while it has inflight callbacks when Cancel is called. | 343 // could be deleted while it has inflight callbacks when Cancel is called. |
| 314 base::WeakPtrFactory<LocalFileSystemOperation> weak_factory_; | 344 base::WeakPtrFactory<LocalFileSystemOperation> weak_factory_; |
| 315 | 345 |
| 316 DISALLOW_COPY_AND_ASSIGN(LocalFileSystemOperation); | 346 DISALLOW_COPY_AND_ASSIGN(LocalFileSystemOperation); |
| 317 }; | 347 }; |
| 318 | 348 |
| 319 } // namespace fileapi | 349 } // namespace fileapi |
| 320 | 350 |
| 321 #endif // WEBKIT_FILEAPI_LOCAL_FILE_SYSTEM_OPERATION_H_ | 351 #endif // WEBKIT_FILEAPI_LOCAL_FILE_SYSTEM_OPERATION_H_ |
| OLD | NEW |