Commit 902a75dc authored by Anand K. Mistry's avatar Anand K. Mistry Committed by Commit Bot

Convert Callback -> {Once,Repeating}Callback in //chrome/utility/image_writer

Bug: 1007645
Change-Id: Ie5bb04e446051089e45e6be3d0f0683f8395d3f6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1930249
Commit-Queue: Anand Mistry <amistry@chromium.org>
Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#718916}
parent 701b32b0
......@@ -30,13 +30,19 @@ DiskUnmounterMac::~DiskUnmounterMac() {
}
void DiskUnmounterMac::Unmount(const std::string& device_path,
const base::Closure& success_continuation,
const base::Closure& failure_continuation) {
base::OnceClosure success_continuation,
base::OnceClosure failure_continuation) {
// Should only be used once.
DCHECK(!original_thread_.get());
DCHECK(!success_continuation_);
DCHECK(!failure_continuation_);
DCHECK(success_continuation);
DCHECK(failure_continuation);
original_thread_ = base::ThreadTaskRunnerHandle::Get();
success_continuation_ = success_continuation;
failure_continuation_ = failure_continuation;
success_continuation_ = std::move(success_continuation);
failure_continuation_ = std::move(failure_continuation);
cf_thread_.task_runner()->PostTask(
FROM_HERE, base::BindOnce(&DiskUnmounterMac::UnmountOnWorker,
......@@ -85,7 +91,7 @@ void DiskUnmounterMac::DiskUnmounted(DADiskRef disk,
}
disk_unmounter->original_thread_->PostTask(
FROM_HERE, disk_unmounter->success_continuation_);
FROM_HERE, std::move(disk_unmounter->success_continuation_));
}
void DiskUnmounterMac::UnmountOnWorker(const std::string& device_path) {
......@@ -114,7 +120,7 @@ void DiskUnmounterMac::UnmountOnWorker(const std::string& device_path) {
}
void DiskUnmounterMac::Error() {
original_thread_->PostTask(FROM_HERE, failure_continuation_);
original_thread_->PostTask(FROM_HERE, std::move(failure_continuation_));
}
} // namespace image_writer
......@@ -34,8 +34,8 @@ class DiskUnmounterMac {
// the |continuation| when complete. This can be called from any thread.
// The continuation will be run on the thread this object was created on.
void Unmount(const std::string& device_path,
const base::Closure& success_continuation,
const base::Closure& failure_continuation);
base::OnceClosure success_continuation,
base::OnceClosure failure_continuation);
private:
// Handles disk-claimed callbacks.
......@@ -56,8 +56,8 @@ class DiskUnmounterMac {
void Error();
scoped_refptr<base::SingleThreadTaskRunner> original_thread_;
base::Closure success_continuation_;
base::Closure failure_continuation_;
base::OnceClosure success_continuation_;
base::OnceClosure failure_continuation_;
base::ScopedCFTypeRef<DADiskRef> disk_;
base::ScopedCFTypeRef<DASessionRef> session_;
......
......@@ -51,7 +51,7 @@ void ImageWriter::Write() {
}
PostProgress(0);
PostTask(base::Bind(&ImageWriter::WriteChunk, AsWeakPtr()));
PostTask(base::BindOnce(&ImageWriter::WriteChunk, AsWeakPtr()));
}
void ImageWriter::Verify() {
......@@ -60,7 +60,7 @@ void ImageWriter::Verify() {
}
PostProgress(0);
PostTask(base::Bind(&ImageWriter::VerifyChunk, AsWeakPtr()));
PostTask(base::BindOnce(&ImageWriter::VerifyChunk, AsWeakPtr()));
}
void ImageWriter::Cancel() {
......@@ -74,8 +74,8 @@ const base::FilePath& ImageWriter::GetImagePath() { return image_path_; }
const base::FilePath& ImageWriter::GetDevicePath() { return device_path_; }
void ImageWriter::PostTask(const base::Closure& task) {
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task);
void ImageWriter::PostTask(base::OnceClosure task) {
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, std::move(task));
}
void ImageWriter::PostProgress(int64_t progress) {
......@@ -143,7 +143,7 @@ void ImageWriter::WriteChunk() {
bytes_processed_ += bytes_read;
PostProgress(bytes_processed_);
PostTask(base::Bind(&ImageWriter::WriteChunk, AsWeakPtr()));
PostTask(base::BindOnce(&ImageWriter::WriteChunk, AsWeakPtr()));
} else if (bytes_read == 0) {
// End of file.
device_file_.Flush();
......@@ -189,7 +189,7 @@ void ImageWriter::VerifyChunk() {
bytes_processed_ += bytes_read;
PostProgress(bytes_processed_);
PostTask(base::Bind(&ImageWriter::VerifyChunk, AsWeakPtr()));
PostTask(base::BindOnce(&ImageWriter::VerifyChunk, AsWeakPtr()));
} else if (bytes_read == 0) {
// End of file.
handler_->SendSucceeded();
......
......@@ -53,7 +53,7 @@ class ImageWriter : public base::SupportsWeakPtr<ImageWriter> {
bool IsValidDevice();
// Unmounts all volumes on the target device.
// This method has OS-specific implementations.
void UnmountVolumes(const base::Closure& continuation);
void UnmountVolumes(base::OnceClosure continuation);
// Return the current image path.
const base::FilePath& GetImagePath();
......@@ -62,7 +62,7 @@ class ImageWriter : public base::SupportsWeakPtr<ImageWriter> {
private:
// Convenience wrappers.
void PostTask(const base::Closure& task);
void PostTask(base::OnceClosure task);
void PostProgress(int64_t progress);
void Error(const std::string& message);
......
......@@ -63,7 +63,7 @@ void ImageWriterHandler::Write(
}
image_writer_->UnmountVolumes(
base::Bind(&ImageWriter::Write, image_writer_->AsWeakPtr()));
base::BindOnce(&ImageWriter::Write, image_writer_->AsWeakPtr()));
}
void ImageWriterHandler::Verify(
......
......@@ -50,15 +50,14 @@ bool ImageWriter::IsValidDevice() {
nullptr, nullptr);
}
void ImageWriter::UnmountVolumes(const base::Closure& continuation) {
void ImageWriter::UnmountVolumes(base::OnceClosure continuation) {
if (!unmounter_)
unmounter_.reset(new DiskUnmounterMac());
unmounter_->Unmount(
device_path_.value(),
continuation,
base::Bind(
&ImageWriter::Error, base::Unretained(this), error::kUnmountVolumes));
device_path_.value(), std::move(continuation),
base::BindOnce(&ImageWriter::Error, base::Unretained(this),
error::kUnmountVolumes));
}
bool ImageWriter::OpenDevice() {
......
......@@ -14,7 +14,7 @@ bool ImageWriter::IsValidDevice() {
return false;
}
void ImageWriter::UnmountVolumes(const base::Closure& continuation) {
void ImageWriter::UnmountVolumes(base::OnceClosure continuation) {
NOTIMPLEMENTED();
return;
}
......
......@@ -71,7 +71,7 @@ bool ImageWriter::OpenDevice() {
return device_file_.IsValid();
}
void ImageWriter::UnmountVolumes(const base::Closure& continuation) {
void ImageWriter::UnmountVolumes(base::OnceClosure continuation) {
if (!InitializeFiles()) {
return;
}
......@@ -194,7 +194,7 @@ void ImageWriter::UnmountVolumes(const base::Closure& continuation) {
}
if (success)
continuation.Run();
std::move(continuation).Run();
}
} // namespace image_writer
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment