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 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 if (!writer.get()) { | 307 if (!writer.get()) { |
308 // Write is not supported. | 308 // Write is not supported. |
309 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY, 0, false); | 309 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY, 0, false); |
310 delete this; | 310 delete this; |
311 return; | 311 return; |
312 } | 312 } |
313 | 313 |
314 DCHECK(blob_url.is_valid()); | 314 DCHECK(blob_url.is_valid()); |
315 file_writer_delegate_.reset(new FileWriterDelegate( | 315 file_writer_delegate_.reset(new FileWriterDelegate( |
316 base::Bind(&LocalFileSystemOperation::DidWrite, | 316 base::Bind(&LocalFileSystemOperation::DidWrite, |
317 weak_factory_.GetWeakPtr()), | 317 weak_factory_.GetWeakPtr(), url), |
318 writer.Pass())); | 318 writer.Pass())); |
319 | 319 |
320 set_write_callback(callback); | 320 set_write_callback(callback); |
321 scoped_ptr<net::URLRequest> blob_request(url_request_context->CreateRequest( | 321 scoped_ptr<net::URLRequest> blob_request(url_request_context->CreateRequest( |
322 blob_url, file_writer_delegate_.get())); | 322 blob_url, file_writer_delegate_.get())); |
323 | 323 |
324 file_writer_delegate_->Start(blob_request.Pass()); | 324 file_writer_delegate_->Start(blob_request.Pass()); |
325 } | 325 } |
326 | 326 |
327 void LocalFileSystemOperation::Truncate(const FileSystemURL& url, int64 length, | 327 void LocalFileSystemOperation::Truncate(const FileSystemURL& url, int64 length, |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
670 | 670 |
671 void LocalFileSystemOperation::DidReadDirectory( | 671 void LocalFileSystemOperation::DidReadDirectory( |
672 const ReadDirectoryCallback& callback, | 672 const ReadDirectoryCallback& callback, |
673 base::PlatformFileError rv, | 673 base::PlatformFileError rv, |
674 const std::vector<base::FileUtilProxy::Entry>& entries, | 674 const std::vector<base::FileUtilProxy::Entry>& entries, |
675 bool has_more) { | 675 bool has_more) { |
676 callback.Run(rv, entries, has_more); | 676 callback.Run(rv, entries, has_more); |
677 } | 677 } |
678 | 678 |
679 void LocalFileSystemOperation::DidWrite( | 679 void LocalFileSystemOperation::DidWrite( |
| 680 const FileSystemURL& url, |
680 base::PlatformFileError rv, | 681 base::PlatformFileError rv, |
681 int64 bytes, | 682 int64 bytes, |
682 bool complete) { | 683 FileWriterDelegate::WriteProgressStatus write_status) { |
683 if (write_callback_.is_null()) { | 684 if (write_callback_.is_null()) { |
684 // If cancelled, callback is already invoked and set to null in Cancel(). | 685 // If cancelled, callback is already invoked and set to null in Cancel(). |
685 // We must not call it twice. Just shut down this operation object. | 686 // We must not call it twice. Just shut down this operation object. |
686 delete this; | 687 delete this; |
687 return; | 688 return; |
688 } | 689 } |
| 690 |
| 691 const bool complete = ( |
| 692 write_status != FileWriterDelegate::SUCCESS_IO_PENDING); |
| 693 if (complete && write_status != FileWriterDelegate::ERROR_WRITE_NOT_STARTED) { |
| 694 operation_context_->change_observers()->Notify( |
| 695 &FileChangeObserver::OnModifyFile, MakeTuple(url)); |
| 696 } |
| 697 |
689 write_callback_.Run(rv, bytes, complete); | 698 write_callback_.Run(rv, bytes, complete); |
690 if (complete || rv != base::PLATFORM_FILE_OK) | 699 if (complete || rv != base::PLATFORM_FILE_OK) |
691 delete this; | 700 delete this; |
692 } | 701 } |
693 | 702 |
694 void LocalFileSystemOperation::DidTouchFile(const StatusCallback& callback, | 703 void LocalFileSystemOperation::DidTouchFile(const StatusCallback& callback, |
695 base::PlatformFileError rv) { | 704 base::PlatformFileError rv) { |
696 callback.Run(rv); | 705 callback.Run(rv); |
697 } | 706 } |
698 | 707 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
768 } | 777 } |
769 | 778 |
770 bool LocalFileSystemOperation::SetPendingOperationType(OperationType type) { | 779 bool LocalFileSystemOperation::SetPendingOperationType(OperationType type) { |
771 if (pending_operation_ != kOperationNone) | 780 if (pending_operation_ != kOperationNone) |
772 return false; | 781 return false; |
773 pending_operation_ = type; | 782 pending_operation_ = type; |
774 return true; | 783 return true; |
775 } | 784 } |
776 | 785 |
777 } // namespace fileapi | 786 } // namespace fileapi |
OLD | NEW |