Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(180)

Side by Side Diff: webkit/fileapi/file_system_operation.cc

Issue 6471019: Stackable file_util for FileAPIs. Sample code for discussion. Incomplete. Cannot be compiled. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Fixed the Patch Set 3 before reflecting the comments. -UtilBase can be built and works. Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/fileapi/file_system_operation.h ('k') | webkit/fileapi/file_system_operation_context.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include "webkit/fileapi/file_system_operation.h" 5 #include "webkit/fileapi/file_system_operation.h"
6 6
7 #include "base/time.h" 7 #include "base/time.h"
8 #include "net/url_request/url_request_context.h" 8 #include "net/url_request/url_request_context.h"
9 #include "webkit/fileapi/file_system_callback_dispatcher.h" 9 #include "webkit/fileapi/file_system_callback_dispatcher.h"
10 #include "webkit/fileapi/file_system_context.h" 10 #include "webkit/fileapi/file_system_context.h"
11 #include "webkit/fileapi/file_system_file_util_proxy.h"
11 #include "webkit/fileapi/file_system_path_manager.h" 12 #include "webkit/fileapi/file_system_path_manager.h"
12 #include "webkit/fileapi/file_system_quota_manager.h" 13 #include "webkit/fileapi/file_system_quota_manager.h"
13 #include "webkit/fileapi/file_writer_delegate.h" 14 #include "webkit/fileapi/file_writer_delegate.h"
14 15
15 namespace fileapi { 16 namespace fileapi {
16 17
17 FileSystemOperation::FileSystemOperation( 18 FileSystemOperation::FileSystemOperation(
18 FileSystemCallbackDispatcher* dispatcher, 19 FileSystemCallbackDispatcher* dispatcher,
19 scoped_refptr<base::MessageLoopProxy> proxy, 20 scoped_refptr<base::MessageLoopProxy> proxy,
20 FileSystemContext* file_system_context) 21 FileSystemContext* file_system_context)
21 : proxy_(proxy), 22 : proxy_(proxy),
22 dispatcher_(dispatcher), 23 dispatcher_(dispatcher),
23 file_system_context_(file_system_context), 24 file_system_context_(file_system_context),
24 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { 25 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
25 DCHECK(dispatcher); 26 DCHECK(dispatcher);
26 #ifndef NDEBUG 27 #ifndef NDEBUG
27 pending_operation_ = kOperationNone; 28 pending_operation_ = kOperationNone;
28 #endif 29 #endif
29 } 30 }
30 31
31 FileSystemOperation::~FileSystemOperation() { 32 FileSystemOperation::~FileSystemOperation() {
32 if (file_writer_delegate_.get()) 33 if (file_writer_delegate_.get())
33 base::FileUtilProxy::Close(proxy_, file_writer_delegate_->file(), NULL); 34 fileapi::FileSystemFileUtilProxy::Close(
35 file_system_operation_context_.get(),
36 proxy_, file_writer_delegate_->file(), NULL);
34 } 37 }
35 38
36 void FileSystemOperation::OpenFileSystem( 39 void FileSystemOperation::OpenFileSystem(
37 const GURL& origin_url, fileapi::FileSystemType type, bool create) { 40 const GURL& origin_url, fileapi::FileSystemType type, bool create) {
38 #ifndef NDEBUG 41 #ifndef NDEBUG
39 DCHECK(kOperationNone == pending_operation_); 42 DCHECK(kOperationNone == pending_operation_);
40 pending_operation_ = static_cast<FileSystemOperation::OperationType>( 43 pending_operation_ = static_cast<FileSystemOperation::OperationType>(
41 kOperationOpenFileSystem); 44 kOperationOpenFileSystem);
42 #endif 45 #endif
43 46
44 DCHECK(file_system_context_.get()); 47 DCHECK(file_system_context_.get());
45 file_system_context_->path_manager()->GetFileSystemRootPath( 48 file_system_context_->path_manager()->GetFileSystemRootPath(
46 origin_url, type, create, 49 origin_url, type, create,
47 callback_factory_.NewCallback(&FileSystemOperation::DidGetRootPath)); 50 callback_factory_.NewCallback(&FileSystemOperation::DidGetRootPath));
48 } 51 }
49 52
50 void FileSystemOperation::CreateFile(const FilePath& path, 53 void FileSystemOperation::CreateFile(const FilePath& path,
51 bool exclusive) { 54 bool exclusive) {
52 #ifndef NDEBUG 55 #ifndef NDEBUG
53 DCHECK(kOperationNone == pending_operation_); 56 DCHECK(kOperationNone == pending_operation_);
54 pending_operation_ = kOperationCreateFile; 57 pending_operation_ = kOperationCreateFile;
55 #endif 58 #endif
56 59
57 if (!VerifyFileSystemPathForWrite(path, true /* create */, 0)) { 60 if (!VerifyFileSystemPathForWrite(path, true /* create */, 0)) {
58 delete this; 61 delete this;
59 return; 62 return;
60 } 63 }
61 base::FileUtilProxy::EnsureFileExists( 64 fileapi::FileSystemFileUtilProxy::EnsureFileExists(
62 proxy_, path, callback_factory_.NewCallback( 65 file_system_operation_context_.get(),
63 exclusive ? &FileSystemOperation::DidEnsureFileExistsExclusive 66 proxy_, path, callback_factory_.NewCallback(
64 : &FileSystemOperation::DidEnsureFileExistsNonExclusive)); 67 exclusive ? &FileSystemOperation::DidEnsureFileExistsExclusive
68 : &FileSystemOperation::DidEnsureFileExistsNonExclusive));
65 } 69 }
66 70
67 void FileSystemOperation::CreateDirectory(const FilePath& path, 71 void FileSystemOperation::CreateDirectory(const FilePath& path,
68 bool exclusive, 72 bool exclusive,
69 bool recursive) { 73 bool recursive) {
70 #ifndef NDEBUG 74 #ifndef NDEBUG
71 DCHECK(kOperationNone == pending_operation_); 75 DCHECK(kOperationNone == pending_operation_);
72 pending_operation_ = kOperationCreateDirectory; 76 pending_operation_ = kOperationCreateDirectory;
73 #endif 77 #endif
74 78
75 if (!VerifyFileSystemPathForWrite(path, true /* create */, 0)) { 79 if (!VerifyFileSystemPathForWrite(path, true /* create */, 0)) {
76 delete this; 80 delete this;
77 return; 81 return;
78 } 82 }
79 base::FileUtilProxy::CreateDirectory( 83 fileapi::FileSystemFileUtilProxy::CreateDirectory(
84 file_system_operation_context_.get(),
80 proxy_, path, exclusive, recursive, callback_factory_.NewCallback( 85 proxy_, path, exclusive, recursive, callback_factory_.NewCallback(
81 &FileSystemOperation::DidFinishFileOperation)); 86 &FileSystemOperation::DidFinishFileOperation));
82 } 87 }
83 88
84 void FileSystemOperation::Copy(const FilePath& src_path, 89 void FileSystemOperation::Copy(const FilePath& src_path,
85 const FilePath& dest_path) { 90 const FilePath& dest_path) {
86 #ifndef NDEBUG 91 #ifndef NDEBUG
87 DCHECK(kOperationNone == pending_operation_); 92 DCHECK(kOperationNone == pending_operation_);
88 pending_operation_ = kOperationCopy; 93 pending_operation_ = kOperationCopy;
89 #endif 94 #endif
90 95
91 if (!VerifyFileSystemPathForRead(src_path) || 96 if (!VerifyFileSystemPathForRead(src_path) ||
92 !VerifyFileSystemPathForWrite(dest_path, true /* create */, 97 !VerifyFileSystemPathForWrite(dest_path, true /* create */,
93 FileSystemQuotaManager::kUnknownSize)) { 98 FileSystemQuotaManager::kUnknownSize)) {
94 delete this; 99 delete this;
95 return; 100 return;
96 } 101 }
97 base::FileUtilProxy::Copy(proxy_, src_path, dest_path, 102 fileapi::FileSystemFileUtilProxy::Copy(
103 file_system_operation_context_.get(),
104 proxy_, src_path, dest_path,
98 callback_factory_.NewCallback( 105 callback_factory_.NewCallback(
99 &FileSystemOperation::DidFinishFileOperation)); 106 &FileSystemOperation::DidFinishFileOperation));
100 } 107 }
101 108
102 void FileSystemOperation::Move(const FilePath& src_path, 109 void FileSystemOperation::Move(const FilePath& src_path,
103 const FilePath& dest_path) { 110 const FilePath& dest_path) {
104 #ifndef NDEBUG 111 #ifndef NDEBUG
105 DCHECK(kOperationNone == pending_operation_); 112 DCHECK(kOperationNone == pending_operation_);
106 pending_operation_ = kOperationMove; 113 pending_operation_ = kOperationMove;
107 #endif 114 #endif
108 115
109 if (!VerifyFileSystemPathForRead(src_path) || 116 if (!VerifyFileSystemPathForRead(src_path) ||
110 !VerifyFileSystemPathForWrite(dest_path, true /* create */, 117 !VerifyFileSystemPathForWrite(dest_path, true /* create */,
111 FileSystemQuotaManager::kUnknownSize)) { 118 FileSystemQuotaManager::kUnknownSize)) {
112 delete this; 119 delete this;
113 return; 120 return;
114 } 121 }
115 base::FileUtilProxy::Move(proxy_, src_path, dest_path, 122 fileapi::FileSystemFileUtilProxy::Move(
123 file_system_operation_context_.get(),
124 proxy_, src_path, dest_path,
116 callback_factory_.NewCallback( 125 callback_factory_.NewCallback(
117 &FileSystemOperation::DidFinishFileOperation)); 126 &FileSystemOperation::DidFinishFileOperation));
118 } 127 }
119 128
120 void FileSystemOperation::DirectoryExists(const FilePath& path) { 129 void FileSystemOperation::DirectoryExists(const FilePath& path) {
121 #ifndef NDEBUG 130 #ifndef NDEBUG
122 DCHECK(kOperationNone == pending_operation_); 131 DCHECK(kOperationNone == pending_operation_);
123 pending_operation_ = kOperationDirectoryExists; 132 pending_operation_ = kOperationDirectoryExists;
124 #endif 133 #endif
125 134
126 if (!VerifyFileSystemPathForRead(path)) { 135 if (!VerifyFileSystemPathForRead(path)) {
127 delete this; 136 delete this;
128 return; 137 return;
129 } 138 }
130 base::FileUtilProxy::GetFileInfo(proxy_, path, callback_factory_.NewCallback( 139 fileapi::FileSystemFileUtilProxy::GetFileInfo(
140 file_system_operation_context_.get(),
141 proxy_, path, callback_factory_.NewCallback(
131 &FileSystemOperation::DidDirectoryExists)); 142 &FileSystemOperation::DidDirectoryExists));
132 } 143 }
133 144
134 void FileSystemOperation::FileExists(const FilePath& path) { 145 void FileSystemOperation::FileExists(const FilePath& path) {
135 #ifndef NDEBUG 146 #ifndef NDEBUG
136 DCHECK(kOperationNone == pending_operation_); 147 DCHECK(kOperationNone == pending_operation_);
137 pending_operation_ = kOperationFileExists; 148 pending_operation_ = kOperationFileExists;
138 #endif 149 #endif
139 150
140 if (!VerifyFileSystemPathForRead(path)) { 151 if (!VerifyFileSystemPathForRead(path)) {
141 delete this; 152 delete this;
142 return; 153 return;
143 } 154 }
144 base::FileUtilProxy::GetFileInfo(proxy_, path, callback_factory_.NewCallback( 155 fileapi::FileSystemFileUtilProxy::GetFileInfo(
156 file_system_operation_context_.get(),
157 proxy_, path, callback_factory_.NewCallback(
145 &FileSystemOperation::DidFileExists)); 158 &FileSystemOperation::DidFileExists));
146 } 159 }
147 160
148 void FileSystemOperation::GetMetadata(const FilePath& path) { 161 void FileSystemOperation::GetMetadata(const FilePath& path) {
149 #ifndef NDEBUG 162 #ifndef NDEBUG
150 DCHECK(kOperationNone == pending_operation_); 163 DCHECK(kOperationNone == pending_operation_);
151 pending_operation_ = kOperationGetMetadata; 164 pending_operation_ = kOperationGetMetadata;
152 #endif 165 #endif
153 166
154 if (!VerifyFileSystemPathForRead(path)) { 167 if (!VerifyFileSystemPathForRead(path)) {
155 delete this; 168 delete this;
156 return; 169 return;
157 } 170 }
158 base::FileUtilProxy::GetFileInfo(proxy_, path, callback_factory_.NewCallback( 171 fileapi::FileSystemFileUtilProxy::GetFileInfo(
172 file_system_operation_context_.get(),
173 proxy_, path, callback_factory_.NewCallback(
159 &FileSystemOperation::DidGetMetadata)); 174 &FileSystemOperation::DidGetMetadata));
160 } 175 }
161 176
162 void FileSystemOperation::ReadDirectory(const FilePath& path) { 177 void FileSystemOperation::ReadDirectory(const FilePath& path) {
163 #ifndef NDEBUG 178 #ifndef NDEBUG
164 DCHECK(kOperationNone == pending_operation_); 179 DCHECK(kOperationNone == pending_operation_);
165 pending_operation_ = kOperationReadDirectory; 180 pending_operation_ = kOperationReadDirectory;
166 #endif 181 #endif
167 182
168 if (!VerifyFileSystemPathForRead(path)) { 183 if (!VerifyFileSystemPathForRead(path)) {
169 delete this; 184 delete this;
170 return; 185 return;
171 } 186 }
172 base::FileUtilProxy::ReadDirectory(proxy_, path, 187 fileapi::FileSystemFileUtilProxy::ReadDirectory(
188 file_system_operation_context_.get(),
189 proxy_, path,
173 callback_factory_.NewCallback( 190 callback_factory_.NewCallback(
174 &FileSystemOperation::DidReadDirectory)); 191 &FileSystemOperation::DidReadDirectory));
175 } 192 }
176 193
177 void FileSystemOperation::Remove(const FilePath& path, bool recursive) { 194 void FileSystemOperation::Remove(const FilePath& path, bool recursive) {
178 #ifndef NDEBUG 195 #ifndef NDEBUG
179 DCHECK(kOperationNone == pending_operation_); 196 DCHECK(kOperationNone == pending_operation_);
180 pending_operation_ = kOperationRemove; 197 pending_operation_ = kOperationRemove;
181 #endif 198 #endif
182 199
183 if (!VerifyFileSystemPathForWrite(path, false /* create */, 0)) { 200 if (!VerifyFileSystemPathForWrite(path, false /* create */, 0)) {
184 delete this; 201 delete this;
185 return; 202 return;
186 } 203 }
187 base::FileUtilProxy::Delete(proxy_, path, recursive, 204 fileapi::FileSystemFileUtilProxy::Delete(
205 file_system_operation_context_.get(),
206 proxy_, path, recursive,
188 callback_factory_.NewCallback( 207 callback_factory_.NewCallback(
189 &FileSystemOperation::DidFinishFileOperation)); 208 &FileSystemOperation::DidFinishFileOperation));
190 } 209 }
191 210
192 void FileSystemOperation::Write( 211 void FileSystemOperation::Write(
193 scoped_refptr<net::URLRequestContext> url_request_context, 212 scoped_refptr<net::URLRequestContext> url_request_context,
194 const FilePath& path, 213 const FilePath& path,
195 const GURL& blob_url, 214 const GURL& blob_url,
196 int64 offset) { 215 int64 offset) {
197 #ifndef NDEBUG 216 #ifndef NDEBUG
198 DCHECK(kOperationNone == pending_operation_); 217 DCHECK(kOperationNone == pending_operation_);
199 pending_operation_ = kOperationWrite; 218 pending_operation_ = kOperationWrite;
200 #endif 219 #endif
201 if (!VerifyFileSystemPathForWrite(path, true /* create */, 220 if (!VerifyFileSystemPathForWrite(path, true /* create */,
202 FileSystemQuotaManager::kUnknownSize)) { 221 FileSystemQuotaManager::kUnknownSize)) {
203 delete this; 222 delete this;
204 return; 223 return;
205 } 224 }
206 DCHECK(blob_url.is_valid()); 225 DCHECK(blob_url.is_valid());
207 file_writer_delegate_.reset(new FileWriterDelegate(this, offset)); 226 file_writer_delegate_.reset(new FileWriterDelegate(this, offset));
208 blob_request_.reset( 227 blob_request_.reset(
209 new net::URLRequest(blob_url, file_writer_delegate_.get())); 228 new net::URLRequest(blob_url, file_writer_delegate_.get()));
210 blob_request_->set_context(url_request_context); 229 blob_request_->set_context(url_request_context);
211 base::FileUtilProxy::CreateOrOpen( 230 fileapi::FileSystemFileUtilProxy::CreateOrOpen(
231 file_system_operation_context_.get(),
212 proxy_, 232 proxy_,
213 path, 233 path,
214 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE | 234 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE |
215 base::PLATFORM_FILE_ASYNC, 235 base::PLATFORM_FILE_ASYNC,
216 callback_factory_.NewCallback( 236 callback_factory_.NewCallback(
217 &FileSystemOperation::OnFileOpenedForWrite)); 237 &FileSystemOperation::OnFileOpenedForWrite));
218 } 238 }
219 239
220 void FileSystemOperation::Truncate(const FilePath& path, int64 length) { 240 void FileSystemOperation::Truncate(const FilePath& path, int64 length) {
221 #ifndef NDEBUG 241 #ifndef NDEBUG
222 DCHECK(kOperationNone == pending_operation_); 242 DCHECK(kOperationNone == pending_operation_);
223 pending_operation_ = kOperationTruncate; 243 pending_operation_ = kOperationTruncate;
224 #endif 244 #endif
225 if (!VerifyFileSystemPathForWrite(path, false /* create */, 0)) { 245 if (!VerifyFileSystemPathForWrite(path, false /* create */, 0)) {
226 delete this; 246 delete this;
227 return; 247 return;
228 } 248 }
229 base::FileUtilProxy::Truncate(proxy_, path, length, 249 fileapi::FileSystemFileUtilProxy::Truncate(
250 file_system_operation_context_.get(),
251 proxy_, path, length,
230 callback_factory_.NewCallback( 252 callback_factory_.NewCallback(
231 &FileSystemOperation::DidFinishFileOperation)); 253 &FileSystemOperation::DidFinishFileOperation));
232 } 254 }
233 255
234 void FileSystemOperation::TouchFile(const FilePath& path, 256 void FileSystemOperation::TouchFile(const FilePath& path,
235 const base::Time& last_access_time, 257 const base::Time& last_access_time,
236 const base::Time& last_modified_time) { 258 const base::Time& last_modified_time) {
237 #ifndef NDEBUG 259 #ifndef NDEBUG
238 DCHECK(kOperationNone == pending_operation_); 260 DCHECK(kOperationNone == pending_operation_);
239 pending_operation_ = kOperationTouchFile; 261 pending_operation_ = kOperationTouchFile;
240 #endif 262 #endif
241 263
242 if (!VerifyFileSystemPathForWrite(path, true /* create */, 0)) { 264 if (!VerifyFileSystemPathForWrite(path, true /* create */, 0)) {
243 delete this; 265 delete this;
244 return; 266 return;
245 } 267 }
246 base::FileUtilProxy::Touch( 268 fileapi::FileSystemFileUtilProxy::Touch(
269 file_system_operation_context_.get(),
247 proxy_, path, last_access_time, last_modified_time, 270 proxy_, path, last_access_time, last_modified_time,
248 callback_factory_.NewCallback(&FileSystemOperation::DidTouchFile)); 271 callback_factory_.NewCallback(&FileSystemOperation::DidTouchFile));
249 } 272 }
250 273
251 // We can only get here on a write or truncate that's not yet completed. 274 // We can only get here on a write or truncate that's not yet completed.
252 // We don't support cancelling any other operation at this time. 275 // We don't support cancelling any other operation at this time.
253 void FileSystemOperation::Cancel(FileSystemOperation* cancel_operation_ptr) { 276 void FileSystemOperation::Cancel(FileSystemOperation* cancel_operation_ptr) {
254 scoped_ptr<FileSystemOperation> cancel_operation(cancel_operation_ptr); 277 scoped_ptr<FileSystemOperation> cancel_operation(cancel_operation_ptr);
255 if (file_writer_delegate_.get()) { 278 if (file_writer_delegate_.get()) {
256 #ifndef NDEBUG 279 #ifndef NDEBUG
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 // need to resolve what amount of size it's going to write. 467 // need to resolve what amount of size it's going to write.
445 if (!file_system_context_->quota_manager()->CheckOriginQuota( 468 if (!file_system_context_->quota_manager()->CheckOriginQuota(
446 origin_url, growth)) { 469 origin_url, growth)) {
447 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_NO_SPACE); 470 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_NO_SPACE);
448 return false; 471 return false;
449 } 472 }
450 return true; 473 return true;
451 } 474 }
452 475
453 } // namespace fileapi 476 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/file_system_operation.h ('k') | webkit/fileapi/file_system_operation_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698