| 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 #include "webkit/fileapi/local_file_system_operation.h" | 5 #include "webkit/fileapi/local_file_system_operation.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
| 9 #include "base/time.h" | 9 #include "base/time.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "webkit/fileapi/file_writer_delegate.h" | 25 #include "webkit/fileapi/file_writer_delegate.h" |
| 26 #include "webkit/fileapi/remove_operation_delegate.h" | 26 #include "webkit/fileapi/remove_operation_delegate.h" |
| 27 #include "webkit/fileapi/sandbox_file_stream_writer.h" | 27 #include "webkit/fileapi/sandbox_file_stream_writer.h" |
| 28 #include "webkit/quota/quota_manager.h" | 28 #include "webkit/quota/quota_manager.h" |
| 29 #include "webkit/quota/quota_types.h" | 29 #include "webkit/quota/quota_types.h" |
| 30 | 30 |
| 31 using webkit_blob::ShareableFileReference; | 31 using webkit_blob::ShareableFileReference; |
| 32 | 32 |
| 33 namespace fileapi { | 33 namespace fileapi { |
| 34 | 34 |
| 35 LocalFileSystemOperation::LocalFileSystemOperation( |
| 36 FileSystemContext* file_system_context, |
| 37 scoped_ptr<FileSystemOperationContext> operation_context) |
| 38 : file_system_context_(file_system_context), |
| 39 operation_context_(operation_context.Pass()), |
| 40 async_file_util_(NULL), |
| 41 peer_handle_(base::kNullProcessHandle), |
| 42 pending_operation_(kOperationNone), |
| 43 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 44 DCHECK(operation_context_.get()); |
| 45 operation_context_->DetachUserDataThread(); |
| 46 } |
| 47 |
| 35 LocalFileSystemOperation::~LocalFileSystemOperation() { | 48 LocalFileSystemOperation::~LocalFileSystemOperation() { |
| 49 if (!operation_context()) |
| 50 return; |
| 51 operation_context()->DetachUserDataThread(); |
| 36 if (write_target_url_.is_valid()) { | 52 if (write_target_url_.is_valid()) { |
| 37 operation_context()->update_observers()->Notify( | 53 operation_context()->update_observers()->Notify( |
| 38 &FileUpdateObserver::OnEndUpdate, MakeTuple(write_target_url_)); | 54 &FileUpdateObserver::OnEndUpdate, MakeTuple(write_target_url_)); |
| 39 } | 55 } |
| 40 } | 56 } |
| 41 | 57 |
| 42 void LocalFileSystemOperation::CreateFile(const FileSystemURL& url, | 58 void LocalFileSystemOperation::CreateFile(const FileSystemURL& url, |
| 43 bool exclusive, | 59 bool exclusive, |
| 44 const StatusCallback& callback) { | 60 const StatusCallback& callback) { |
| 45 DCHECK(SetPendingOperationType(kOperationCreateFile)); | 61 DCHECK(SetPendingOperationType(kOperationCreateFile)); |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 async_file_util_->CreateSnapshotFile( | 439 async_file_util_->CreateSnapshotFile( |
| 424 operation_context(), url, | 440 operation_context(), url, |
| 425 base::Bind(&LocalFileSystemOperation::DidCreateSnapshotFile, | 441 base::Bind(&LocalFileSystemOperation::DidCreateSnapshotFile, |
| 426 base::Owned(this), callback)); | 442 base::Owned(this), callback)); |
| 427 } | 443 } |
| 428 | 444 |
| 429 LocalFileSystemOperation* LocalFileSystemOperation::CreateNestedOperation() { | 445 LocalFileSystemOperation* LocalFileSystemOperation::CreateNestedOperation() { |
| 430 LocalFileSystemOperation* operation = new LocalFileSystemOperation( | 446 LocalFileSystemOperation* operation = new LocalFileSystemOperation( |
| 431 file_system_context(), | 447 file_system_context(), |
| 432 make_scoped_ptr(new FileSystemOperationContext(file_system_context()))); | 448 make_scoped_ptr(new FileSystemOperationContext(file_system_context()))); |
| 433 operation->parent_operation_ = this; | 449 operation->parent_operation_ = weak_factory_.GetWeakPtr(); |
| 434 return operation; | 450 return operation; |
| 435 } | 451 } |
| 436 | 452 |
| 437 void LocalFileSystemOperation::CopyInForeignFile( | 453 void LocalFileSystemOperation::CopyInForeignFile( |
| 438 const base::FilePath& src_local_disk_file_path, | 454 const base::FilePath& src_local_disk_file_path, |
| 439 const FileSystemURL& dest_url, | 455 const FileSystemURL& dest_url, |
| 440 const StatusCallback& callback) { | 456 const StatusCallback& callback) { |
| 441 DCHECK(SetPendingOperationType(kOperationCopyInForeignFile)); | 457 DCHECK(SetPendingOperationType(kOperationCopyInForeignFile)); |
| 442 | 458 |
| 443 base::PlatformFileError result = SetUp(dest_url, OPERATION_MODE_WRITE); | 459 base::PlatformFileError result = SetUp(dest_url, OPERATION_MODE_WRITE); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 return; | 544 return; |
| 529 } | 545 } |
| 530 | 546 |
| 531 GetUsageAndQuotaThenRunTask( | 547 GetUsageAndQuotaThenRunTask( |
| 532 dest_url, | 548 dest_url, |
| 533 base::Bind(&LocalFileSystemOperation::DoMoveFileLocal, | 549 base::Bind(&LocalFileSystemOperation::DoMoveFileLocal, |
| 534 base::Unretained(this), src_url, dest_url, callback), | 550 base::Unretained(this), src_url, dest_url, callback), |
| 535 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED)); | 551 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED)); |
| 536 } | 552 } |
| 537 | 553 |
| 538 LocalFileSystemOperation::LocalFileSystemOperation( | |
| 539 FileSystemContext* file_system_context, | |
| 540 scoped_ptr<FileSystemOperationContext> operation_context) | |
| 541 : file_system_context_(file_system_context), | |
| 542 operation_context_(operation_context.Pass()), | |
| 543 async_file_util_(NULL), | |
| 544 parent_operation_(NULL), | |
| 545 peer_handle_(base::kNullProcessHandle), | |
| 546 pending_operation_(kOperationNone), | |
| 547 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | |
| 548 DCHECK(operation_context_.get()); | |
| 549 } | |
| 550 | |
| 551 void LocalFileSystemOperation::GetUsageAndQuotaThenRunTask( | 554 void LocalFileSystemOperation::GetUsageAndQuotaThenRunTask( |
| 552 const FileSystemURL& url, | 555 const FileSystemURL& url, |
| 553 const base::Closure& task, | 556 const base::Closure& task, |
| 554 const base::Closure& error_callback) { | 557 const base::Closure& error_callback) { |
| 555 quota::QuotaManagerProxy* quota_manager_proxy = | 558 quota::QuotaManagerProxy* quota_manager_proxy = |
| 556 file_system_context()->quota_manager_proxy(); | 559 file_system_context()->quota_manager_proxy(); |
| 557 if (!quota_manager_proxy || | 560 if (!quota_manager_proxy || |
| 558 !file_system_context()->GetQuotaUtil(url.type())) { | 561 !file_system_context()->GetQuotaUtil(url.type())) { |
| 559 // If we don't have the quota manager or the requested filesystem type | 562 // If we don't have the quota manager or the requested filesystem type |
| 560 // does not support quota, we should be able to let it go. | 563 // does not support quota, we should be able to let it go. |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 866 } | 869 } |
| 867 | 870 |
| 868 bool LocalFileSystemOperation::SetPendingOperationType(OperationType type) { | 871 bool LocalFileSystemOperation::SetPendingOperationType(OperationType type) { |
| 869 if (pending_operation_ != kOperationNone) | 872 if (pending_operation_ != kOperationNone) |
| 870 return false; | 873 return false; |
| 871 pending_operation_ = type; | 874 pending_operation_ = type; |
| 872 return true; | 875 return true; |
| 873 } | 876 } |
| 874 | 877 |
| 875 } // namespace fileapi | 878 } // namespace fileapi |
| OLD | NEW |