// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // // This file provides base classes used to issue HTTP requests for Google // APIs. #ifndef GOOGLE_APIS_DRIVE_DRIVE_BASE_REQUESTS_H_ #define GOOGLE_APIS_DRIVE_DRIVE_BASE_REQUESTS_H_ #include <stdint.h> #include <memory> #include <string> #include <utility> #include <vector> #include "base/files/file_path.h" #include "base/functional/callback.h" #include "base/memory/weak_ptr.h" #include "base/task/sequenced_task_runner.h" #include "base/threading/thread_checker.h" #include "google_apis/common/api_error_codes.h" #include "google_apis/common/base_requests.h" #include "services/network/public/cpp/simple_url_loader.h" #include "services/network/public/cpp/simple_url_loader_stream_consumer.h" #include "services/network/public/mojom/url_response_head.mojom-forward.h" #include "url/gurl.h" namespace base { class Value; } // namespace base namespace google_apis { class FileResource; class RequestSender; // Content type for multipart body. enum class MultipartType { … }; // Pair of content type and data. struct ContentTypeAndData { … }; // Callback used for requests that the server returns FileResource data // formatted into JSON value. FileResourceCallback; // Generate multipart body. If |predetermined_boundary| is not empty, it uses // the string as boundary. Otherwise it generates random boundary that does not // conflict with |parts|. If |data_offset| is not nullptr, it stores the // index of first byte of each part in multipart body. void GenerateMultipartBody(MultipartType multipart_type, const std::string& predetermined_boundary, const std::vector<ContentTypeAndData>& parts, ContentTypeAndData* output, std::vector<uint64_t>* data_offset); //============================ DriveUrlFetchRequestBase ======================= // Base class for Drive requests that are fetching URLs. class DriveUrlFetchRequestBase : public UrlFetchRequestBase { … }; //============================ BatchableDelegate ============================ // Delegate to be used by |SingleBatchableDelegateRequest| and // |BatchUploadRequest|. class BatchableDelegate { … }; //============================ EntryActionRequest ============================ // Callback type for requests that return only error status, like: Delete/Move. EntryActionCallback; // This class performs a simple action over a given entry (document/file). // It is meant to be used for requests that return no JSON blobs. class EntryActionRequest : public DriveUrlFetchRequestBase { … }; //=========================== InitiateUploadRequestBase======================= // Callback type for DriveServiceInterface::InitiateUpload. InitiateUploadCallback; // This class provides base implementation for performing the request for // initiating the upload of a file. // |callback| will be called with the obtained upload URL. The URL will be // used with requests for resuming the file uploading. // // Here's the flow of uploading: // 1) Get the upload URL with a class inheriting InitiateUploadRequestBase. // 2) Upload the first 1GB (see kUploadChunkSize in drive_uploader.cc) // of the target file to the upload URL // 3) If there is more data to upload, go to 2). // class InitiateUploadRequestBase : public DriveUrlFetchRequestBase { … }; //========================== UploadRangeRequestBase ========================== // Struct for response to ResumeUpload and GetUploadStatus. struct UploadRangeResponse { … }; // Base class for a URL fetch request expecting the response containing the // current uploading range. This class processes the response containing // "Range" header and invoke OnRangeRequestComplete. class UploadRangeRequestBase : public DriveUrlFetchRequestBase { … }; //========================== ResumeUploadRequestBase ========================= // This class performs the request for resuming the upload of a file. // More specifically, this request uploads a chunk of data carried in |buf| // of ResumeUploadResponseBase. This class is designed to share the // implementation of upload resuming between GData WAPI and Drive API v2. // The subclasses should implement OnRangeRequestComplete inherited by // UploadRangeRequestBase, because the type of the response should be // different (although the format in the server response is JSON). class ResumeUploadRequestBase : public UploadRangeRequestBase { … }; //======================== GetUploadStatusRequestBase ======================== // This class performs the request for getting the current upload status // of a file. // This request calls OnRangeRequestComplete() with: // - HTTP_RESUME_INCOMPLETE and the range of previously uploaded data, // if a file has been partially uploaded. |value| is not used. // - HTTP_SUCCESS or HTTP_CREATED (up to the upload mode) and |value| // for the uploaded data, if a file has been completely uploaded. // See also UploadRangeRequestBase. class GetUploadStatusRequestBase : public UploadRangeRequestBase { … }; //=========================== MultipartUploadRequestBase======================= // This class provides base implementation for performing the request for // uploading a file by multipart body. class MultipartUploadRequestBase : public BatchableDelegate { … }; //============================ DownloadFileRequest =========================== // Callback type for receiving the completion of DownloadFileRequest. DownloadActionCallback; // This is a base class for performing the request for downloading a file. class DownloadFileRequestBase : public DriveUrlFetchRequestBase { … }; } // namespace google_apis #endif // GOOGLE_APIS_DRIVE_DRIVE_BASE_REQUESTS_H_