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

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

Issue 10197007: Change webkit/{fileapi,quota} code to use TaskRunner. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: test fix Created 8 years, 7 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) 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 #include "webkit/fileapi/file_system_operation.h" 5 #include "webkit/fileapi/file_system_operation.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/sequenced_task_runner.h"
8 #include "base/time.h" 9 #include "base/time.h"
9 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
10 #include "net/base/escape.h" 11 #include "net/base/escape.h"
11 #include "net/url_request/url_request_context.h" 12 #include "net/url_request/url_request_context.h"
12 #include "webkit/blob/shareable_file_reference.h" 13 #include "webkit/blob/shareable_file_reference.h"
13 #include "webkit/fileapi/file_system_context.h" 14 #include "webkit/fileapi/file_system_context.h"
14 #include "webkit/fileapi/file_system_file_util_proxy.h" 15 #include "webkit/fileapi/file_system_file_util_proxy.h"
15 #include "webkit/fileapi/file_system_mount_point_provider.h" 16 #include "webkit/fileapi/file_system_mount_point_provider.h"
16 #include "webkit/fileapi/file_system_operation_context.h" 17 #include "webkit/fileapi/file_system_operation_context.h"
17 #include "webkit/fileapi/file_system_quota_util.h" 18 #include "webkit/fileapi/file_system_quota_util.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 : type(kFileSystemTypeUnknown) { 76 : type(kFileSystemTypeUnknown) {
76 } 77 }
77 78
78 FileSystemOperation::TaskParamsForDidGetQuota::~TaskParamsForDidGetQuota() {} 79 FileSystemOperation::TaskParamsForDidGetQuota::~TaskParamsForDidGetQuota() {}
79 80
80 FileSystemOperation::~FileSystemOperation() { 81 FileSystemOperation::~FileSystemOperation() {
81 if (file_writer_delegate_.get()) { 82 if (file_writer_delegate_.get()) {
82 FileSystemOperationContext* c = 83 FileSystemOperationContext* c =
83 new FileSystemOperationContext(operation_context_); 84 new FileSystemOperationContext(operation_context_);
84 base::FileUtilProxy::RelayClose( 85 base::FileUtilProxy::RelayClose(
85 proxy_, 86 file_system_context()->file_task_runner(),
86 base::Bind(&FileSystemFileUtil::Close, 87 base::Bind(&FileSystemFileUtil::Close,
87 base::Unretained(src_util_), 88 base::Unretained(src_util_),
88 base::Owned(c)), 89 base::Owned(c)),
89 file_writer_delegate_->file(), 90 file_writer_delegate_->file(),
90 base::FileUtilProxy::StatusCallback()); 91 base::FileUtilProxy::StatusCallback());
91 } 92 }
92 } 93 }
93 94
94 void FileSystemOperation::CreateFile(const GURL& path_url, 95 void FileSystemOperation::CreateFile(const GURL& path_url,
95 bool exclusive, 96 bool exclusive,
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 184
184 base::PlatformFileError result = SetUpFileSystemPath( 185 base::PlatformFileError result = SetUpFileSystemPath(
185 path_url, &src_path_, &src_util_, PATH_FOR_READ); 186 path_url, &src_path_, &src_util_, PATH_FOR_READ);
186 if (result != base::PLATFORM_FILE_OK) { 187 if (result != base::PLATFORM_FILE_OK) {
187 callback.Run(result); 188 callback.Run(result);
188 delete this; 189 delete this;
189 return; 190 return;
190 } 191 }
191 192
192 FileSystemFileUtilProxy::GetFileInfo( 193 FileSystemFileUtilProxy::GetFileInfo(
193 proxy_, &operation_context_, src_util_, src_path_, 194 &operation_context_, src_util_, src_path_,
194 base::Bind(&FileSystemOperation::DidDirectoryExists, 195 base::Bind(&FileSystemOperation::DidDirectoryExists,
195 base::Owned(this), callback)); 196 base::Owned(this), callback));
196 } 197 }
197 198
198 void FileSystemOperation::FileExists(const GURL& path_url, 199 void FileSystemOperation::FileExists(const GURL& path_url,
199 const StatusCallback& callback) { 200 const StatusCallback& callback) {
200 DCHECK(SetPendingOperationType(kOperationFileExists)); 201 DCHECK(SetPendingOperationType(kOperationFileExists));
201 202
202 base::PlatformFileError result = SetUpFileSystemPath( 203 base::PlatformFileError result = SetUpFileSystemPath(
203 path_url, &src_path_, &src_util_, PATH_FOR_READ); 204 path_url, &src_path_, &src_util_, PATH_FOR_READ);
204 if (result != base::PLATFORM_FILE_OK) { 205 if (result != base::PLATFORM_FILE_OK) {
205 callback.Run(result); 206 callback.Run(result);
206 delete this; 207 delete this;
207 return; 208 return;
208 } 209 }
209 210
210 FileSystemFileUtilProxy::GetFileInfo( 211 FileSystemFileUtilProxy::GetFileInfo(
211 proxy_, &operation_context_, src_util_, src_path_, 212 &operation_context_, src_util_, src_path_,
212 base::Bind(&FileSystemOperation::DidFileExists, 213 base::Bind(&FileSystemOperation::DidFileExists,
213 base::Owned(this), callback)); 214 base::Owned(this), callback));
214 } 215 }
215 216
216 void FileSystemOperation::GetMetadata(const GURL& path_url, 217 void FileSystemOperation::GetMetadata(const GURL& path_url,
217 const GetMetadataCallback& callback) { 218 const GetMetadataCallback& callback) {
218 DCHECK(SetPendingOperationType(kOperationGetMetadata)); 219 DCHECK(SetPendingOperationType(kOperationGetMetadata));
219 220
220 base::PlatformFileError result = SetUpFileSystemPath( 221 base::PlatformFileError result = SetUpFileSystemPath(
221 path_url, &src_path_, &src_util_, PATH_FOR_READ); 222 path_url, &src_path_, &src_util_, PATH_FOR_READ);
222 if (result != base::PLATFORM_FILE_OK) { 223 if (result != base::PLATFORM_FILE_OK) {
223 callback.Run(result, base::PlatformFileInfo(), FilePath()); 224 callback.Run(result, base::PlatformFileInfo(), FilePath());
224 delete this; 225 delete this;
225 return; 226 return;
226 } 227 }
227 228
228 FileSystemFileUtilProxy::GetFileInfo( 229 FileSystemFileUtilProxy::GetFileInfo(
229 proxy_, &operation_context_, src_util_, src_path_, 230 &operation_context_, src_util_, src_path_,
230 base::Bind(&FileSystemOperation::DidGetMetadata, 231 base::Bind(&FileSystemOperation::DidGetMetadata,
231 base::Owned(this), callback)); 232 base::Owned(this), callback));
232 } 233 }
233 234
234 void FileSystemOperation::ReadDirectory(const GURL& path_url, 235 void FileSystemOperation::ReadDirectory(const GURL& path_url,
235 const ReadDirectoryCallback& callback) { 236 const ReadDirectoryCallback& callback) {
236 DCHECK(SetPendingOperationType(kOperationReadDirectory)); 237 DCHECK(SetPendingOperationType(kOperationReadDirectory));
237 238
238 base::PlatformFileError result = SetUpFileSystemPath( 239 base::PlatformFileError result = SetUpFileSystemPath(
239 path_url, &src_path_, &src_util_, PATH_FOR_READ); 240 path_url, &src_path_, &src_util_, PATH_FOR_READ);
240 if (result != base::PLATFORM_FILE_OK) { 241 if (result != base::PLATFORM_FILE_OK) {
241 callback.Run(result, std::vector<base::FileUtilProxy::Entry>(), false); 242 callback.Run(result, std::vector<base::FileUtilProxy::Entry>(), false);
242 delete this; 243 delete this;
243 return; 244 return;
244 } 245 }
245 246
246 FileSystemFileUtilProxy::ReadDirectory( 247 FileSystemFileUtilProxy::ReadDirectory(
247 proxy_, &operation_context_, src_util_, src_path_, 248 &operation_context_, src_util_, src_path_,
248 base::Bind(&FileSystemOperation::DidReadDirectory, 249 base::Bind(&FileSystemOperation::DidReadDirectory,
249 base::Owned(this), callback)); 250 base::Owned(this), callback));
250 } 251 }
251 252
252 void FileSystemOperation::Remove(const GURL& path_url, bool recursive, 253 void FileSystemOperation::Remove(const GURL& path_url, bool recursive,
253 const StatusCallback& callback) { 254 const StatusCallback& callback) {
254 DCHECK(SetPendingOperationType(kOperationRemove)); 255 DCHECK(SetPendingOperationType(kOperationRemove));
255 256
256 base::PlatformFileError result = SetUpFileSystemPath( 257 base::PlatformFileError result = SetUpFileSystemPath(
257 path_url, &src_path_, &src_util_, PATH_FOR_WRITE); 258 path_url, &src_path_, &src_util_, PATH_FOR_WRITE);
258 if (result != base::PLATFORM_FILE_OK) { 259 if (result != base::PLATFORM_FILE_OK) {
259 callback.Run(result); 260 callback.Run(result);
260 delete this; 261 delete this;
261 return; 262 return;
262 } 263 }
263 264
264 scoped_quota_notifier_.reset(new ScopedQuotaNotifier( 265 scoped_quota_notifier_.reset(new ScopedQuotaNotifier(
265 file_system_context(), src_path_.origin(), src_path_.type())); 266 file_system_context(), src_path_.origin(), src_path_.type()));
266 267
267 FileSystemFileUtilProxy::Delete( 268 FileSystemFileUtilProxy::Delete(
268 proxy_, &operation_context_, src_util_, src_path_, recursive, 269 &operation_context_, src_util_, src_path_, recursive,
269 base::Bind(&FileSystemOperation::DidFinishFileOperation, 270 base::Bind(&FileSystemOperation::DidFinishFileOperation,
270 base::Owned(this), callback)); 271 base::Owned(this), callback));
271 } 272 }
272 273
273 void FileSystemOperation::Write( 274 void FileSystemOperation::Write(
274 const net::URLRequestContext* url_request_context, 275 const net::URLRequestContext* url_request_context,
275 const GURL& path_url, 276 const GURL& path_url,
276 const GURL& blob_url, 277 const GURL& blob_url,
277 int64 offset, 278 int64 offset,
278 const WriteCallback& callback) { 279 const WriteCallback& callback) {
279 DCHECK(SetPendingOperationType(kOperationWrite)); 280 DCHECK(SetPendingOperationType(kOperationWrite));
280 281
281 base::PlatformFileError result = SetUpFileSystemPath( 282 base::PlatformFileError result = SetUpFileSystemPath(
282 path_url, &src_path_, &src_util_, PATH_FOR_WRITE); 283 path_url, &src_path_, &src_util_, PATH_FOR_WRITE);
283 if (result != base::PLATFORM_FILE_OK) { 284 if (result != base::PLATFORM_FILE_OK) {
284 callback.Run(result, 0, false); 285 callback.Run(result, 0, false);
285 delete this; 286 delete this;
286 return; 287 return;
287 } 288 }
288 DCHECK(blob_url.is_valid()); 289 DCHECK(blob_url.is_valid());
289 file_writer_delegate_.reset(new FileWriterDelegate( 290 file_writer_delegate_.reset(new FileWriterDelegate(
290 this, src_path_, offset, proxy_)); 291 this, src_path_, offset));
291 set_write_callback(callback); 292 set_write_callback(callback);
292 blob_request_.reset( 293 blob_request_.reset(
293 new net::URLRequest(blob_url, file_writer_delegate_.get())); 294 new net::URLRequest(blob_url, file_writer_delegate_.get()));
294 blob_request_->set_context(url_request_context); 295 blob_request_->set_context(url_request_context);
295 296
296 GetUsageAndQuotaThenRunTask( 297 GetUsageAndQuotaThenRunTask(
297 src_path_.origin(), src_path_.type(), 298 src_path_.origin(), src_path_.type(),
298 base::Bind(&FileSystemOperation::DoWrite, base::Unretained(this)), 299 base::Bind(&FileSystemOperation::DoWrite, base::Unretained(this)),
299 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED, 0, true)); 300 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED, 0, true));
300 } 301 }
(...skipping 24 matching lines...) Expand all
325 326
326 base::PlatformFileError result = SetUpFileSystemPath( 327 base::PlatformFileError result = SetUpFileSystemPath(
327 path_url, &src_path_, &src_util_, PATH_FOR_WRITE); 328 path_url, &src_path_, &src_util_, PATH_FOR_WRITE);
328 if (result != base::PLATFORM_FILE_OK) { 329 if (result != base::PLATFORM_FILE_OK) {
329 callback.Run(result); 330 callback.Run(result);
330 delete this; 331 delete this;
331 return; 332 return;
332 } 333 }
333 334
334 FileSystemFileUtilProxy::Touch( 335 FileSystemFileUtilProxy::Touch(
335 proxy_, &operation_context_, src_util_, src_path_, 336 &operation_context_, src_util_, src_path_,
336 last_access_time, last_modified_time, 337 last_access_time, last_modified_time,
337 base::Bind(&FileSystemOperation::DidTouchFile, 338 base::Bind(&FileSystemOperation::DidTouchFile,
338 base::Owned(this), callback)); 339 base::Owned(this), callback));
339 } 340 }
340 341
341 void FileSystemOperation::OpenFile(const GURL& path_url, 342 void FileSystemOperation::OpenFile(const GURL& path_url,
342 int file_flags, 343 int file_flags,
343 base::ProcessHandle peer_handle, 344 base::ProcessHandle peer_handle,
344 const OpenFileCallback& callback) { 345 const OpenFileCallback& callback) {
345 DCHECK(SetPendingOperationType(kOperationOpenFile)); 346 DCHECK(SetPendingOperationType(kOperationOpenFile));
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 delete this; 438 delete this;
438 } 439 }
439 440
440 void FileSystemOperation::CreateSnapshotFile( 441 void FileSystemOperation::CreateSnapshotFile(
441 const GURL& path_url, 442 const GURL& path_url,
442 const SnapshotFileCallback& callback) { 443 const SnapshotFileCallback& callback) {
443 GetMetadata(path_url, base::Bind(&GetMetadataForSnapshot, callback)); 444 GetMetadata(path_url, base::Bind(&GetMetadataForSnapshot, callback));
444 } 445 }
445 446
446 FileSystemOperation::FileSystemOperation( 447 FileSystemOperation::FileSystemOperation(
447 scoped_refptr<base::MessageLoopProxy> proxy,
448 FileSystemContext* file_system_context) 448 FileSystemContext* file_system_context)
449 : proxy_(proxy), 449 : operation_context_(file_system_context),
450 operation_context_(file_system_context),
451 src_util_(NULL), 450 src_util_(NULL),
452 dest_util_(NULL), 451 dest_util_(NULL),
453 peer_handle_(base::kNullProcessHandle), 452 peer_handle_(base::kNullProcessHandle),
454 pending_operation_(kOperationNone) { 453 pending_operation_(kOperationNone) {
455 } 454 }
456 455
457 void FileSystemOperation::GetUsageAndQuotaThenRunTask( 456 void FileSystemOperation::GetUsageAndQuotaThenRunTask(
458 const GURL& origin, FileSystemType type, 457 const GURL& origin, FileSystemType type,
459 const base::Closure& task, 458 const base::Closure& task,
460 const base::Closure& error_callback) { 459 const base::Closure& error_callback) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 scoped_quota_notifier_.reset(new ScopedQuotaNotifier( 497 scoped_quota_notifier_.reset(new ScopedQuotaNotifier(
499 file_system_context(), params.origin, params.type)); 498 file_system_context(), params.origin, params.type));
500 499
501 params.task.Run(); 500 params.task.Run();
502 } 501 }
503 502
504 void FileSystemOperation::DoCreateFile( 503 void FileSystemOperation::DoCreateFile(
505 const StatusCallback& callback, 504 const StatusCallback& callback,
506 bool exclusive) { 505 bool exclusive) {
507 FileSystemFileUtilProxy::EnsureFileExists( 506 FileSystemFileUtilProxy::EnsureFileExists(
508 proxy_, &operation_context_, src_util_, src_path_, 507 &operation_context_,
508 src_util_, src_path_,
509 base::Bind( 509 base::Bind(
510 exclusive ? &FileSystemOperation::DidEnsureFileExistsExclusive 510 exclusive ? &FileSystemOperation::DidEnsureFileExistsExclusive
511 : &FileSystemOperation::DidEnsureFileExistsNonExclusive, 511 : &FileSystemOperation::DidEnsureFileExistsNonExclusive,
512 base::Owned(this), callback)); 512 base::Owned(this), callback));
513 } 513 }
514 514
515 void FileSystemOperation::DoCreateDirectory( 515 void FileSystemOperation::DoCreateDirectory(
516 const StatusCallback& callback, 516 const StatusCallback& callback,
517 bool exclusive, bool recursive) { 517 bool exclusive, bool recursive) {
518 FileSystemFileUtilProxy::CreateDirectory( 518 FileSystemFileUtilProxy::CreateDirectory(
519 proxy_, &operation_context_, src_util_, src_path_, exclusive, recursive, 519 &operation_context_,
520 src_util_, src_path_, exclusive, recursive,
520 base::Bind(&FileSystemOperation::DidFinishFileOperation, 521 base::Bind(&FileSystemOperation::DidFinishFileOperation,
521 base::Owned(this), callback)); 522 base::Owned(this), callback));
522 } 523 }
523 524
524 void FileSystemOperation::DoCopy(const StatusCallback& callback) { 525 void FileSystemOperation::DoCopy(const StatusCallback& callback) {
525 FileSystemFileUtilProxy::Copy( 526 FileSystemFileUtilProxy::Copy(
526 proxy_, &operation_context_, 527 &operation_context_,
527 src_util_, dest_util_, 528 src_util_, dest_util_,
528 src_path_, dest_path_, 529 src_path_, dest_path_,
529 base::Bind(&FileSystemOperation::DidFinishFileOperation, 530 base::Bind(&FileSystemOperation::DidFinishFileOperation,
530 base::Owned(this), callback)); 531 base::Owned(this), callback));
531 } 532 }
532 533
533 void FileSystemOperation::DoMove(const StatusCallback& callback) { 534 void FileSystemOperation::DoMove(const StatusCallback& callback) {
534 FileSystemFileUtilProxy::Move( 535 FileSystemFileUtilProxy::Move(
535 proxy_, &operation_context_, 536 &operation_context_,
536 src_util_, dest_util_, 537 src_util_, dest_util_,
537 src_path_, dest_path_, 538 src_path_, dest_path_,
538 base::Bind(&FileSystemOperation::DidFinishFileOperation, 539 base::Bind(&FileSystemOperation::DidFinishFileOperation,
539 base::Owned(this), callback)); 540 base::Owned(this), callback));
540 } 541 }
541 542
542 void FileSystemOperation::DoWrite() { 543 void FileSystemOperation::DoWrite() {
543 int file_flags = base::PLATFORM_FILE_OPEN | 544 int file_flags = base::PLATFORM_FILE_OPEN |
544 base::PLATFORM_FILE_WRITE | 545 base::PLATFORM_FILE_WRITE |
545 base::PLATFORM_FILE_ASYNC; 546 base::PLATFORM_FILE_ASYNC;
546 547
547 FileSystemFileUtilProxy::CreateOrOpen( 548 FileSystemFileUtilProxy::CreateOrOpen(
548 proxy_, &operation_context_, src_util_, src_path_, file_flags, 549 &operation_context_, src_util_, src_path_, file_flags,
549 base::Bind(&FileSystemOperation::OnFileOpenedForWrite, 550 base::Bind(&FileSystemOperation::OnFileOpenedForWrite,
550 base::Unretained(this))); 551 base::Unretained(this)));
551 } 552 }
552 553
553 void FileSystemOperation::DoTruncate(const StatusCallback& callback, 554 void FileSystemOperation::DoTruncate(const StatusCallback& callback,
554 int64 length) { 555 int64 length) {
555 FileSystemFileUtilProxy::Truncate( 556 FileSystemFileUtilProxy::Truncate(
556 proxy_, &operation_context_, src_util_, src_path_, length, 557 &operation_context_, src_util_, src_path_, length,
557 base::Bind(&FileSystemOperation::DidFinishFileOperation, 558 base::Bind(&FileSystemOperation::DidFinishFileOperation,
558 base::Owned(this), callback)); 559 base::Owned(this), callback));
559 } 560 }
560 561
561 void FileSystemOperation::DoOpenFile(const OpenFileCallback& callback, 562 void FileSystemOperation::DoOpenFile(const OpenFileCallback& callback,
562 int file_flags) { 563 int file_flags) {
563 FileSystemFileUtilProxy::CreateOrOpen( 564 FileSystemFileUtilProxy::CreateOrOpen(
564 proxy_, &operation_context_, src_util_, src_path_, file_flags, 565 &operation_context_, src_util_, src_path_, file_flags,
565 base::Bind(&FileSystemOperation::DidOpenFile, 566 base::Bind(&FileSystemOperation::DidOpenFile,
566 base::Owned(this), callback)); 567 base::Owned(this), callback));
567 } 568 }
568 569
569 void FileSystemOperation::DidEnsureFileExistsExclusive( 570 void FileSystemOperation::DidEnsureFileExistsExclusive(
570 const StatusCallback& callback, 571 const StatusCallback& callback,
571 base::PlatformFileError rv, bool created) { 572 base::PlatformFileError rv, bool created) {
572 if (rv == base::PLATFORM_FILE_OK && !created) { 573 if (rv == base::PLATFORM_FILE_OK && !created) {
573 callback.Run(base::PLATFORM_FILE_ERROR_EXISTS); 574 callback.Run(base::PLATFORM_FILE_ERROR_EXISTS);
574 } else { 575 } else {
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 } 736 }
736 737
737 bool FileSystemOperation::SetPendingOperationType(OperationType type) { 738 bool FileSystemOperation::SetPendingOperationType(OperationType type) {
738 if (pending_operation_ != kOperationNone) 739 if (pending_operation_ != kOperationNone)
739 return false; 740 return false;
740 pending_operation_ = type; 741 pending_operation_ = type;
741 return true; 742 return true;
742 } 743 }
743 744
744 } // namespace fileapi 745 } // 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