Chromium Code Reviews| Index: storage/browser/fileapi/copy_or_move_operation_delegate.cc |
| diff --git a/storage/browser/fileapi/copy_or_move_operation_delegate.cc b/storage/browser/fileapi/copy_or_move_operation_delegate.cc |
| index d406526966135ee24d5d3040d33c2a02650f4bd0..54696eac9b0b7f10aa32ac88d3f3ff7e0134a4c5 100644 |
| --- a/storage/browser/fileapi/copy_or_move_operation_delegate.cc |
| +++ b/storage/browser/fileapi/copy_or_move_operation_delegate.cc |
| @@ -13,6 +13,7 @@ |
| #include "base/bind.h" |
| #include "base/files/file_path.h" |
| #include "base/macros.h" |
| +#include "base/memory/ptr_util.h" |
| #include "net/base/io_buffer.h" |
| #include "net/base/net_errors.h" |
| #include "storage/browser/blob/shareable_file_reference.h" |
| @@ -754,7 +755,6 @@ CopyOrMoveOperationDelegate::CopyOrMoveOperationDelegate( |
| } |
| CopyOrMoveOperationDelegate::~CopyOrMoveOperationDelegate() { |
| - base::STLDeleteElements(&running_copy_set_); |
| } |
| void CopyOrMoveOperationDelegate::Run() { |
| @@ -795,13 +795,13 @@ void CopyOrMoveOperationDelegate::ProcessFile( |
| } |
| FileSystemURL dest_url = CreateDestURL(src_url); |
| - CopyOrMoveImpl* impl = NULL; |
| + std::unique_ptr<CopyOrMoveImpl> impl; |
| if (same_file_system_ && |
| (file_system_context() |
| ->GetFileSystemBackend(src_url.type()) |
| ->HasInplaceCopyImplementation(src_url.type()) || |
| operation_type_ == OPERATION_MOVE)) { |
| - impl = new CopyOrMoveOnSameFileSystemImpl( |
| + impl = base::MakeUnique<CopyOrMoveOnSameFileSystemImpl>( |
| operation_runner(), operation_type_, src_url, dest_url, option_, |
| base::Bind(&CopyOrMoveOperationDelegate::OnCopyFileProgress, |
| weak_factory_.GetWeakPtr(), src_url)); |
| @@ -827,7 +827,7 @@ void CopyOrMoveOperationDelegate::ProcessFile( |
| std::unique_ptr<FileStreamWriter> writer = |
| file_system_context()->CreateFileStreamWriter(dest_url, 0); |
| if (reader && writer) { |
| - impl = new StreamCopyOrMoveImpl( |
| + impl = base::MakeUnique<StreamCopyOrMoveImpl>( |
| operation_runner(), file_system_context(), operation_type_, src_url, |
| dest_url, option_, std::move(reader), std::move(writer), |
| base::Bind(&CopyOrMoveOperationDelegate::OnCopyFileProgress, |
| @@ -836,7 +836,7 @@ void CopyOrMoveOperationDelegate::ProcessFile( |
| } |
| if (!impl) { |
| - impl = new SnapshotCopyOrMoveImpl( |
| + impl = base::MakeUnique<SnapshotCopyOrMoveImpl>( |
| operation_runner(), operation_type_, src_url, dest_url, option_, |
| validator_factory, |
| base::Bind(&CopyOrMoveOperationDelegate::OnCopyFileProgress, |
| @@ -845,10 +845,13 @@ void CopyOrMoveOperationDelegate::ProcessFile( |
| } |
| // Register the running task. |
| - running_copy_set_.insert(impl); |
| - impl->Run(base::Bind( |
| - &CopyOrMoveOperationDelegate::DidCopyOrMoveFile, |
| - weak_factory_.GetWeakPtr(), src_url, dest_url, callback, impl)); |
| + |
| + CopyOrMoveImpl* impl_ptr = impl.get(); |
| + ; |
|
danakj
2016/10/03 22:51:49
extra;
Avi (use Gerrit)
2016/10/04 15:56:22
Done.
|
| + running_copy_set_.insert(std::move(impl)); |
| + impl_ptr->Run(base::Bind(&CopyOrMoveOperationDelegate::DidCopyOrMoveFile, |
| + weak_factory_.GetWeakPtr(), src_url, dest_url, |
| + callback, impl_ptr)); |
| } |
| void CopyOrMoveOperationDelegate::ProcessDirectory( |
| @@ -893,9 +896,8 @@ void CopyOrMoveOperationDelegate::PostProcessDirectory( |
| void CopyOrMoveOperationDelegate::OnCancel() { |
| // Request to cancel all running Copy/Move file. |
| - for (std::set<CopyOrMoveImpl*>::iterator iter = running_copy_set_.begin(); |
| - iter != running_copy_set_.end(); ++iter) |
| - (*iter)->Cancel(); |
| + for (auto& job : running_copy_set_) |
| + job->Cancel(); |
| } |
| void CopyOrMoveOperationDelegate::DidCopyOrMoveFile( |
| @@ -904,8 +906,11 @@ void CopyOrMoveOperationDelegate::DidCopyOrMoveFile( |
| const StatusCallback& callback, |
| CopyOrMoveImpl* impl, |
| base::File::Error error) { |
| - running_copy_set_.erase(impl); |
| - delete impl; |
| + running_copy_set_.erase( |
|
danakj
2016/10/03 22:51:49
I assume this set is small and not being called mu
Avi (use Gerrit)
2016/10/04 15:56:22
Switching to map.
|
| + std::find_if(running_copy_set_.begin(), running_copy_set_.end(), |
| + [impl](const std::unique_ptr<CopyOrMoveImpl>& ptr) { |
| + return ptr.get() == impl; |
| + })); |
| if (!progress_callback_.is_null() && error != base::File::FILE_OK && |
| error != base::File::FILE_ERROR_NOT_A_FILE) |