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..d8b72157ca0043c6aaa0c2fc974b9ddff65c517e 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,12 @@ 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(); |
+ running_copy_set_[impl_ptr] = 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 +895,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.first->Cancel(); |
} |
void CopyOrMoveOperationDelegate::DidCopyOrMoveFile( |
@@ -905,7 +906,6 @@ void CopyOrMoveOperationDelegate::DidCopyOrMoveFile( |
CopyOrMoveImpl* impl, |
base::File::Error error) { |
running_copy_set_.erase(impl); |
- delete impl; |
if (!progress_callback_.is_null() && error != base::File::FILE_OK && |
error != base::File::FILE_ERROR_NOT_A_FILE) |