chromium/google_apis/drive/drive_api_requests.cc

// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "google_apis/drive/drive_api_requests.h"

#include <stddef.h>

#include <string_view>
#include <utility>

#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/functional/callback_helpers.h"
#include "base/json/json_writer.h"
#include "base/location.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/not_fatal_until.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/task/sequenced_task_runner.h"
#include "base/values.h"
#include "google_apis/common/base_requests.h"
#include "google_apis/common/request_sender.h"
#include "google_apis/common/time_util.h"
#include "google_apis/drive/request_util.h"
#include "net/base/url_util.h"
#include "net/http/http_response_headers.h"
#include "services/network/public/mojom/url_response_head.mojom.h"

namespace google_apis::drive {
namespace {

// Format of one request in batch uploading request.
const char kBatchUploadRequestFormat[] =;

// Request header for specifying batch upload.
const char kBatchUploadHeader[] =;

// Content type of HTTP request.
const char kHttpContentType[] =;

// Break line in HTTP message.
const char kHttpBr[] =;

// Mime type of multipart mixed.
const char kMultipartMixedMimeTypePrefix[] =;

// Parses the JSON value to FileResource instance and runs |callback| on the
// UI thread once parsing is done.
// This is customized version of ParseJsonAndRun defined above to adapt the
// remaining response type.
void ParseFileResourceWithUploadRangeAndRun(
    UploadRangeCallback callback,
    const UploadRangeResponse& response,
    std::unique_ptr<base::Value> value) {}

// Attaches |properties| to the |request_body| if |properties| is not empty.
void AttachProperties(const Properties& properties,
                      base::Value::Dict& request_body) {}

// Creates metadata JSON string for multipart uploading.
// All the values are optional. If the value is empty or null, the value does
// not appear in the metadata.
std::string CreateMultipartUploadMetadataJson(
    const std::string& title,
    const std::string& parent_resource_id,
    const base::Time& modified_date,
    const base::Time& last_viewed_by_me_date,
    const Properties& properties) {}

}  // namespace

MultipartHttpResponse::MultipartHttpResponse() = default;

MultipartHttpResponse::~MultipartHttpResponse() = default;

// The |response| must be multipart/mixed format that contains child HTTP
// response of drive batch request.
// https://www.ietf.org/rfc/rfc2046.txt
//
// It looks like:
// --Boundary
// Content-type: application/http
//
// HTTP/1.1 200 OK
// Header of child response
//
// Body of child response
// --Boundary
// Content-type: application/http
//
// HTTP/1.1 404 Not Found
// Header of child response
//
// Body of child response
// --Boundary--
bool ParseMultipartResponse(const std::string& content_type,
                            const std::string& response,
                            std::vector<MultipartHttpResponse>* parts) {}

Property::Property() :{}

Property::~Property() = default;

//============================ DriveApiPartialFieldRequest ====================

DriveApiPartialFieldRequest::DriveApiPartialFieldRequest(RequestSender* sender)
    :{}

DriveApiPartialFieldRequest::~DriveApiPartialFieldRequest() = default;

GURL DriveApiPartialFieldRequest::GetURL() const {}

//=============================== FilesGetRequest =============================

FilesGetRequest::FilesGetRequest(RequestSender* sender,
                                 const DriveApiUrlGenerator& url_generator,
                                 FileResourceCallback callback)
    :{}

FilesGetRequest::~FilesGetRequest() = default;

GURL FilesGetRequest::GetURLInternal() const {}

//============================ FilesInsertRequest ============================

FilesInsertRequest::FilesInsertRequest(
    RequestSender* sender,
    const DriveApiUrlGenerator& url_generator,
    FileResourceCallback callback)
    :{}

FilesInsertRequest::~FilesInsertRequest() = default;

HttpRequestMethod FilesInsertRequest::GetRequestType() const {}

bool FilesInsertRequest::GetContentData(std::string* upload_content_type,
                                        std::string* upload_content) {}

GURL FilesInsertRequest::GetURLInternal() const {}

//============================== FilesPatchRequest ============================

FilesPatchRequest::FilesPatchRequest(RequestSender* sender,
                                     const DriveApiUrlGenerator& url_generator,
                                     FileResourceCallback callback)
    :{}

FilesPatchRequest::~FilesPatchRequest() = default;

HttpRequestMethod FilesPatchRequest::GetRequestType() const {}

std::vector<std::string> FilesPatchRequest::GetExtraRequestHeaders() const {}

GURL FilesPatchRequest::GetURLInternal() const {}

bool FilesPatchRequest::GetContentData(std::string* upload_content_type,
                                       std::string* upload_content) {}

//============================= FilesCopyRequest ==============================

FilesCopyRequest::FilesCopyRequest(RequestSender* sender,
                                   const DriveApiUrlGenerator& url_generator,
                                   FileResourceCallback callback)
    :{}

FilesCopyRequest::~FilesCopyRequest() = default;

HttpRequestMethod FilesCopyRequest::GetRequestType() const {}

GURL FilesCopyRequest::GetURLInternal() const {}

bool FilesCopyRequest::GetContentData(std::string* upload_content_type,
                                      std::string* upload_content) {}

//========================= TeamDriveListRequest =============================

TeamDriveListRequest::TeamDriveListRequest(
    RequestSender* sender,
    const DriveApiUrlGenerator& url_generator,
    TeamDriveListCallback callback)
    :{}

TeamDriveListRequest::~TeamDriveListRequest() = default;

GURL TeamDriveListRequest::GetURLInternal() const {}

//========================= StartPageTokenRequest =============================

StartPageTokenRequest::StartPageTokenRequest(
    RequestSender* sender,
    const DriveApiUrlGenerator& url_generator,
    StartPageTokenCallback callback)
    :{}

StartPageTokenRequest::~StartPageTokenRequest() = default;

GURL StartPageTokenRequest::GetURLInternal() const {}

//============================= FilesListRequest =============================

FilesListRequest::FilesListRequest(RequestSender* sender,
                                   const DriveApiUrlGenerator& url_generator,
                                   FileListCallback callback)
    :{}

FilesListRequest::~FilesListRequest() = default;

GURL FilesListRequest::GetURLInternal() const {}

//======================== FilesListNextPageRequest =========================

FilesListNextPageRequest::FilesListNextPageRequest(RequestSender* sender,
                                                   FileListCallback callback)
    :{}

FilesListNextPageRequest::~FilesListNextPageRequest() = default;

GURL FilesListNextPageRequest::GetURLInternal() const {}

//============================ FilesDeleteRequest =============================

FilesDeleteRequest::FilesDeleteRequest(
    RequestSender* sender,
    const DriveApiUrlGenerator& url_generator,
    EntryActionCallback callback)
    :{}

FilesDeleteRequest::~FilesDeleteRequest() = default;

HttpRequestMethod FilesDeleteRequest::GetRequestType() const {}

GURL FilesDeleteRequest::GetURL() const {}

std::vector<std::string> FilesDeleteRequest::GetExtraRequestHeaders() const {}

//============================ FilesTrashRequest =============================

FilesTrashRequest::FilesTrashRequest(RequestSender* sender,
                                     const DriveApiUrlGenerator& url_generator,
                                     FileResourceCallback callback)
    :{}

FilesTrashRequest::~FilesTrashRequest() = default;

HttpRequestMethod FilesTrashRequest::GetRequestType() const {}

GURL FilesTrashRequest::GetURLInternal() const {}

//============================== AboutGetRequest =============================

AboutGetRequest::AboutGetRequest(RequestSender* sender,
                                 const DriveApiUrlGenerator& url_generator,
                                 AboutResourceCallback callback)
    :{}

AboutGetRequest::~AboutGetRequest() = default;

GURL AboutGetRequest::GetURLInternal() const {}

//============================ ChangesListRequest ===========================

ChangesListRequest::ChangesListRequest(
    RequestSender* sender,
    const DriveApiUrlGenerator& url_generator,
    ChangeListCallback callback)
    :{}

ChangesListRequest::~ChangesListRequest() = default;

GURL ChangesListRequest::GetURLInternal() const {}

//======================== ChangesListNextPageRequest =========================

ChangesListNextPageRequest::ChangesListNextPageRequest(
    RequestSender* sender,
    ChangeListCallback callback)
    :{}

ChangesListNextPageRequest::~ChangesListNextPageRequest() = default;

GURL ChangesListNextPageRequest::GetURLInternal() const {}

//========================== ChildrenInsertRequest ============================

ChildrenInsertRequest::ChildrenInsertRequest(
    RequestSender* sender,
    const DriveApiUrlGenerator& url_generator,
    EntryActionCallback callback)
    :{}

ChildrenInsertRequest::~ChildrenInsertRequest() = default;

HttpRequestMethod ChildrenInsertRequest::GetRequestType() const {}

GURL ChildrenInsertRequest::GetURL() const {}

bool ChildrenInsertRequest::GetContentData(std::string* upload_content_type,
                                           std::string* upload_content) {}

//========================== ChildrenDeleteRequest ============================

ChildrenDeleteRequest::ChildrenDeleteRequest(
    RequestSender* sender,
    const DriveApiUrlGenerator& url_generator,
    EntryActionCallback callback)
    :{}

ChildrenDeleteRequest::~ChildrenDeleteRequest() = default;

HttpRequestMethod ChildrenDeleteRequest::GetRequestType() const {}

GURL ChildrenDeleteRequest::GetURL() const {}

//======================= InitiateUploadNewFileRequest =======================

InitiateUploadNewFileRequest::InitiateUploadNewFileRequest(
    RequestSender* sender,
    const DriveApiUrlGenerator& url_generator,
    const std::string& content_type,
    int64_t content_length,
    const std::string& parent_resource_id,
    const std::string& title,
    InitiateUploadCallback callback)
    :{}

InitiateUploadNewFileRequest::~InitiateUploadNewFileRequest() = default;

GURL InitiateUploadNewFileRequest::GetURL() const {}

HttpRequestMethod InitiateUploadNewFileRequest::GetRequestType() const {}

bool InitiateUploadNewFileRequest::GetContentData(
    std::string* upload_content_type,
    std::string* upload_content) {}

//===================== InitiateUploadExistingFileRequest ====================

InitiateUploadExistingFileRequest::InitiateUploadExistingFileRequest(
    RequestSender* sender,
    const DriveApiUrlGenerator& url_generator,
    const std::string& content_type,
    int64_t content_length,
    const std::string& resource_id,
    const std::string& etag,
    InitiateUploadCallback callback)
    :{}

InitiateUploadExistingFileRequest::~InitiateUploadExistingFileRequest() =
    default;

GURL InitiateUploadExistingFileRequest::GetURL() const {}

HttpRequestMethod InitiateUploadExistingFileRequest::GetRequestType() const {}

std::vector<std::string>
InitiateUploadExistingFileRequest::GetExtraRequestHeaders() const {}

bool InitiateUploadExistingFileRequest::GetContentData(
    std::string* upload_content_type,
    std::string* upload_content) {}

//============================ ResumeUploadRequest ===========================

ResumeUploadRequest::ResumeUploadRequest(RequestSender* sender,
                                         const GURL& upload_location,
                                         int64_t start_position,
                                         int64_t end_position,
                                         int64_t content_length,
                                         const std::string& content_type,
                                         const base::FilePath& local_file_path,
                                         UploadRangeCallback callback,
                                         ProgressCallback progress_callback)
    :{}

ResumeUploadRequest::~ResumeUploadRequest() = default;

void ResumeUploadRequest::OnRangeRequestComplete(
    const UploadRangeResponse& response,
    std::unique_ptr<base::Value> value) {}

//========================== GetUploadStatusRequest ==========================

GetUploadStatusRequest::GetUploadStatusRequest(RequestSender* sender,
                                               const GURL& upload_url,
                                               int64_t content_length,
                                               UploadRangeCallback callback)
    :{}

GetUploadStatusRequest::~GetUploadStatusRequest() = default;

void GetUploadStatusRequest::OnRangeRequestComplete(
    const UploadRangeResponse& response,
    std::unique_ptr<base::Value> value) {}

//======================= MultipartUploadNewFileDelegate =======================

MultipartUploadNewFileDelegate::MultipartUploadNewFileDelegate(
    base::SequencedTaskRunner* task_runner,
    const std::string& title,
    const std::string& parent_resource_id,
    const std::string& content_type,
    int64_t content_length,
    const base::Time& modified_date,
    const base::Time& last_viewed_by_me_date,
    const base::FilePath& local_file_path,
    const Properties& properties,
    const DriveApiUrlGenerator& url_generator,
    FileResourceCallback callback,
    ProgressCallback progress_callback)
    :{}

MultipartUploadNewFileDelegate::~MultipartUploadNewFileDelegate() = default;

GURL MultipartUploadNewFileDelegate::GetURL() const {}

HttpRequestMethod MultipartUploadNewFileDelegate::GetRequestType() const {}

//====================== MultipartUploadExistingFileDelegate ===================

MultipartUploadExistingFileDelegate::MultipartUploadExistingFileDelegate(
    base::SequencedTaskRunner* task_runner,
    const std::string& title,
    const std::string& resource_id,
    const std::string& parent_resource_id,
    const std::string& content_type,
    int64_t content_length,
    const base::Time& modified_date,
    const base::Time& last_viewed_by_me_date,
    const base::FilePath& local_file_path,
    const std::string& etag,
    const Properties& properties,
    const DriveApiUrlGenerator& url_generator,
    FileResourceCallback callback,
    ProgressCallback progress_callback)
    :{}

MultipartUploadExistingFileDelegate::~MultipartUploadExistingFileDelegate() =
    default;

std::vector<std::string>
MultipartUploadExistingFileDelegate::GetExtraRequestHeaders() const {}

GURL MultipartUploadExistingFileDelegate::GetURL() const {}

HttpRequestMethod MultipartUploadExistingFileDelegate::GetRequestType() const {}

//========================== DownloadFileRequest ==========================

DownloadFileRequest::DownloadFileRequest(
    RequestSender* sender,
    const DriveApiUrlGenerator& url_generator,
    const std::string& resource_id,
    const base::FilePath& output_file_path,
    DownloadActionCallback download_action_callback,
    const GetContentCallback& get_content_callback,
    ProgressCallback progress_callback)
    :{}

DownloadFileRequest::~DownloadFileRequest() = default;

//========================== PermissionsInsertRequest ==========================

PermissionsInsertRequest::PermissionsInsertRequest(
    RequestSender* sender,
    const DriveApiUrlGenerator& url_generator,
    EntryActionCallback callback)
    :{}

PermissionsInsertRequest::~PermissionsInsertRequest() = default;

GURL PermissionsInsertRequest::GetURL() const {}

HttpRequestMethod PermissionsInsertRequest::GetRequestType() const {}

bool PermissionsInsertRequest::GetContentData(std::string* upload_content_type,
                                              std::string* upload_content) {}

//======================= SingleBatchableDelegateRequest =======================

SingleBatchableDelegateRequest::SingleBatchableDelegateRequest(
    RequestSender* sender,
    std::unique_ptr<BatchableDelegate> delegate)
    :{}

SingleBatchableDelegateRequest::~SingleBatchableDelegateRequest() = default;

GURL SingleBatchableDelegateRequest::GetURL() const {}

HttpRequestMethod SingleBatchableDelegateRequest::GetRequestType() const {}

std::vector<std::string>
SingleBatchableDelegateRequest::GetExtraRequestHeaders() const {}

void SingleBatchableDelegateRequest::Prepare(PrepareCallback callback) {}

bool SingleBatchableDelegateRequest::GetContentData(
    std::string* upload_content_type,
    std::string* upload_content) {}

void SingleBatchableDelegateRequest::ProcessURLFetchResults(
    const network::mojom::URLResponseHead* response_head,
    base::FilePath response_file,
    std::string response_body) {}

void SingleBatchableDelegateRequest::RunCallbackOnPrematureFailure(
    ApiErrorCode code) {}

void SingleBatchableDelegateRequest::OnUploadProgress(int64_t current,
                                                      int64_t total) {}

//========================== BatchUploadRequest ==========================

BatchUploadChildEntry::BatchUploadChildEntry(BatchableDelegate* request)
    :{}

BatchUploadChildEntry::~BatchUploadChildEntry() = default;

BatchUploadRequest::BatchUploadRequest(
    RequestSender* sender,
    const DriveApiUrlGenerator& url_generator)
    :{}

BatchUploadRequest::~BatchUploadRequest() = default;

void BatchUploadRequest::SetBoundaryForTesting(const std::string& boundary) {}

void BatchUploadRequest::AddRequest(BatchableDelegate* request) {}

void BatchUploadRequest::OnChildRequestPrepared(RequestID request_id,
                                                ApiErrorCode result) {}

void BatchUploadRequest::Commit() {}

void BatchUploadRequest::Prepare(PrepareCallback callback) {}

void BatchUploadRequest::Cancel() {}

// Obtains corresponding child entry of |request_id|. Returns NULL if the
// entry is not found.
std::vector<std::unique_ptr<BatchUploadChildEntry>>::iterator
BatchUploadRequest::GetChildEntry(RequestID request_id) {}

void BatchUploadRequest::MayCompletePrepare() {}

bool BatchUploadRequest::GetContentData(std::string* upload_content_type,
                                        std::string* upload_content_data) {}

base::WeakPtr<BatchUploadRequest>
BatchUploadRequest::GetWeakPtrAsBatchUploadRequest() {}

GURL BatchUploadRequest::GetURL() const {}

HttpRequestMethod BatchUploadRequest::GetRequestType() const {}

std::vector<std::string> BatchUploadRequest::GetExtraRequestHeaders() const {}

void BatchUploadRequest::ProcessURLFetchResults(
    const network::mojom::URLResponseHead* response_head,
    base::FilePath response_file,
    std::string response_body) {}

void BatchUploadRequest::RunCallbackOnPrematureFailure(ApiErrorCode code) {}

void BatchUploadRequest::OnUploadProgress(int64_t current, int64_t total) {}
}  // namespace google_apis::drive