0

Convert google_apis::BatchableDelegate::NotifyResult to OnceClosure

Bug: 1007788
Change-Id: I8628a694a5e38552f4527bb81bd808fed4dc6cb1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1978201
Commit-Queue: Anand Mistry <amistry@chromium.org>
Auto-Submit: Anand Mistry <amistry@chromium.org>
Reviewed-by: Stuart Langley <slangley@chromium.org>
Cr-Commit-Position: refs/heads/master@{#728808}
This commit is contained in:
Anand K. Mistry
2020-01-07 05:42:06 +00:00
committed by Commit Bot
parent cb15ec6746
commit fd2e64be2d
4 changed files with 15 additions and 14 deletions

@@ -942,7 +942,7 @@ bool MultipartUploadRequestBase::GetContentData(
void MultipartUploadRequestBase::NotifyResult( void MultipartUploadRequestBase::NotifyResult(
DriveApiErrorCode code, DriveApiErrorCode code,
const std::string& body, const std::string& body,
const base::Closure& notify_complete_callback) { base::OnceClosure notify_complete_callback) {
// The upload is successfully done. Parse the response which should be // The upload is successfully done. Parse the response which should be
// the entry's metadata. // the entry's metadata.
if (code == HTTP_CREATED || code == HTTP_SUCCESS) { if (code == HTTP_CREATED || code == HTTP_SUCCESS) {
@@ -950,10 +950,10 @@ void MultipartUploadRequestBase::NotifyResult(
blocking_task_runner_.get(), body, blocking_task_runner_.get(), body,
base::BindOnce(&MultipartUploadRequestBase::OnDataParsed, base::BindOnce(&MultipartUploadRequestBase::OnDataParsed,
weak_ptr_factory_.GetWeakPtr(), code, weak_ptr_factory_.GetWeakPtr(), code,
notify_complete_callback)); std::move(notify_complete_callback)));
} else { } else {
NotifyError(MapJsonError(code, body)); NotifyError(MapJsonError(code, body));
notify_complete_callback.Run(); std::move(notify_complete_callback).Run();
} }
} }
@@ -969,14 +969,14 @@ void MultipartUploadRequestBase::NotifyUploadProgress(int64_t current,
void MultipartUploadRequestBase::OnDataParsed( void MultipartUploadRequestBase::OnDataParsed(
DriveApiErrorCode code, DriveApiErrorCode code,
const base::Closure& notify_complete_callback, base::OnceClosure notify_complete_callback,
std::unique_ptr<base::Value> value) { std::unique_ptr<base::Value> value) {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
if (value) if (value)
callback_.Run(code, google_apis::FileResource::CreateFrom(*value)); callback_.Run(code, google_apis::FileResource::CreateFrom(*value));
else else
NotifyError(DRIVE_PARSE_ERROR); NotifyError(DRIVE_PARSE_ERROR);
notify_complete_callback.Run(); std::move(notify_complete_callback).Run();
} }
//============================ DownloadFileRequestBase ========================= //============================ DownloadFileRequestBase =========================

@@ -309,7 +309,7 @@ class BatchableDelegate {
// |callback|. // |callback|.
virtual void NotifyResult(DriveApiErrorCode code, virtual void NotifyResult(DriveApiErrorCode code,
const std::string& response_body, const std::string& response_body,
const base::Closure& callback) = 0; base::OnceClosure callback) = 0;
// Notifies error. Unlike |NotifyResult|, it must report error // Notifies error. Unlike |NotifyResult|, it must report error
// synchronously. The instance may be deleted just after calling // synchronously. The instance may be deleted just after calling
@@ -575,12 +575,12 @@ class MultipartUploadRequestBase : public BatchableDelegate {
std::string* upload_content) override; std::string* upload_content) override;
void NotifyResult(DriveApiErrorCode code, void NotifyResult(DriveApiErrorCode code,
const std::string& body, const std::string& body,
const base::Closure& callback) override; base::OnceClosure callback) override;
void NotifyError(DriveApiErrorCode code) override; void NotifyError(DriveApiErrorCode code) override;
void NotifyUploadProgress(int64_t current, int64_t total) override; void NotifyUploadProgress(int64_t current, int64_t total) override;
// Parses the response value and invokes |callback_| with |FileResource|. // Parses the response value and invokes |callback_| with |FileResource|.
void OnDataParsed(DriveApiErrorCode code, void OnDataParsed(DriveApiErrorCode code,
const base::Closure& callback, base::OnceClosure callback,
std::unique_ptr<base::Value> value); std::unique_ptr<base::Value> value);
private: private:

@@ -1144,7 +1144,7 @@ void SingleBatchableDelegateRequest::ProcessURLFetchResults(
std::string response_body) { std::string response_body) {
delegate_->NotifyResult( delegate_->NotifyResult(
GetErrorCode(), response_body, GetErrorCode(), response_body,
base::Bind( base::BindOnce(
&SingleBatchableDelegateRequest::OnProcessURLFetchResultsComplete, &SingleBatchableDelegateRequest::OnProcessURLFetchResultsComplete,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
} }
@@ -1347,9 +1347,10 @@ void BatchUploadRequest::ProcessURLFetchResults(
BatchableDelegate* delegate = child_requests_[i]->request.get(); BatchableDelegate* delegate = child_requests_[i]->request.get();
// Pass ownership of |delegate| so that child_requests_.clear() won't // Pass ownership of |delegate| so that child_requests_.clear() won't
// kill the delegate. It has to be deleted after the notification. // kill the delegate. It has to be deleted after the notification.
delegate->NotifyResult(parts[i].code, parts[i].body, delegate->NotifyResult(
base::Bind(&base::DeletePointer<BatchableDelegate>, parts[i].code, parts[i].body,
child_requests_[i]->request.release())); base::BindOnce(&base::DeletePointer<BatchableDelegate>,
child_requests_[i]->request.release()));
} }
child_requests_.clear(); child_requests_.clear();

@@ -100,9 +100,9 @@ class TestBatchableDelegate : public BatchableDelegate {
void NotifyError(DriveApiErrorCode code) override { callback_.Run(); } void NotifyError(DriveApiErrorCode code) override { callback_.Run(); }
void NotifyResult(DriveApiErrorCode code, void NotifyResult(DriveApiErrorCode code,
const std::string& body, const std::string& body,
const base::Closure& closure) override { base::OnceClosure closure) override {
callback_.Run(); callback_.Run();
closure.Run(); std::move(closure).Run();
} }
void NotifyUploadProgress(int64_t current, int64_t total) override { void NotifyUploadProgress(int64_t current, int64_t total) override {
progress_values_.push_back(current); progress_values_.push_back(current);