Commit 2e0573cb authored by Austin Sullivan's avatar Austin Sullivan Committed by Commit Bot

Fix SandboxFileStreamWriter Flush() method

- Add DidFlush() method which checks for cancellation
  before flush completes.
- This should fix the behavior of Cancel()

Bug: N/A
Change-Id: I763f5f87eaed80c7a8f1962d781a749d8a63b2f8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2456866Reviewed-by: default avatarMarijn Kruisselbrink <mek@chromium.org>
Commit-Queue: Austin Sullivan <asully@chromium.org>
Cr-Commit-Position: refs/heads/master@{#817003}
parent ccee000d
......@@ -266,7 +266,23 @@ int SandboxFileStreamWriter::Flush(net::CompletionOnceCallback callback) {
if (!file_writer_)
return net::OK;
return file_writer_->Flush(std::move(callback));
has_pending_operation_ = true;
int result = file_writer_->Flush(
base::BindOnce(&SandboxFileStreamWriter::DidFlush,
weak_factory_.GetWeakPtr(), std::move(callback)));
if (result != net::ERR_IO_PENDING)
has_pending_operation_ = false;
return result;
}
void SandboxFileStreamWriter::DidFlush(net::CompletionOnceCallback callback,
int result) {
DCHECK(has_pending_operation_);
if (CancelIfRequested())
return;
has_pending_operation_ = false;
std::move(callback).Run(result);
}
} // namespace storage
......@@ -64,6 +64,8 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) SandboxFileStreamWriter
void DidWrite(int write_response);
void DidFlush(net::CompletionOnceCallback callback, int result);
// Stops the in-flight operation, calls |cancel_callback_| and returns true
// if there's a pending cancel request.
bool CancelIfRequested();
......
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