| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 "storage/browser/fileapi/file_system_operation_runner.h" | 5 #include "storage/browser/fileapi/file_system_operation_runner.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <tuple> |
| 8 #include <utility> | 9 #include <utility> |
| 9 | 10 |
| 10 #include "base/bind.h" | 11 #include "base/bind.h" |
| 11 #include "base/macros.h" | 12 #include "base/macros.h" |
| 12 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 13 #include "base/thread_task_runner_handle.h" | 14 #include "base/thread_task_runner_handle.h" |
| 14 #include "net/url_request/url_request_context.h" | 15 #include "net/url_request/url_request_context.h" |
| 15 #include "storage/browser/blob/blob_url_request_job_factory.h" | 16 #include "storage/browser/blob/blob_url_request_job_factory.h" |
| 16 #include "storage/browser/blob/shareable_file_reference.h" | 17 #include "storage/browser/blob/shareable_file_reference.h" |
| 17 #include "storage/browser/fileapi/file_observers.h" | 18 #include "storage/browser/fileapi/file_observers.h" |
| (...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 AsWeakPtr(), handle, callback, type, source_url, dest_url, size)); | 631 AsWeakPtr(), handle, callback, type, source_url, dest_url, size)); |
| 631 return; | 632 return; |
| 632 } | 633 } |
| 633 callback.Run(type, source_url, dest_url, size); | 634 callback.Run(type, source_url, dest_url, size); |
| 634 } | 635 } |
| 635 | 636 |
| 636 void FileSystemOperationRunner::PrepareForWrite(OperationID id, | 637 void FileSystemOperationRunner::PrepareForWrite(OperationID id, |
| 637 const FileSystemURL& url) { | 638 const FileSystemURL& url) { |
| 638 if (file_system_context_->GetUpdateObservers(url.type())) { | 639 if (file_system_context_->GetUpdateObservers(url.type())) { |
| 639 file_system_context_->GetUpdateObservers(url.type())->Notify( | 640 file_system_context_->GetUpdateObservers(url.type())->Notify( |
| 640 &FileUpdateObserver::OnStartUpdate, base::MakeTuple(url)); | 641 &FileUpdateObserver::OnStartUpdate, std::make_tuple(url)); |
| 641 } | 642 } |
| 642 write_target_urls_[id].insert(url); | 643 write_target_urls_[id].insert(url); |
| 643 } | 644 } |
| 644 | 645 |
| 645 void FileSystemOperationRunner::PrepareForRead(OperationID id, | 646 void FileSystemOperationRunner::PrepareForRead(OperationID id, |
| 646 const FileSystemURL& url) { | 647 const FileSystemURL& url) { |
| 647 if (file_system_context_->GetAccessObservers(url.type())) { | 648 if (file_system_context_->GetAccessObservers(url.type())) { |
| 648 file_system_context_->GetAccessObservers(url.type())->Notify( | 649 file_system_context_->GetAccessObservers(url.type())->Notify( |
| 649 &FileAccessObserver::OnAccess, base::MakeTuple(url)); | 650 &FileAccessObserver::OnAccess, std::make_tuple(url)); |
| 650 } | 651 } |
| 651 } | 652 } |
| 652 | 653 |
| 653 FileSystemOperationRunner::OperationHandle | 654 FileSystemOperationRunner::OperationHandle |
| 654 FileSystemOperationRunner::BeginOperation( | 655 FileSystemOperationRunner::BeginOperation( |
| 655 FileSystemOperation* operation, | 656 FileSystemOperation* operation, |
| 656 base::WeakPtr<BeginOperationScoper> scope) { | 657 base::WeakPtr<BeginOperationScoper> scope) { |
| 657 OperationHandle handle; | 658 OperationHandle handle; |
| 658 handle.id = operations_.Add(operation); | 659 handle.id = operations_.Add(operation); |
| 659 handle.scope = scope; | 660 handle.scope = scope; |
| 660 return handle; | 661 return handle; |
| 661 } | 662 } |
| 662 | 663 |
| 663 void FileSystemOperationRunner::FinishOperation(OperationID id) { | 664 void FileSystemOperationRunner::FinishOperation(OperationID id) { |
| 664 OperationToURLSet::iterator found = write_target_urls_.find(id); | 665 OperationToURLSet::iterator found = write_target_urls_.find(id); |
| 665 if (found != write_target_urls_.end()) { | 666 if (found != write_target_urls_.end()) { |
| 666 const FileSystemURLSet& urls = found->second; | 667 const FileSystemURLSet& urls = found->second; |
| 667 for (FileSystemURLSet::const_iterator iter = urls.begin(); | 668 for (FileSystemURLSet::const_iterator iter = urls.begin(); |
| 668 iter != urls.end(); ++iter) { | 669 iter != urls.end(); ++iter) { |
| 669 if (file_system_context_->GetUpdateObservers(iter->type())) { | 670 if (file_system_context_->GetUpdateObservers(iter->type())) { |
| 670 file_system_context_->GetUpdateObservers(iter->type())->Notify( | 671 file_system_context_->GetUpdateObservers(iter->type())->Notify( |
| 671 &FileUpdateObserver::OnEndUpdate, base::MakeTuple(*iter)); | 672 &FileUpdateObserver::OnEndUpdate, std::make_tuple(*iter)); |
| 672 } | 673 } |
| 673 } | 674 } |
| 674 write_target_urls_.erase(found); | 675 write_target_urls_.erase(found); |
| 675 } | 676 } |
| 676 | 677 |
| 677 // IDMap::Lookup fails if the operation is NULL, so we don't check | 678 // IDMap::Lookup fails if the operation is NULL, so we don't check |
| 678 // operations_.Lookup(id) here. | 679 // operations_.Lookup(id) here. |
| 679 | 680 |
| 680 operations_.Remove(id); | 681 operations_.Remove(id); |
| 681 finished_operations_.erase(id); | 682 finished_operations_.erase(id); |
| 682 | 683 |
| 683 // Dispatch stray cancel callback if exists. | 684 // Dispatch stray cancel callback if exists. |
| 684 std::map<OperationID, StatusCallback>::iterator found_cancel = | 685 std::map<OperationID, StatusCallback>::iterator found_cancel = |
| 685 stray_cancel_callbacks_.find(id); | 686 stray_cancel_callbacks_.find(id); |
| 686 if (found_cancel != stray_cancel_callbacks_.end()) { | 687 if (found_cancel != stray_cancel_callbacks_.end()) { |
| 687 // This cancel has been requested after the operation has finished, | 688 // This cancel has been requested after the operation has finished, |
| 688 // so report that we failed to stop it. | 689 // so report that we failed to stop it. |
| 689 found_cancel->second.Run(base::File::FILE_ERROR_INVALID_OPERATION); | 690 found_cancel->second.Run(base::File::FILE_ERROR_INVALID_OPERATION); |
| 690 stray_cancel_callbacks_.erase(found_cancel); | 691 stray_cancel_callbacks_.erase(found_cancel); |
| 691 } | 692 } |
| 692 } | 693 } |
| 693 | 694 |
| 694 } // namespace storage | 695 } // namespace storage |
| OLD | NEW |