From a91bb9341c5beded34dacad3d5d1526b1b7250dc Mon Sep 17 00:00:00 2001 From: hirono Date: Wed, 1 Apr 2015 21:08:18 -0700 Subject: [PATCH] Drive: Add definition of StartBatchRequest to DriveServiceInterface. The method starts to batch request. Client code can build batch request by using BatchRequestBuilder returned from the method. The implementation of the method will be added by the following CLs. BUG=451917 TEST=None Review URL: https://codereview.chromium.org/1047653002 Cr-Commit-Position: refs/heads/master@{#323424} --- chrome/browser/drive/drive_api_service.cc | 51 ++++++++++++++ chrome/browser/drive/drive_api_service.h | 32 +++++++++ chrome/browser/drive/drive_service_interface.h | 77 ++++++++++++++-------- chrome/browser/drive/dummy_drive_service.cc | 4 ++ chrome/browser/drive/dummy_drive_service.h | 1 + chrome/browser/drive/fake_drive_service.cc | 8 +++ chrome/browser/drive/fake_drive_service.h | 1 + .../drive_backend/drive_service_on_worker.cc | 6 ++ .../drive_backend/drive_service_on_worker.h | 2 + 9 files changed, 153 insertions(+), 29 deletions(-) diff --git a/chrome/browser/drive/drive_api_service.cc b/chrome/browser/drive/drive_api_service.cc index 4e31c3ec0faa..7a19b851359f 100644 --- a/chrome/browser/drive/drive_api_service.cc +++ b/chrome/browser/drive/drive_api_service.cc @@ -159,6 +159,51 @@ const char kDriveApiRootDirectoryResourceId[] = "root"; } // namespace +BatchRequestConfigurator::BatchRequestConfigurator() { +} + +BatchRequestConfigurator::~BatchRequestConfigurator() { +} + +google_apis::CancelCallback BatchRequestConfigurator::MultipartUploadNewFile( + const std::string& content_type, + int64 content_length, + const std::string& parent_resource_id, + const std::string& title, + const base::FilePath& local_file_path, + const UploadNewFileOptions& options, + const google_apis::FileResourceCallback& callback, + const google_apis::ProgressCallback& progress_callback) { + DCHECK(CalledOnValidThread()); + DCHECK(!callback.is_null()); + + NOTIMPLEMENTED(); + + return google_apis::CancelCallback(); +} + +google_apis::CancelCallback +BatchRequestConfigurator::MultipartUploadExistingFile( + const std::string& content_type, + int64 content_length, + const std::string& resource_id, + const base::FilePath& local_file_path, + const UploadExistingFileOptions& options, + const google_apis::FileResourceCallback& callback, + const google_apis::ProgressCallback& progress_callback) { + DCHECK(CalledOnValidThread()); + DCHECK(!callback.is_null()); + + NOTIMPLEMENTED(); + + return google_apis::CancelCallback(); +} + +void BatchRequestConfigurator::Commit() { + DCHECK(CalledOnValidThread()); + NOTIMPLEMENTED(); +} + DriveAPIService::DriveAPIService( OAuth2TokenService* oauth2_token_service, net::URLRequestContextGetter* url_request_context_getter, @@ -780,4 +825,10 @@ void DriveAPIService::OnOAuth2RefreshTokenChanged() { } } +scoped_ptr +DriveAPIService::StartBatchRequest() { + return make_scoped_ptr( + new BatchRequestConfigurator); +} + } // namespace drive diff --git a/chrome/browser/drive/drive_api_service.h b/chrome/browser/drive/drive_api_service.h index 33d847604f1a..ce1d8236a10d 100644 --- a/chrome/browser/drive/drive_api_service.h +++ b/chrome/browser/drive/drive_api_service.h @@ -34,6 +34,37 @@ class URLRequestContextGetter; namespace drive { +// Builder for batch request returned by |DriveAPIService|. +class BatchRequestConfigurator : public BatchRequestConfiguratorInterface, + public base::NonThreadSafe { + public: + BatchRequestConfigurator(); + ~BatchRequestConfigurator() override; + + // BatchRequestConfiguratorInterface overrides. + google_apis::CancelCallback MultipartUploadNewFile( + const std::string& content_type, + int64 content_length, + const std::string& parent_resource_id, + const std::string& title, + const base::FilePath& local_file_path, + const UploadNewFileOptions& options, + const google_apis::FileResourceCallback& callback, + const google_apis::ProgressCallback& progress_callback) override; + google_apis::CancelCallback MultipartUploadExistingFile( + const std::string& content_type, + int64 content_length, + const std::string& resource_id, + const base::FilePath& local_file_path, + const UploadExistingFileOptions& options, + const google_apis::FileResourceCallback& callback, + const google_apis::ProgressCallback& progress_callback) override; + void Commit() override; + + private: + DISALLOW_COPY_AND_ASSIGN(BatchRequestConfigurator); +}; + // This class provides Drive request calls using Drive V2 API. // Details of API call are abstracted in each request class and this class // works as a thin wrapper for the API. @@ -196,6 +227,7 @@ class DriveAPIService : public DriveServiceInterface, const std::string& email, google_apis::drive::PermissionRole role, const google_apis::EntryActionCallback& callback) override; + scoped_ptr StartBatchRequest() override; private: // AuthServiceObserver override. diff --git a/chrome/browser/drive/drive_service_interface.h b/chrome/browser/drive/drive_service_interface.h index 3e4f4c53da56..9fa23835c5ca 100644 --- a/chrome/browser/drive/drive_service_interface.h +++ b/chrome/browser/drive/drive_service_interface.h @@ -99,14 +99,57 @@ struct UploadExistingFileOptions { google_apis::drive::Properties properties; }; +// Interface where we define operations that can be sent in batch requests. +class DriveServiceBatchOperationsInterface { + public: + virtual ~DriveServiceBatchOperationsInterface() {} + + // Uploads a file by a single request with multipart body. It's more efficient + // for small files than using |InitiateUploadNewFile| and |ResumeUpload|. + // |content_type| and |content_length| should be the ones of the file to be + // uploaded. |callback| must not be null. |progress_callback| may be null. + virtual google_apis::CancelCallback MultipartUploadNewFile( + const std::string& content_type, + int64 content_length, + const std::string& parent_resource_id, + const std::string& title, + const base::FilePath& local_file_path, + const UploadNewFileOptions& options, + const google_apis::FileResourceCallback& callback, + const google_apis::ProgressCallback& progress_callback) = 0; + + // Uploads a file by a single request with multipart body. It's more efficient + // for small files than using |InitiateUploadExistingFile| and |ResumeUpload|. + // |content_type| and |content_length| should be the ones of the file to be + // uploaded. |callback| must not be null. |progress_callback| may be null. + virtual google_apis::CancelCallback MultipartUploadExistingFile( + const std::string& content_type, + int64 content_length, + const std::string& resource_id, + const base::FilePath& local_file_path, + const UploadExistingFileOptions& options, + const google_apis::FileResourceCallback& callback, + const google_apis::ProgressCallback& progress_callback) = 0; +}; + +// Builder returned by DriveServiceInterface to build batch request. +class BatchRequestConfiguratorInterface + : public DriveServiceBatchOperationsInterface { + public: + ~BatchRequestConfiguratorInterface() override {} + + // Commits and sends the batch request. + virtual void Commit() = 0; +}; + // This defines an interface for sharing by DriveService and MockDriveService // so that we can do testing of clients of DriveService. // // All functions must be called on UI thread. DriveService is built on top of // URLFetcher that runs on UI thread. -class DriveServiceInterface { +class DriveServiceInterface : public DriveServiceBatchOperationsInterface { public: - virtual ~DriveServiceInterface() {} + ~DriveServiceInterface() override {} // Common service: @@ -394,33 +437,6 @@ class DriveServiceInterface { int64 content_length, const google_apis::drive::UploadRangeCallback& callback) = 0; - // Uploads a file by a single request with multipart body. It's more efficient - // for small files than using |InitiateUploadNewFile| and |ResumeUpload|. - // |content_type| and |content_length| should be the ones of the file to be - // uploaded. |callback| must not be null. |progress_callback| may be null. - virtual google_apis::CancelCallback MultipartUploadNewFile( - const std::string& content_type, - int64 content_length, - const std::string& parent_resource_id, - const std::string& title, - const base::FilePath& local_file_path, - const UploadNewFileOptions& options, - const google_apis::FileResourceCallback& callback, - const google_apis::ProgressCallback& progress_callback) = 0; - - // Uploads a file by a single request with multipart body. It's more efficient - // for small files than using |InitiateUploadExistingFile| and |ResumeUpload|. - // |content_type| and |content_length| should be the ones of the file to be - // uploaded. |callback| must not be null. |progress_callback| may be null. - virtual google_apis::CancelCallback MultipartUploadExistingFile( - const std::string& content_type, - int64 content_length, - const std::string& resource_id, - const base::FilePath& local_file_path, - const UploadExistingFileOptions& options, - const google_apis::FileResourceCallback& callback, - const google_apis::ProgressCallback& progress_callback) = 0; - // Authorizes a Drive app with the id |app_id| to open the given file. // Upon completion, invokes |callback| with the link to open the file with // the provided app. |callback| must not be null. @@ -441,6 +457,9 @@ class DriveServiceInterface { const std::string& email, google_apis::drive::PermissionRole role, const google_apis::EntryActionCallback& callback) = 0; + + // Starts batch request and returns |BatchRequestConfigurator|. + virtual scoped_ptr StartBatchRequest() = 0; }; } // namespace drive diff --git a/chrome/browser/drive/dummy_drive_service.cc b/chrome/browser/drive/dummy_drive_service.cc index 2e8fafc602cf..053cb17ff428 100644 --- a/chrome/browser/drive/dummy_drive_service.cc +++ b/chrome/browser/drive/dummy_drive_service.cc @@ -216,5 +216,9 @@ CancelCallback DummyDriveService::AddPermission( const std::string& email, google_apis::drive::PermissionRole role, const EntryActionCallback& callback) { return CancelCallback(); } +scoped_ptr +DummyDriveService::StartBatchRequest() { + return scoped_ptr(); +} } // namespace drive diff --git a/chrome/browser/drive/dummy_drive_service.h b/chrome/browser/drive/dummy_drive_service.h index 44772ee2afe0..338e44cc97ed 100644 --- a/chrome/browser/drive/dummy_drive_service.h +++ b/chrome/browser/drive/dummy_drive_service.h @@ -158,6 +158,7 @@ class DummyDriveService : public DriveServiceInterface { const std::string& email, google_apis::drive::PermissionRole role, const google_apis::EntryActionCallback& callback) override; + scoped_ptr StartBatchRequest() override; }; } // namespace drive diff --git a/chrome/browser/drive/fake_drive_service.cc b/chrome/browser/drive/fake_drive_service.cc index 7f9b585b9f30..3e4e854c812d 100644 --- a/chrome/browser/drive/fake_drive_service.cc +++ b/chrome/browser/drive/fake_drive_service.cc @@ -1772,6 +1772,14 @@ google_apis::CancelCallback FakeDriveService::AddPermission( return CancelCallback(); } +scoped_ptr +FakeDriveService::StartBatchRequest() { + DCHECK(thread_checker_.CalledOnValidThread()); + + NOTREACHED(); + return scoped_ptr(); +} + void FakeDriveService::NotifyObservers() { FOR_EACH_OBSERVER(ChangeObserver, change_observers_, OnNewChangeAvailable()); } diff --git a/chrome/browser/drive/fake_drive_service.h b/chrome/browser/drive/fake_drive_service.h index ebb1658176dc..0950963f518f 100644 --- a/chrome/browser/drive/fake_drive_service.h +++ b/chrome/browser/drive/fake_drive_service.h @@ -271,6 +271,7 @@ class FakeDriveService : public DriveServiceInterface { const std::string& email, google_apis::drive::PermissionRole role, const google_apis::EntryActionCallback& callback) override; + scoped_ptr StartBatchRequest() override; // Adds a new file with the given parameters. On success, returns // HTTP_CREATED with the parsed entry. diff --git a/chrome/browser/sync_file_system/drive_backend/drive_service_on_worker.cc b/chrome/browser/sync_file_system/drive_backend/drive_service_on_worker.cc index 1441d93a6db3..a7bf05bbeeb4 100644 --- a/chrome/browser/sync_file_system/drive_backend/drive_service_on_worker.cc +++ b/chrome/browser/sync_file_system/drive_backend/drive_service_on_worker.cc @@ -400,6 +400,12 @@ google_apis::CancelCallback DriveServiceOnWorker::MultipartUploadExistingFile( return google_apis::CancelCallback(); } +scoped_ptr +DriveServiceOnWorker::StartBatchRequest() { + NOTREACHED(); + return scoped_ptr(); +} + google_apis::CancelCallback DriveServiceOnWorker::AuthorizeApp( const std::string& resource_id, const std::string& app_id, diff --git a/chrome/browser/sync_file_system/drive_backend/drive_service_on_worker.h b/chrome/browser/sync_file_system/drive_backend/drive_service_on_worker.h index 8a55d91ad59e..ed4e72c60d2c 100644 --- a/chrome/browser/sync_file_system/drive_backend/drive_service_on_worker.h +++ b/chrome/browser/sync_file_system/drive_backend/drive_service_on_worker.h @@ -172,6 +172,8 @@ class DriveServiceOnWorker : public drive::DriveServiceInterface { const drive::UploadExistingFileOptions& options, const google_apis::FileResourceCallback& callback, const google_apis::ProgressCallback& progress_callback) override; + scoped_ptr StartBatchRequest() + override; google_apis::CancelCallback AuthorizeApp( const std::string& resource_id, const std::string& app_id, -- 2.11.4.GIT