chromium/google_apis/drive/drive_base_requests.cc

// 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.

#include "google_apis/drive/drive_base_requests.h"

#include <stddef.h>

#include <algorithm>
#include <memory>
#include <utility>

#include "base/containers/contains.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/location.h"
#include "base/strings/string_number_conversions.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/task_util.h"
#include "google_apis/common/time_util.h"
#include "google_apis/drive/drive_api_parser.h"
#include "google_apis/drive/request_util.h"
#include "net/base/load_flags.h"
#include "net/base/mime_util.h"
#include "net/http/http_util.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/mojom/url_response_head.mojom.h"

namespace {

// Template for initiate upload of both GData WAPI and Drive API v2.
const char kUploadContentType[] =;
const char kUploadContentLength[] =;
const char kUploadResponseLocation[] =;

// Template for upload data range of both GData WAPI and Drive API v2.
const char kUploadContentRange[] =;
const char kUploadResponseRange[] =;

// Mime type of JSON.
const char kJsonMimeType[] =;

// Mime type of multipart related.
const char kMultipartRelatedMimeTypePrefix[] =;

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

// Header for each item in a multipart message.
const char kMultipartItemHeaderFormat[] =;

// Footer for whole multipart message.
const char kMultipartFooterFormat[] =;

// Parses JSON passed in |json| on |blocking_task_runner|. Runs |callback| on
// the calling thread when finished with either success or failure.
// The callback must not be null.
void ParseJsonOnBlockingPool(
    base::TaskRunner* blocking_task_runner,
    std::string json,
    base::OnceCallback<void(std::unique_ptr<base::Value> value)> callback) {}

// Obtains the multipart body for the metadata string and file contents. If
// predetermined_boundary is empty, the function generates the boundary string.
bool GetMultipartContent(const std::string& predetermined_boundary,
                         const std::string& metadata_json,
                         const std::string& content_type,
                         const base::FilePath& path,
                         std::string* upload_content_type,
                         std::string* upload_content_data) {}

// See https://developers.google.com/drive/handle-errors
google_apis::ApiErrorCode MapDriveReasonToError(google_apis::ApiErrorCode code,
                                                const std::string& reason) {}

}  // namespace

namespace google_apis {

void GenerateMultipartBody(MultipartType multipart_type,
                           const std::string& predetermined_boundary,
                           const std::vector<ContentTypeAndData>& parts,
                           ContentTypeAndData* output,
                           std::vector<uint64_t>* data_offset) {}

//========================== DriveUrlFetchRequestBase ======================
DriveUrlFetchRequestBase::DriveUrlFetchRequestBase(
    RequestSender* sender,
    ProgressCallback upload_progress_callback,
    ProgressCallback download_progress_callback)
    :{}

DriveUrlFetchRequestBase::~DriveUrlFetchRequestBase() = default;

ApiErrorCode DriveUrlFetchRequestBase::MapReasonToError(
    ApiErrorCode code,
    const std::string& reason) {}

bool DriveUrlFetchRequestBase::IsSuccessfulErrorCode(ApiErrorCode error) {}

//============================ EntryActionRequest ============================

EntryActionRequest::EntryActionRequest(RequestSender* sender,
                                       EntryActionCallback callback)
    :{}

EntryActionRequest::~EntryActionRequest() = default;

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

void EntryActionRequest::RunCallbackOnPrematureFailure(ApiErrorCode code) {}

//========================= InitiateUploadRequestBase ========================

InitiateUploadRequestBase::InitiateUploadRequestBase(
    RequestSender* sender,
    InitiateUploadCallback callback,
    const std::string& content_type,
    int64_t content_length)
    :{}

InitiateUploadRequestBase::~InitiateUploadRequestBase() = default;

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

void InitiateUploadRequestBase::RunCallbackOnPrematureFailure(
    ApiErrorCode code) {}

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

//============================ UploadRangeResponse =============================

UploadRangeResponse::UploadRangeResponse() = default;

UploadRangeResponse::UploadRangeResponse(ApiErrorCode code,
                                         int64_t start_position_received,
                                         int64_t end_position_received)
    :{}

UploadRangeResponse::~UploadRangeResponse() = default;

//========================== UploadRangeRequestBase ==========================

UploadRangeRequestBase::UploadRangeRequestBase(
    RequestSender* sender,
    const GURL& upload_url,
    ProgressCallback progress_callback)
    :{}

UploadRangeRequestBase::~UploadRangeRequestBase() = default;

GURL UploadRangeRequestBase::GetURL() const {}

HttpRequestMethod UploadRangeRequestBase::GetRequestType() const {}

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

void UploadRangeRequestBase::OnDataParsed(ApiErrorCode code,
                                          std::unique_ptr<base::Value> value) {}

void UploadRangeRequestBase::RunCallbackOnPrematureFailure(ApiErrorCode code) {}

//========================== ResumeUploadRequestBase =========================

ResumeUploadRequestBase::ResumeUploadRequestBase(
    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,
    ProgressCallback progress_callback)
    :{}

ResumeUploadRequestBase::~ResumeUploadRequestBase() = default;

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

bool ResumeUploadRequestBase::GetContentFile(base::FilePath* local_file_path,
                                             int64_t* range_offset,
                                             int64_t* range_length,
                                             std::string* upload_content_type) {}

//======================== GetUploadStatusRequestBase ========================

GetUploadStatusRequestBase::GetUploadStatusRequestBase(RequestSender* sender,
                                                       const GURL& upload_url,
                                                       int64_t content_length)
    :{}

GetUploadStatusRequestBase::~GetUploadStatusRequestBase() = default;

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

//========================= MultipartUploadRequestBase ========================

MultipartUploadRequestBase::MultipartUploadRequestBase(
    base::SequencedTaskRunner* blocking_task_runner,
    const std::string& metadata_json,
    const std::string& content_type,
    int64_t content_length,
    const base::FilePath& local_file_path,
    FileResourceCallback callback,
    ProgressCallback progress_callback)
    :{}

MultipartUploadRequestBase::~MultipartUploadRequestBase() = default;

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

void MultipartUploadRequestBase::Prepare(PrepareCallback callback) {}

void MultipartUploadRequestBase::OnPrepareUploadContent(
    PrepareCallback callback,
    std::string* upload_content_type,
    std::string* upload_content_data,
    bool result) {}

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

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

void MultipartUploadRequestBase::NotifyResult(
    ApiErrorCode code,
    const std::string& body,
    base::OnceClosure notify_complete_callback) {}

void MultipartUploadRequestBase::NotifyError(ApiErrorCode code) {}

void MultipartUploadRequestBase::NotifyUploadProgress(int64_t current,
                                                      int64_t total) {}

void MultipartUploadRequestBase::OnDataParsed(
    ApiErrorCode code,
    base::OnceClosure notify_complete_callback,
    std::unique_ptr<base::Value> value) {}

//============================ DownloadFileRequestBase =========================

DownloadFileRequestBase::DownloadFileRequestBase(
    RequestSender* sender,
    DownloadActionCallback download_action_callback,
    const GetContentCallback& get_content_callback,
    ProgressCallback progress_callback,
    const GURL& download_url,
    const base::FilePath& output_file_path)
    :{}

DownloadFileRequestBase::~DownloadFileRequestBase() = default;

// Overridden from UrlFetchRequestBase.
GURL DownloadFileRequestBase::GetURL() const {}

void DownloadFileRequestBase::GetOutputFilePath(
    base::FilePath* local_file_path,
    GetContentCallback* get_content_callback) {}

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

void DownloadFileRequestBase::RunCallbackOnPrematureFailure(ApiErrorCode code) {}

}  // namespace google_apis