| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_BROWSER_FILEAPI_FILE_SYSTEM_OPERATION_IMPL_H_ | 5 #ifndef WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_OPERATION_IMPL_H_ |
| 6 #define WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_OPERATION_IMPL_H_ | 6 #define WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_OPERATION_IMPL_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/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "webkit/browser/fileapi/file_system_operation.h" | 13 #include "storage/browser/fileapi/file_system_operation.h" |
| 14 #include "webkit/browser/fileapi/file_system_operation_context.h" | 14 #include "storage/browser/fileapi/file_system_operation_context.h" |
| 15 #include "webkit/browser/fileapi/file_system_url.h" | 15 #include "storage/browser/fileapi/file_system_url.h" |
| 16 #include "webkit/browser/fileapi/file_writer_delegate.h" | 16 #include "storage/browser/fileapi/file_writer_delegate.h" |
| 17 #include "webkit/browser/webkit_storage_browser_export.h" | 17 #include "storage/common/storage_export.h" |
| 18 #include "webkit/common/blob/scoped_file.h" | 18 #include "storage/common/blob/scoped_file.h" |
| 19 #include "webkit/common/quota/quota_types.h" | 19 #include "storage/common/quota/quota_types.h" |
| 20 | 20 |
| 21 namespace fileapi { | 21 namespace storage { |
| 22 | 22 |
| 23 class AsyncFileUtil; | 23 class AsyncFileUtil; |
| 24 class FileSystemContext; | 24 class FileSystemContext; |
| 25 class RecursiveOperationDelegate; | 25 class RecursiveOperationDelegate; |
| 26 | 26 |
| 27 // The default implementation of FileSystemOperation for file systems. | 27 // The default implementation of FileSystemOperation for file systems. |
| 28 class WEBKIT_STORAGE_BROWSER_EXPORT FileSystemOperationImpl | 28 class STORAGE_EXPORT FileSystemOperationImpl |
| 29 : public NON_EXPORTED_BASE(FileSystemOperation) { | 29 : public NON_EXPORTED_BASE(FileSystemOperation) { |
| 30 public: | 30 public: |
| 31 virtual ~FileSystemOperationImpl(); | 31 virtual ~FileSystemOperationImpl(); |
| 32 | 32 |
| 33 // FileSystemOperation overrides. | 33 // FileSystemOperation overrides. |
| 34 virtual void CreateFile(const FileSystemURL& url, | 34 virtual void CreateFile(const FileSystemURL& url, |
| 35 bool exclusive, | 35 bool exclusive, |
| 36 const StatusCallback& callback) OVERRIDE; | 36 const StatusCallback& callback) OVERRIDE; |
| 37 virtual void CreateDirectory(const FileSystemURL& url, | 37 virtual void CreateDirectory(const FileSystemURL& url, |
| 38 bool exclusive, | 38 bool exclusive, |
| 39 bool recursive, | 39 bool recursive, |
| 40 const StatusCallback& callback) OVERRIDE; | 40 const StatusCallback& callback) OVERRIDE; |
| 41 virtual void Copy(const FileSystemURL& src_url, | 41 virtual void Copy(const FileSystemURL& src_url, |
| 42 const FileSystemURL& dest_url, | 42 const FileSystemURL& dest_url, |
| 43 CopyOrMoveOption option, | 43 CopyOrMoveOption option, |
| 44 const CopyProgressCallback& progress_callback, | 44 const CopyProgressCallback& progress_callback, |
| 45 const StatusCallback& callback) OVERRIDE; | 45 const StatusCallback& callback) OVERRIDE; |
| 46 virtual void Move(const FileSystemURL& src_url, | 46 virtual void Move(const FileSystemURL& src_url, |
| 47 const FileSystemURL& dest_url, | 47 const FileSystemURL& dest_url, |
| 48 CopyOrMoveOption option, | 48 CopyOrMoveOption option, |
| 49 const StatusCallback& callback) OVERRIDE; | 49 const StatusCallback& callback) OVERRIDE; |
| 50 virtual void DirectoryExists(const FileSystemURL& url, | 50 virtual void DirectoryExists(const FileSystemURL& url, |
| 51 const StatusCallback& callback) OVERRIDE; | 51 const StatusCallback& callback) OVERRIDE; |
| 52 virtual void FileExists(const FileSystemURL& url, | 52 virtual void FileExists(const FileSystemURL& url, |
| 53 const StatusCallback& callback) OVERRIDE; | 53 const StatusCallback& callback) OVERRIDE; |
| 54 virtual void GetMetadata(const FileSystemURL& url, | 54 virtual void GetMetadata(const FileSystemURL& url, |
| 55 const GetMetadataCallback& callback) OVERRIDE; | 55 const GetMetadataCallback& callback) OVERRIDE; |
| 56 virtual void ReadDirectory(const FileSystemURL& url, | 56 virtual void ReadDirectory(const FileSystemURL& url, |
| 57 const ReadDirectoryCallback& callback) OVERRIDE; | 57 const ReadDirectoryCallback& callback) OVERRIDE; |
| 58 virtual void Remove(const FileSystemURL& url, bool recursive, | 58 virtual void Remove(const FileSystemURL& url, |
| 59 bool recursive, |
| 59 const StatusCallback& callback) OVERRIDE; | 60 const StatusCallback& callback) OVERRIDE; |
| 60 virtual void Write(const FileSystemURL& url, | 61 virtual void Write(const FileSystemURL& url, |
| 61 scoped_ptr<FileWriterDelegate> writer_delegate, | 62 scoped_ptr<FileWriterDelegate> writer_delegate, |
| 62 scoped_ptr<net::URLRequest> blob_request, | 63 scoped_ptr<net::URLRequest> blob_request, |
| 63 const WriteCallback& callback) OVERRIDE; | 64 const WriteCallback& callback) OVERRIDE; |
| 64 virtual void Truncate(const FileSystemURL& url, int64 length, | 65 virtual void Truncate(const FileSystemURL& url, |
| 66 int64 length, |
| 65 const StatusCallback& callback) OVERRIDE; | 67 const StatusCallback& callback) OVERRIDE; |
| 66 virtual void TouchFile(const FileSystemURL& url, | 68 virtual void TouchFile(const FileSystemURL& url, |
| 67 const base::Time& last_access_time, | 69 const base::Time& last_access_time, |
| 68 const base::Time& last_modified_time, | 70 const base::Time& last_modified_time, |
| 69 const StatusCallback& callback) OVERRIDE; | 71 const StatusCallback& callback) OVERRIDE; |
| 70 virtual void OpenFile(const FileSystemURL& url, | 72 virtual void OpenFile(const FileSystemURL& url, |
| 71 int file_flags, | 73 int file_flags, |
| 72 const OpenFileCallback& callback) OVERRIDE; | 74 const OpenFileCallback& callback) OVERRIDE; |
| 73 virtual void Cancel(const StatusCallback& cancel_callback) OVERRIDE; | 75 virtual void Cancel(const StatusCallback& cancel_callback) OVERRIDE; |
| 74 virtual void CreateSnapshotFile( | 76 virtual void CreateSnapshotFile( |
| (...skipping 26 matching lines...) Expand all Loading... |
| 101 private: | 103 private: |
| 102 friend class FileSystemOperation; | 104 friend class FileSystemOperation; |
| 103 | 105 |
| 104 FileSystemOperationImpl( | 106 FileSystemOperationImpl( |
| 105 const FileSystemURL& url, | 107 const FileSystemURL& url, |
| 106 FileSystemContext* file_system_context, | 108 FileSystemContext* file_system_context, |
| 107 scoped_ptr<FileSystemOperationContext> operation_context); | 109 scoped_ptr<FileSystemOperationContext> operation_context); |
| 108 | 110 |
| 109 // Queries the quota and usage and then runs the given |task|. | 111 // Queries the quota and usage and then runs the given |task|. |
| 110 // If an error occurs during the quota query it runs |error_callback| instead. | 112 // If an error occurs during the quota query it runs |error_callback| instead. |
| 111 void GetUsageAndQuotaThenRunTask( | 113 void GetUsageAndQuotaThenRunTask(const FileSystemURL& url, |
| 112 const FileSystemURL& url, | 114 const base::Closure& task, |
| 113 const base::Closure& task, | 115 const base::Closure& error_callback); |
| 114 const base::Closure& error_callback); | |
| 115 | 116 |
| 116 // Called after the quota info is obtained from the quota manager | 117 // Called after the quota info is obtained from the quota manager |
| 117 // (which is triggered by GetUsageAndQuotaThenRunTask). | 118 // (which is triggered by GetUsageAndQuotaThenRunTask). |
| 118 // Sets the quota info in the operation_context_ and then runs the given | 119 // Sets the quota info in the operation_context_ and then runs the given |
| 119 // |task| if the returned quota status is successful, otherwise runs | 120 // |task| if the returned quota status is successful, otherwise runs |
| 120 // |error_callback|. | 121 // |error_callback|. |
| 121 void DidGetUsageAndQuotaAndRunTask( | 122 void DidGetUsageAndQuotaAndRunTask(const base::Closure& task, |
| 122 const base::Closure& task, | 123 const base::Closure& error_callback, |
| 123 const base::Closure& error_callback, | 124 quota::QuotaStatusCode status, |
| 124 quota::QuotaStatusCode status, | 125 int64 usage, |
| 125 int64 usage, int64 quota); | 126 int64 quota); |
| 126 | 127 |
| 127 // The 'body' methods that perform the actual work (i.e. posting the | 128 // The 'body' methods that perform the actual work (i.e. posting the |
| 128 // file task on proxy_) after the quota check. | 129 // file task on proxy_) after the quota check. |
| 129 void DoCreateFile(const FileSystemURL& url, | 130 void DoCreateFile(const FileSystemURL& url, |
| 130 const StatusCallback& callback, bool exclusive); | 131 const StatusCallback& callback, |
| 132 bool exclusive); |
| 131 void DoCreateDirectory(const FileSystemURL& url, | 133 void DoCreateDirectory(const FileSystemURL& url, |
| 132 const StatusCallback& callback, | 134 const StatusCallback& callback, |
| 133 bool exclusive, | 135 bool exclusive, |
| 134 bool recursive); | 136 bool recursive); |
| 135 void DoCopyFileLocal(const FileSystemURL& src, | 137 void DoCopyFileLocal(const FileSystemURL& src, |
| 136 const FileSystemURL& dest, | 138 const FileSystemURL& dest, |
| 137 CopyOrMoveOption option, | 139 CopyOrMoveOption option, |
| 138 const CopyFileProgressCallback& progress_callback, | 140 const CopyFileProgressCallback& progress_callback, |
| 139 const StatusCallback& callback); | 141 const StatusCallback& callback); |
| 140 void DoMoveFileLocal(const FileSystemURL& src, | 142 void DoMoveFileLocal(const FileSystemURL& src, |
| 141 const FileSystemURL& dest, | 143 const FileSystemURL& dest, |
| 142 CopyOrMoveOption option, | 144 CopyOrMoveOption option, |
| 143 const StatusCallback& callback); | 145 const StatusCallback& callback); |
| 144 void DoCopyInForeignFile(const base::FilePath& src_local_disk_file_path, | 146 void DoCopyInForeignFile(const base::FilePath& src_local_disk_file_path, |
| 145 const FileSystemURL& dest, | 147 const FileSystemURL& dest, |
| 146 const StatusCallback& callback); | 148 const StatusCallback& callback); |
| 147 void DoTruncate(const FileSystemURL& url, | 149 void DoTruncate(const FileSystemURL& url, |
| 148 const StatusCallback& callback, int64 length); | 150 const StatusCallback& callback, |
| 151 int64 length); |
| 149 void DoOpenFile(const FileSystemURL& url, | 152 void DoOpenFile(const FileSystemURL& url, |
| 150 const OpenFileCallback& callback, int file_flags); | 153 const OpenFileCallback& callback, |
| 154 int file_flags); |
| 151 | 155 |
| 152 // Callback for CreateFile for |exclusive|=true cases. | 156 // Callback for CreateFile for |exclusive|=true cases. |
| 153 void DidEnsureFileExistsExclusive(const StatusCallback& callback, | 157 void DidEnsureFileExistsExclusive(const StatusCallback& callback, |
| 154 base::File::Error rv, | 158 base::File::Error rv, |
| 155 bool created); | 159 bool created); |
| 156 | 160 |
| 157 // Callback for CreateFile for |exclusive|=false cases. | 161 // Callback for CreateFile for |exclusive|=false cases. |
| 158 void DidEnsureFileExistsNonExclusive(const StatusCallback& callback, | 162 void DidEnsureFileExistsNonExclusive(const StatusCallback& callback, |
| 159 base::File::Error rv, | 163 base::File::Error rv, |
| 160 bool created); | 164 bool created); |
| 161 | 165 |
| 162 void DidFinishOperation(const StatusCallback& callback, | 166 void DidFinishOperation(const StatusCallback& callback, base::File::Error rv); |
| 163 base::File::Error rv); | |
| 164 void DidDirectoryExists(const StatusCallback& callback, | 167 void DidDirectoryExists(const StatusCallback& callback, |
| 165 base::File::Error rv, | 168 base::File::Error rv, |
| 166 const base::File::Info& file_info); | 169 const base::File::Info& file_info); |
| 167 void DidFileExists(const StatusCallback& callback, | 170 void DidFileExists(const StatusCallback& callback, |
| 168 base::File::Error rv, | 171 base::File::Error rv, |
| 169 const base::File::Info& file_info); | 172 const base::File::Info& file_info); |
| 170 void DidDeleteRecursively(const FileSystemURL& url, | 173 void DidDeleteRecursively(const FileSystemURL& url, |
| 171 const StatusCallback& callback, | 174 const StatusCallback& callback, |
| 172 base::File::Error rv); | 175 base::File::Error rv); |
| 173 void DidWrite(const FileSystemURL& url, | 176 void DidWrite(const FileSystemURL& url, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 194 StatusCallback cancel_callback_; | 197 StatusCallback cancel_callback_; |
| 195 | 198 |
| 196 // A flag to make sure we call operation only once per instance. | 199 // A flag to make sure we call operation only once per instance. |
| 197 OperationType pending_operation_; | 200 OperationType pending_operation_; |
| 198 | 201 |
| 199 base::WeakPtrFactory<FileSystemOperationImpl> weak_factory_; | 202 base::WeakPtrFactory<FileSystemOperationImpl> weak_factory_; |
| 200 | 203 |
| 201 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationImpl); | 204 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationImpl); |
| 202 }; | 205 }; |
| 203 | 206 |
| 204 } // namespace fileapi | 207 } // namespace storage |
| 205 | 208 |
| 206 #endif // WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_OPERATION_IMPL_H_ | 209 #endif // WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_OPERATION_IMPL_H_ |
| OLD | NEW |