#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 {
const char kBatchUploadRequestFormat[] = …;
const char kBatchUploadHeader[] = …;
const char kHttpContentType[] = …;
const char kHttpBr[] = …;
const char kMultipartMixedMimeTypePrefix[] = …;
void ParseFileResourceWithUploadRangeAndRun(
UploadRangeCallback callback,
const UploadRangeResponse& response,
std::unique_ptr<base::Value> value) { … }
void AttachProperties(const Properties& properties,
base::Value::Dict& request_body) { … }
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) { … }
}
MultipartHttpResponse::MultipartHttpResponse() = default;
MultipartHttpResponse::~MultipartHttpResponse() = default;
bool ParseMultipartResponse(const std::string& content_type,
const std::string& response,
std::vector<MultipartHttpResponse>* parts) { … }
Property::Property() : … { … }
Property::~Property() = default;
DriveApiPartialFieldRequest::DriveApiPartialFieldRequest(RequestSender* sender)
: … { … }
DriveApiPartialFieldRequest::~DriveApiPartialFieldRequest() = default;
GURL DriveApiPartialFieldRequest::GetURL() const { … }
FilesGetRequest::FilesGetRequest(RequestSender* sender,
const DriveApiUrlGenerator& url_generator,
FileResourceCallback callback)
: … { … }
FilesGetRequest::~FilesGetRequest() = default;
GURL FilesGetRequest::GetURLInternal() const { … }
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(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(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(
RequestSender* sender,
const DriveApiUrlGenerator& url_generator,
TeamDriveListCallback callback)
: … { … }
TeamDriveListRequest::~TeamDriveListRequest() = default;
GURL TeamDriveListRequest::GetURLInternal() const { … }
StartPageTokenRequest::StartPageTokenRequest(
RequestSender* sender,
const DriveApiUrlGenerator& url_generator,
StartPageTokenCallback callback)
: … { … }
StartPageTokenRequest::~StartPageTokenRequest() = default;
GURL StartPageTokenRequest::GetURLInternal() const { … }
FilesListRequest::FilesListRequest(RequestSender* sender,
const DriveApiUrlGenerator& url_generator,
FileListCallback callback)
: … { … }
FilesListRequest::~FilesListRequest() = default;
GURL FilesListRequest::GetURLInternal() const { … }
FilesListNextPageRequest::FilesListNextPageRequest(RequestSender* sender,
FileListCallback callback)
: … { … }
FilesListNextPageRequest::~FilesListNextPageRequest() = default;
GURL FilesListNextPageRequest::GetURLInternal() const { … }
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(RequestSender* sender,
const DriveApiUrlGenerator& url_generator,
FileResourceCallback callback)
: … { … }
FilesTrashRequest::~FilesTrashRequest() = default;
HttpRequestMethod FilesTrashRequest::GetRequestType() const { … }
GURL FilesTrashRequest::GetURLInternal() const { … }
AboutGetRequest::AboutGetRequest(RequestSender* sender,
const DriveApiUrlGenerator& url_generator,
AboutResourceCallback callback)
: … { … }
AboutGetRequest::~AboutGetRequest() = default;
GURL AboutGetRequest::GetURLInternal() const { … }
ChangesListRequest::ChangesListRequest(
RequestSender* sender,
const DriveApiUrlGenerator& url_generator,
ChangeListCallback callback)
: … { … }
ChangesListRequest::~ChangesListRequest() = default;
GURL ChangesListRequest::GetURLInternal() const { … }
ChangesListNextPageRequest::ChangesListNextPageRequest(
RequestSender* sender,
ChangeListCallback callback)
: … { … }
ChangesListNextPageRequest::~ChangesListNextPageRequest() = default;
GURL ChangesListNextPageRequest::GetURLInternal() const { … }
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(
RequestSender* sender,
const DriveApiUrlGenerator& url_generator,
EntryActionCallback callback)
: … { … }
ChildrenDeleteRequest::~ChildrenDeleteRequest() = default;
HttpRequestMethod ChildrenDeleteRequest::GetRequestType() const { … }
GURL ChildrenDeleteRequest::GetURL() const { … }
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(
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(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(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(
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(
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(
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(
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(
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) { … }
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() { … }
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) { … }
}