#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 {
const char kUploadContentType[] = …;
const char kUploadContentLength[] = …;
const char kUploadResponseLocation[] = …;
const char kUploadContentRange[] = …;
const char kUploadResponseRange[] = …;
const char kJsonMimeType[] = …;
const char kMultipartRelatedMimeTypePrefix[] = …;
const char kMultipartMixedMimeTypePrefix[] = …;
const char kMultipartItemHeaderFormat[] = …;
const char kMultipartFooterFormat[] = …;
void ParseJsonOnBlockingPool(
base::TaskRunner* blocking_task_runner,
std::string json,
base::OnceCallback<void(std::unique_ptr<base::Value> value)> callback) { … }
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) { … }
google_apis::ApiErrorCode MapDriveReasonToError(google_apis::ApiErrorCode code,
const std::string& reason) { … }
}
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(
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(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(
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() = default;
UploadRangeResponse::UploadRangeResponse(ApiErrorCode code,
int64_t start_position_received,
int64_t end_position_received)
: … { … }
UploadRangeResponse::~UploadRangeResponse() = default;
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(
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(RequestSender* sender,
const GURL& upload_url,
int64_t content_length)
: … { … }
GetUploadStatusRequestBase::~GetUploadStatusRequestBase() = default;
std::vector<std::string> GetUploadStatusRequestBase::GetExtraRequestHeaders()
const { … }
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(
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;
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) { … }
}