We started redesigning GpuMemoryBuffer interface to handle multiple buffers [0].
[chromium-blink-merge.git] / storage / browser / fileapi / file_system_operation_impl.h
blobdbf6e3a781c419e95780c205319d4d794acc17e4
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
3 // found in the LICENSE file.
5 #ifndef STORAGE_BROWSER_FILEAPI_FILE_SYSTEM_OPERATION_IMPL_H_
6 #define STORAGE_BROWSER_FILEAPI_FILE_SYSTEM_OPERATION_IMPL_H_
8 #include <vector>
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "storage/browser/blob/scoped_file.h"
14 #include "storage/browser/fileapi/file_system_operation.h"
15 #include "storage/browser/fileapi/file_system_operation_context.h"
16 #include "storage/browser/fileapi/file_system_url.h"
17 #include "storage/browser/fileapi/file_writer_delegate.h"
18 #include "storage/browser/storage_browser_export.h"
19 #include "storage/common/quota/quota_types.h"
21 namespace storage {
23 class AsyncFileUtil;
24 class FileSystemContext;
25 class RecursiveOperationDelegate;
27 // The default implementation of FileSystemOperation for file systems.
28 class STORAGE_EXPORT FileSystemOperationImpl
29 : public NON_EXPORTED_BASE(FileSystemOperation) {
30 public:
31 ~FileSystemOperationImpl() override;
33 // FileSystemOperation overrides.
34 void CreateFile(const FileSystemURL& url,
35 bool exclusive,
36 const StatusCallback& callback) override;
37 void CreateDirectory(const FileSystemURL& url,
38 bool exclusive,
39 bool recursive,
40 const StatusCallback& callback) override;
41 void Copy(const FileSystemURL& src_url,
42 const FileSystemURL& dest_url,
43 CopyOrMoveOption option,
44 const CopyProgressCallback& progress_callback,
45 const StatusCallback& callback) override;
46 void Move(const FileSystemURL& src_url,
47 const FileSystemURL& dest_url,
48 CopyOrMoveOption option,
49 const StatusCallback& callback) override;
50 void DirectoryExists(const FileSystemURL& url,
51 const StatusCallback& callback) override;
52 void FileExists(const FileSystemURL& url,
53 const StatusCallback& callback) override;
54 void GetMetadata(const FileSystemURL& url,
55 const GetMetadataCallback& callback) override;
56 void ReadDirectory(const FileSystemURL& url,
57 const ReadDirectoryCallback& callback) override;
58 void Remove(const FileSystemURL& url,
59 bool recursive,
60 const StatusCallback& callback) override;
61 void Write(const FileSystemURL& url,
62 scoped_ptr<FileWriterDelegate> writer_delegate,
63 scoped_ptr<net::URLRequest> blob_request,
64 const WriteCallback& callback) override;
65 void Truncate(const FileSystemURL& url,
66 int64 length,
67 const StatusCallback& callback) override;
68 void TouchFile(const FileSystemURL& url,
69 const base::Time& last_access_time,
70 const base::Time& last_modified_time,
71 const StatusCallback& callback) override;
72 void OpenFile(const FileSystemURL& url,
73 int file_flags,
74 const OpenFileCallback& callback) override;
75 void Cancel(const StatusCallback& cancel_callback) override;
76 void CreateSnapshotFile(const FileSystemURL& path,
77 const SnapshotFileCallback& callback) override;
78 void CopyInForeignFile(const base::FilePath& src_local_disk_path,
79 const FileSystemURL& dest_url,
80 const StatusCallback& callback) override;
81 void RemoveFile(const FileSystemURL& url,
82 const StatusCallback& callback) override;
83 void RemoveDirectory(const FileSystemURL& url,
84 const StatusCallback& callback) override;
85 void CopyFileLocal(const FileSystemURL& src_url,
86 const FileSystemURL& dest_url,
87 CopyOrMoveOption option,
88 const CopyFileProgressCallback& progress_callback,
89 const StatusCallback& callback) override;
90 void MoveFileLocal(const FileSystemURL& src_url,
91 const FileSystemURL& dest_url,
92 CopyOrMoveOption option,
93 const StatusCallback& callback) override;
94 base::File::Error SyncGetPlatformPath(const FileSystemURL& url,
95 base::FilePath* platform_path) override;
97 FileSystemContext* file_system_context() const {
98 return file_system_context_.get();
101 private:
102 friend class FileSystemOperation;
104 FileSystemOperationImpl(
105 const FileSystemURL& url,
106 FileSystemContext* file_system_context,
107 scoped_ptr<FileSystemOperationContext> operation_context);
109 // 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.
111 void GetUsageAndQuotaThenRunTask(
112 const FileSystemURL& url,
113 const base::Closure& task,
114 const base::Closure& error_callback);
116 // Called after the quota info is obtained from the quota manager
117 // (which is triggered by GetUsageAndQuotaThenRunTask).
118 // 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 // |error_callback|.
121 void DidGetUsageAndQuotaAndRunTask(const base::Closure& task,
122 const base::Closure& error_callback,
123 storage::QuotaStatusCode status,
124 int64 usage,
125 int64 quota);
127 // The 'body' methods that perform the actual work (i.e. posting the
128 // file task on proxy_) after the quota check.
129 void DoCreateFile(const FileSystemURL& url,
130 const StatusCallback& callback, bool exclusive);
131 void DoCreateDirectory(const FileSystemURL& url,
132 const StatusCallback& callback,
133 bool exclusive,
134 bool recursive);
135 void DoCopyFileLocal(const FileSystemURL& src,
136 const FileSystemURL& dest,
137 CopyOrMoveOption option,
138 const CopyFileProgressCallback& progress_callback,
139 const StatusCallback& callback);
140 void DoMoveFileLocal(const FileSystemURL& src,
141 const FileSystemURL& dest,
142 CopyOrMoveOption option,
143 const StatusCallback& callback);
144 void DoCopyInForeignFile(const base::FilePath& src_local_disk_file_path,
145 const FileSystemURL& dest,
146 const StatusCallback& callback);
147 void DoTruncate(const FileSystemURL& url,
148 const StatusCallback& callback, int64 length);
149 void DoOpenFile(const FileSystemURL& url,
150 const OpenFileCallback& callback, int file_flags);
152 // Callback for CreateFile for |exclusive|=true cases.
153 void DidEnsureFileExistsExclusive(const StatusCallback& callback,
154 base::File::Error rv,
155 bool created);
157 // Callback for CreateFile for |exclusive|=false cases.
158 void DidEnsureFileExistsNonExclusive(const StatusCallback& callback,
159 base::File::Error rv,
160 bool created);
162 void DidFinishOperation(const StatusCallback& callback,
163 base::File::Error rv);
164 void DidDirectoryExists(const StatusCallback& callback,
165 base::File::Error rv,
166 const base::File::Info& file_info);
167 void DidFileExists(const StatusCallback& callback,
168 base::File::Error rv,
169 const base::File::Info& file_info);
170 void DidDeleteRecursively(const FileSystemURL& url,
171 const StatusCallback& callback,
172 base::File::Error rv);
173 void DidWrite(const FileSystemURL& url,
174 const WriteCallback& callback,
175 base::File::Error rv,
176 int64 bytes,
177 FileWriterDelegate::WriteProgressStatus write_status);
179 // Used only for internal assertions.
180 // Returns false if there's another inflight pending operation.
181 bool SetPendingOperationType(OperationType type);
183 scoped_refptr<FileSystemContext> file_system_context_;
185 scoped_ptr<FileSystemOperationContext> operation_context_;
186 AsyncFileUtil* async_file_util_; // Not owned.
188 scoped_ptr<FileWriterDelegate> file_writer_delegate_;
189 scoped_ptr<RecursiveOperationDelegate> recursive_operation_delegate_;
191 StatusCallback cancel_callback_;
193 // A flag to make sure we call operation only once per instance.
194 OperationType pending_operation_;
196 base::WeakPtrFactory<FileSystemOperationImpl> weak_factory_;
198 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationImpl);
201 } // namespace storage
203 #endif // STORAGE_BROWSER_FILEAPI_FILE_SYSTEM_OPERATION_IMPL_H_