Commit 3b88e5b9 authored by Josip Sokcevic's avatar Josip Sokcevic Committed by Commit Bot

Introduce base::OnceClosure CancelCallbackOnce

Convert UploadNewFile, UploadExistingFile and ResumeUploadFile to use
CancelCallbackOnce. There is no actual usage of those calbacks.

Bug: 1007686
Change-Id: I42ce6dc010d275aa87fa17f9f81e044f7a4c348d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2298526Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarNaoki Fukino <fukino@chromium.org>
Commit-Queue: Josip Sokcevic <sokcevic@google.com>
Cr-Commit-Position: refs/heads/master@{#788686}
parent e9f80f5b
...@@ -33,7 +33,7 @@ void DriveUploaderOnWorker::StartBatchProcessing() { ...@@ -33,7 +33,7 @@ void DriveUploaderOnWorker::StartBatchProcessing() {
void DriveUploaderOnWorker::StopBatchProcessing() { void DriveUploaderOnWorker::StopBatchProcessing() {
} }
google_apis::CancelCallback DriveUploaderOnWorker::UploadNewFile( google_apis::CancelCallbackOnce DriveUploaderOnWorker::UploadNewFile(
const std::string& parent_resource_id, const std::string& parent_resource_id,
const base::FilePath& local_file_path, const base::FilePath& local_file_path,
const std::string& title, const std::string& title,
...@@ -51,10 +51,10 @@ google_apis::CancelCallback DriveUploaderOnWorker::UploadNewFile( ...@@ -51,10 +51,10 @@ google_apis::CancelCallback DriveUploaderOnWorker::UploadNewFile(
RelayCallbackToTaskRunner(worker_task_runner_.get(), FROM_HERE, RelayCallbackToTaskRunner(worker_task_runner_.get(), FROM_HERE,
std::move(callback)))); std::move(callback))));
return google_apis::CancelCallback(); return google_apis::CancelCallbackOnce();
} }
google_apis::CancelCallback DriveUploaderOnWorker::UploadExistingFile( google_apis::CancelCallbackOnce DriveUploaderOnWorker::UploadExistingFile(
const std::string& resource_id, const std::string& resource_id,
const base::FilePath& local_file_path, const base::FilePath& local_file_path,
const std::string& content_type, const std::string& content_type,
...@@ -71,17 +71,17 @@ google_apis::CancelCallback DriveUploaderOnWorker::UploadExistingFile( ...@@ -71,17 +71,17 @@ google_apis::CancelCallback DriveUploaderOnWorker::UploadExistingFile(
RelayCallbackToTaskRunner(worker_task_runner_.get(), FROM_HERE, RelayCallbackToTaskRunner(worker_task_runner_.get(), FROM_HERE,
std::move(callback)))); std::move(callback))));
return google_apis::CancelCallback(); return google_apis::CancelCallbackOnce();
} }
google_apis::CancelCallback DriveUploaderOnWorker::ResumeUploadFile( google_apis::CancelCallbackOnce DriveUploaderOnWorker::ResumeUploadFile(
const GURL& upload_location, const GURL& upload_location,
const base::FilePath& local_file_path, const base::FilePath& local_file_path,
const std::string& content_type, const std::string& content_type,
drive::UploadCompletionCallback callback, drive::UploadCompletionCallback callback,
google_apis::ProgressCallback progress_callback) { google_apis::ProgressCallback progress_callback) {
NOTREACHED(); NOTREACHED();
return google_apis::CancelCallback(); return google_apis::CancelCallbackOnce();
} }
} // namespace drive_backend } // namespace drive_backend
......
...@@ -37,7 +37,7 @@ class DriveUploaderOnWorker : public drive::DriveUploaderInterface { ...@@ -37,7 +37,7 @@ class DriveUploaderOnWorker : public drive::DriveUploaderInterface {
void StartBatchProcessing() override; void StartBatchProcessing() override;
void StopBatchProcessing() override; void StopBatchProcessing() override;
google_apis::CancelCallback UploadNewFile( google_apis::CancelCallbackOnce UploadNewFile(
const std::string& parent_resource_id, const std::string& parent_resource_id,
const base::FilePath& local_file_path, const base::FilePath& local_file_path,
const std::string& title, const std::string& title,
...@@ -46,7 +46,7 @@ class DriveUploaderOnWorker : public drive::DriveUploaderInterface { ...@@ -46,7 +46,7 @@ class DriveUploaderOnWorker : public drive::DriveUploaderInterface {
drive::UploadCompletionCallback callback, drive::UploadCompletionCallback callback,
google_apis::ProgressCallback progress_callback) override; google_apis::ProgressCallback progress_callback) override;
google_apis::CancelCallback UploadExistingFile( google_apis::CancelCallbackOnce UploadExistingFile(
const std::string& resource_id, const std::string& resource_id,
const base::FilePath& local_file_path, const base::FilePath& local_file_path,
const std::string& content_type, const std::string& content_type,
...@@ -55,7 +55,7 @@ class DriveUploaderOnWorker : public drive::DriveUploaderInterface { ...@@ -55,7 +55,7 @@ class DriveUploaderOnWorker : public drive::DriveUploaderInterface {
google_apis::ProgressCallback progress_callback) override; google_apis::ProgressCallback progress_callback) override;
// Following method is expected not to be used. // Following method is expected not to be used.
google_apis::CancelCallback ResumeUploadFile( google_apis::CancelCallbackOnce ResumeUploadFile(
const GURL& upload_location, const GURL& upload_location,
const base::FilePath& local_file_path, const base::FilePath& local_file_path,
const std::string& content_type, const std::string& content_type,
......
...@@ -11,14 +11,16 @@ ...@@ -11,14 +11,16 @@
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "google_apis/drive/drive_api_parser.h" #include "google_apis/drive/drive_api_parser.h"
#include "google_apis/drive/drive_common_callbacks.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
using drive::FakeDriveService; using drive::FakeDriveService;
using drive::UploadCompletionCallback; using drive::UploadCompletionCallback;
using google_apis::CancelCallback; using google_apis::CancelCallback;
using google_apis::CancelCallbackOnce;
using google_apis::DriveApiErrorCode;
using google_apis::FileResource; using google_apis::FileResource;
using google_apis::FileResourceCallback; using google_apis::FileResourceCallback;
using google_apis::DriveApiErrorCode;
using google_apis::ProgressCallback; using google_apis::ProgressCallback;
namespace sync_file_system { namespace sync_file_system {
...@@ -85,7 +87,7 @@ void FakeDriveUploader::StartBatchProcessing() { ...@@ -85,7 +87,7 @@ void FakeDriveUploader::StartBatchProcessing() {
void FakeDriveUploader::StopBatchProcessing() { void FakeDriveUploader::StopBatchProcessing() {
} }
CancelCallback FakeDriveUploader::UploadNewFile( CancelCallbackOnce FakeDriveUploader::UploadNewFile(
const std::string& parent_resource_id, const std::string& parent_resource_id,
const base::FilePath& local_file_path, const base::FilePath& local_file_path,
const std::string& title, const std::string& title,
...@@ -109,10 +111,10 @@ CancelCallback FakeDriveUploader::UploadNewFile( ...@@ -109,10 +111,10 @@ CancelCallback FakeDriveUploader::UploadNewFile(
base::BindOnce(&DidAddFileForUploadNew, std::move(callback))); base::BindOnce(&DidAddFileForUploadNew, std::move(callback)));
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
return CancelCallback(); return CancelCallbackOnce();
} }
CancelCallback FakeDriveUploader::UploadExistingFile( CancelCallbackOnce FakeDriveUploader::UploadExistingFile(
const std::string& resource_id, const std::string& resource_id,
const base::FilePath& local_file_path, const base::FilePath& local_file_path,
const std::string& content_type, const std::string& content_type,
...@@ -120,12 +122,13 @@ CancelCallback FakeDriveUploader::UploadExistingFile( ...@@ -120,12 +122,13 @@ CancelCallback FakeDriveUploader::UploadExistingFile(
UploadCompletionCallback callback, UploadCompletionCallback callback,
ProgressCallback progress_callback) { ProgressCallback progress_callback) {
DCHECK(!callback.is_null()); DCHECK(!callback.is_null());
return fake_drive_service_->GetFileResource( fake_drive_service_->GetFileResource(
resource_id, base::BindOnce(&DidGetFileResourceForUploadExisting, resource_id, base::BindOnce(&DidGetFileResourceForUploadExisting,
std::move(callback))); std::move(callback)));
return CancelCallbackOnce();
} }
CancelCallback FakeDriveUploader::ResumeUploadFile( CancelCallbackOnce FakeDriveUploader::ResumeUploadFile(
const GURL& upload_location, const GURL& upload_location,
const base::FilePath& local_file_path, const base::FilePath& local_file_path,
const std::string& content_type, const std::string& content_type,
...@@ -134,7 +137,7 @@ CancelCallback FakeDriveUploader::ResumeUploadFile( ...@@ -134,7 +137,7 @@ CancelCallback FakeDriveUploader::ResumeUploadFile(
// At the moment, sync file system doesn't support resuming of the uploading. // At the moment, sync file system doesn't support resuming of the uploading.
// So this method shouldn't be reached. // So this method shouldn't be reached.
NOTREACHED(); NOTREACHED();
return CancelCallback(); return CancelCallbackOnce();
} }
} // namespace drive_backend } // namespace drive_backend
......
...@@ -52,7 +52,7 @@ class FakeDriveUploader : public drive::DriveUploaderInterface { ...@@ -52,7 +52,7 @@ class FakeDriveUploader : public drive::DriveUploaderInterface {
// DriveUploaderInterface overrides. // DriveUploaderInterface overrides.
void StartBatchProcessing() override; void StartBatchProcessing() override;
void StopBatchProcessing() override; void StopBatchProcessing() override;
google_apis::CancelCallback UploadNewFile( google_apis::CancelCallbackOnce UploadNewFile(
const std::string& parent_resource_id, const std::string& parent_resource_id,
const base::FilePath& local_file_path, const base::FilePath& local_file_path,
const std::string& title, const std::string& title,
...@@ -60,14 +60,14 @@ class FakeDriveUploader : public drive::DriveUploaderInterface { ...@@ -60,14 +60,14 @@ class FakeDriveUploader : public drive::DriveUploaderInterface {
const drive::UploadNewFileOptions& options, const drive::UploadNewFileOptions& options,
drive::UploadCompletionCallback callback, drive::UploadCompletionCallback callback,
google_apis::ProgressCallback progress_callback) override; google_apis::ProgressCallback progress_callback) override;
google_apis::CancelCallback UploadExistingFile( google_apis::CancelCallbackOnce UploadExistingFile(
const std::string& resource_id, const std::string& resource_id,
const base::FilePath& local_file_path, const base::FilePath& local_file_path,
const std::string& content_type, const std::string& content_type,
const drive::UploadExistingFileOptions& options, const drive::UploadExistingFileOptions& options,
drive::UploadCompletionCallback callback, drive::UploadCompletionCallback callback,
google_apis::ProgressCallback progress_callback) override; google_apis::ProgressCallback progress_callback) override;
google_apis::CancelCallback ResumeUploadFile( google_apis::CancelCallbackOnce ResumeUploadFile(
const GURL& upload_location, const GURL& upload_location,
const base::FilePath& local_file_path, const base::FilePath& local_file_path,
const std::string& content_type, const std::string& content_type,
......
...@@ -20,10 +20,11 @@ ...@@ -20,10 +20,11 @@
#include "services/device/public/mojom/wake_lock.mojom.h" #include "services/device/public/mojom/wake_lock.mojom.h"
using google_apis::CancelCallback; using google_apis::CancelCallback;
using google_apis::FileResource; using google_apis::CancelCallbackOnce;
using google_apis::DRIVE_CANCELLED; using google_apis::DRIVE_CANCELLED;
using google_apis::DriveApiErrorCode;
using google_apis::DRIVE_NO_SPACE; using google_apis::DRIVE_NO_SPACE;
using google_apis::DriveApiErrorCode;
using google_apis::FileResource;
using google_apis::HTTP_CONFLICT; using google_apis::HTTP_CONFLICT;
using google_apis::HTTP_CREATED; using google_apis::HTTP_CREATED;
using google_apis::HTTP_FORBIDDEN; using google_apis::HTTP_FORBIDDEN;
...@@ -120,8 +121,9 @@ struct DriveUploader::UploadFileInfo { ...@@ -120,8 +121,9 @@ struct DriveUploader::UploadFileInfo {
} }
// Returns the callback to cancel the upload represented by this struct. // Returns the callback to cancel the upload represented by this struct.
CancelCallback GetCancelCallback() { CancelCallbackOnce GetCancelCallback() {
return base::Bind(&UploadFileInfo::Cancel, weak_ptr_factory_.GetWeakPtr()); return base::BindOnce(&UploadFileInfo::Cancel,
weak_ptr_factory_.GetWeakPtr());
} }
// The local file path of the file to be uploaded. // The local file path of the file to be uploaded.
...@@ -179,7 +181,7 @@ DriveUploader::DriveUploader( ...@@ -179,7 +181,7 @@ DriveUploader::DriveUploader(
DriveUploader::~DriveUploader() = default; DriveUploader::~DriveUploader() = default;
CancelCallback DriveUploader::UploadNewFile( CancelCallbackOnce DriveUploader::UploadNewFile(
const std::string& parent_resource_id, const std::string& parent_resource_id,
const base::FilePath& local_file_path, const base::FilePath& local_file_path,
const std::string& title, const std::string& title,
...@@ -213,7 +215,7 @@ void DriveUploader::StopBatchProcessing() { ...@@ -213,7 +215,7 @@ void DriveUploader::StopBatchProcessing() {
current_batch_request_ = nullptr; current_batch_request_ = nullptr;
} }
CancelCallback DriveUploader::UploadExistingFile( CancelCallbackOnce DriveUploader::UploadExistingFile(
const std::string& resource_id, const std::string& resource_id,
const base::FilePath& local_file_path, const base::FilePath& local_file_path,
const std::string& content_type, const std::string& content_type,
...@@ -235,7 +237,7 @@ CancelCallback DriveUploader::UploadExistingFile( ...@@ -235,7 +237,7 @@ CancelCallback DriveUploader::UploadExistingFile(
current_batch_request_)); current_batch_request_));
} }
CancelCallback DriveUploader::ResumeUploadFile( CancelCallbackOnce DriveUploader::ResumeUploadFile(
const GURL& upload_location, const GURL& upload_location,
const base::FilePath& local_file_path, const base::FilePath& local_file_path,
const std::string& content_type, const std::string& content_type,
...@@ -256,7 +258,7 @@ CancelCallback DriveUploader::ResumeUploadFile( ...@@ -256,7 +258,7 @@ CancelCallback DriveUploader::ResumeUploadFile(
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
} }
CancelCallback DriveUploader::StartUploadFile( CancelCallbackOnce DriveUploader::StartUploadFile(
std::unique_ptr<UploadFileInfo> upload_file_info, std::unique_ptr<UploadFileInfo> upload_file_info,
StartInitiateUploadCallback start_initiate_upload_callback) { StartInitiateUploadCallback start_initiate_upload_callback) {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
......
...@@ -79,7 +79,7 @@ class DriveUploaderInterface { ...@@ -79,7 +79,7 @@ class DriveUploaderInterface {
// progress_callback: // progress_callback:
// Periodically called back with the total number of bytes sent so far. // Periodically called back with the total number of bytes sent so far.
// May be null if the information is not needed. // May be null if the information is not needed.
virtual google_apis::CancelCallback UploadNewFile( virtual google_apis::CancelCallbackOnce UploadNewFile(
const std::string& parent_resource_id, const std::string& parent_resource_id,
const base::FilePath& local_file_path, const base::FilePath& local_file_path,
const std::string& title, const std::string& title,
...@@ -99,7 +99,7 @@ class DriveUploaderInterface { ...@@ -99,7 +99,7 @@ class DriveUploaderInterface {
// Expected ETag for the destination file. If it does not match, the upload // Expected ETag for the destination file. If it does not match, the upload
// fails with UPLOAD_ERROR_CONFLICT. // fails with UPLOAD_ERROR_CONFLICT.
// If |etag| is empty, the test is skipped. // If |etag| is empty, the test is skipped.
virtual google_apis::CancelCallback UploadExistingFile( virtual google_apis::CancelCallbackOnce UploadExistingFile(
const std::string& resource_id, const std::string& resource_id,
const base::FilePath& local_file_path, const base::FilePath& local_file_path,
const std::string& content_type, const std::string& content_type,
...@@ -113,7 +113,7 @@ class DriveUploaderInterface { ...@@ -113,7 +113,7 @@ class DriveUploaderInterface {
// |content_type| must be set to the same ones for previous invocation. // |content_type| must be set to the same ones for previous invocation.
// //
// See comments at UploadNewFile about common parameters and the return value. // See comments at UploadNewFile about common parameters and the return value.
virtual google_apis::CancelCallback ResumeUploadFile( virtual google_apis::CancelCallbackOnce ResumeUploadFile(
const GURL& upload_location, const GURL& upload_location,
const base::FilePath& local_file_path, const base::FilePath& local_file_path,
const std::string& content_type, const std::string& content_type,
...@@ -134,7 +134,7 @@ class DriveUploader : public DriveUploaderInterface { ...@@ -134,7 +134,7 @@ class DriveUploader : public DriveUploaderInterface {
// DriveUploaderInterface overrides. // DriveUploaderInterface overrides.
void StartBatchProcessing() override; void StartBatchProcessing() override;
void StopBatchProcessing() override; void StopBatchProcessing() override;
google_apis::CancelCallback UploadNewFile( google_apis::CancelCallbackOnce UploadNewFile(
const std::string& parent_resource_id, const std::string& parent_resource_id,
const base::FilePath& local_file_path, const base::FilePath& local_file_path,
const std::string& title, const std::string& title,
...@@ -142,14 +142,14 @@ class DriveUploader : public DriveUploaderInterface { ...@@ -142,14 +142,14 @@ class DriveUploader : public DriveUploaderInterface {
const UploadNewFileOptions& options, const UploadNewFileOptions& options,
UploadCompletionCallback callback, UploadCompletionCallback callback,
google_apis::ProgressCallback progress_callback) override; google_apis::ProgressCallback progress_callback) override;
google_apis::CancelCallback UploadExistingFile( google_apis::CancelCallbackOnce UploadExistingFile(
const std::string& resource_id, const std::string& resource_id,
const base::FilePath& local_file_path, const base::FilePath& local_file_path,
const std::string& content_type, const std::string& content_type,
const UploadExistingFileOptions& options, const UploadExistingFileOptions& options,
UploadCompletionCallback callback, UploadCompletionCallback callback,
google_apis::ProgressCallback progress_callback) override; google_apis::ProgressCallback progress_callback) override;
google_apis::CancelCallback ResumeUploadFile( google_apis::CancelCallbackOnce ResumeUploadFile(
const GURL& upload_location, const GURL& upload_location,
const base::FilePath& local_file_path, const base::FilePath& local_file_path,
const std::string& content_type, const std::string& content_type,
...@@ -164,7 +164,7 @@ class DriveUploader : public DriveUploaderInterface { ...@@ -164,7 +164,7 @@ class DriveUploader : public DriveUploaderInterface {
StartInitiateUploadCallback; StartInitiateUploadCallback;
// Starts uploading a file with |upload_file_info|. // Starts uploading a file with |upload_file_info|.
google_apis::CancelCallback StartUploadFile( google_apis::CancelCallbackOnce StartUploadFile(
std::unique_ptr<UploadFileInfo> upload_file_info, std::unique_ptr<UploadFileInfo> upload_file_info,
StartInitiateUploadCallback start_initiate_upload_callback); StartInitiateUploadCallback start_initiate_upload_callback);
void StartUploadFileAfterGetFileSize( void StartUploadFileAfterGetFileSize(
......
...@@ -23,6 +23,8 @@ typedef base::OnceCallback<void(DriveApiErrorCode error, ...@@ -23,6 +23,8 @@ typedef base::OnceCallback<void(DriveApiErrorCode error,
// this type of closure. If it is called during the request is in-flight, the // this type of closure. If it is called during the request is in-flight, the
// callback passed with the request is invoked with DRIVE_CANCELLED. If the // callback passed with the request is invoked with DRIVE_CANCELLED. If the
// request is already finished, nothing happens. // request is already finished, nothing happens.
typedef base::OnceClosure CancelCallbackOnce;
// TODO(https://crbug.com/1007686): Remove usage of CancelCallback
typedef base::Closure CancelCallback; typedef base::Closure CancelCallback;
} // namespace google_apis } // namespace google_apis
......
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