#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "google_apis/common/base_requests.h"
#include <stddef.h>
#include <algorithm>
#include <memory>
#include <string>
#include <string_view>
#include <utility>
#include "base/containers/span.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/json/json_reader.h"
#include "base/strings/stringprintf.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/values.h"
#include "google_apis/common/request_sender.h"
#include "google_apis/common/task_util.h"
#include "google_apis/credentials_mode.h"
#include "net/base/load_flags.h"
#include "net/http/http_request_headers.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 kAuthorizationHeaderFormat[] = …;
const char kGDataVersionHeader[] = …;
const int kMaxReAuthenticateAttemptsPerRequest = …;
std::string GetResponseHeadersAsString(
const network::mojom::URLResponseHead& response_head) { … }
}
namespace google_apis {
std::optional<std::string> MapJsonErrorToReason(const std::string& error_body) { … }
std::unique_ptr<base::Value> ParseJson(const std::string& json) { … }
std::string HttpRequestMethodToString(HttpRequestMethod method) { … }
UrlFetchRequestBase::UrlFetchRequestBase(
RequestSender* sender,
ProgressCallback upload_progress_callback,
ProgressCallback download_progress_callback)
: … { … }
UrlFetchRequestBase::~UrlFetchRequestBase() = default;
void UrlFetchRequestBase::Start(const std::string& access_token,
const std::string& custom_user_agent,
ReAuthenticateCallback callback) { … }
void UrlFetchRequestBase::Prepare(PrepareCallback callback) { … }
void UrlFetchRequestBase::StartAfterPrepare(
const std::string& access_token,
const std::string& custom_user_agent,
ReAuthenticateCallback callback,
ApiErrorCode code) { … }
void UrlFetchRequestBase::OnDownloadProgress(ProgressCallback progress_callback,
uint64_t current) { … }
void UrlFetchRequestBase::OnUploadProgress(ProgressCallback progress_callback,
uint64_t position,
uint64_t total) { … }
void UrlFetchRequestBase::OnResponseStarted(
const GURL& final_url,
const network::mojom::URLResponseHead& response_head) { … }
UrlFetchRequestBase::DownloadData::DownloadData(
scoped_refptr<base::SequencedTaskRunner> blocking_task_runner)
: … { … }
UrlFetchRequestBase::DownloadData::~DownloadData() { … }
bool UrlFetchRequestBase::WriteFileData(std::string file_data,
DownloadData* download_data) { … }
void UrlFetchRequestBase::OnWriteComplete(
std::unique_ptr<DownloadData> download_data,
base::OnceClosure resume,
bool write_success) { … }
void UrlFetchRequestBase::OnDataReceived(std::string_view string_piece,
base::OnceClosure resume) { … }
void UrlFetchRequestBase::OnComplete(bool success) { … }
void UrlFetchRequestBase::OnOutputFileClosed(bool success) { … }
void UrlFetchRequestBase::OnRetry(base::OnceClosure start_retry) { … }
HttpRequestMethod UrlFetchRequestBase::GetRequestType() const { … }
std::vector<std::string> UrlFetchRequestBase::GetExtraRequestHeaders() const { … }
bool UrlFetchRequestBase::GetContentData(std::string* upload_content_type,
std::string* upload_content) { … }
bool UrlFetchRequestBase::GetContentFile(base::FilePath* local_file_path,
int64_t* range_offset,
int64_t* range_length,
std::string* upload_content_type) { … }
void UrlFetchRequestBase::GetOutputFilePath(
base::FilePath* local_file_path,
GetContentCallback* get_content_callback) { … }
void UrlFetchRequestBase::Cancel() { … }
ApiErrorCode UrlFetchRequestBase::GetErrorCode() const { … }
int UrlFetchRequestBase::NetError() const { … }
bool UrlFetchRequestBase::CalledOnValidThread() { … }
base::SequencedTaskRunner* UrlFetchRequestBase::blocking_task_runner() const { … }
void UrlFetchRequestBase::OnProcessURLFetchResultsComplete() { … }
void UrlFetchRequestBase::CompleteRequestWithError(ApiErrorCode code) { … }
void UrlFetchRequestBase::OnAuthFailed(ApiErrorCode code) { … }
base::WeakPtr<AuthenticatedRequestInterface> UrlFetchRequestBase::GetWeakPtr() { … }
}