#include "components/plus_addresses/plus_address_http_client_impl.h"
#include <concepts>
#include <memory>
#include <optional>
#include <string>
#include <type_traits>
#include <utility>
#include "base/check_deref.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/json/json_writer.h"
#include "base/sequence_checker.h"
#include "base/strings/strcat.h"
#include "base/task/sequenced_task_runner.h"
#include "base/types/expected.h"
#include "components/plus_addresses/features.h"
#include "components/plus_addresses/metrics/plus_address_metrics.h"
#include "components/plus_addresses/plus_address_parsing_utils.h"
#include "components/plus_addresses/plus_address_types.h"
#include "components/signin/public/base/consent_level.h"
#include "components/signin/public/identity_manager/access_token_info.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "components/signin/public/identity_manager/primary_account_access_token_fetcher.h"
#include "components/signin/public/identity_manager/scope_set.h"
#include "google_apis/gaia/google_service_auth_error.h"
#include "net/http/http_request_headers.h"
#include "net/http/http_status_code.h"
#include "services/data_decoder/public/cpp/data_decoder.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "url/gurl.h"
#include "url/origin.h"
namespace plus_addresses {
namespace {
constexpr base::TimeDelta kRequestTimeout = …;
constexpr auto kSignoutError = …;
constexpr net::NetworkTrafficAnnotationTag kReservePlusAddressAnnotation = …;
constexpr net::NetworkTrafficAnnotationTag kConfirmPlusAddressAnnotation = …;
constexpr net::NetworkTrafficAnnotationTag kPreallocatePlusAddressesAnnotation = …;
std::optional<GURL> ValidateAndGetUrl() { … }
std::optional<int> GetResponseCode(network::SimpleURLLoader* loader) { … }
template <typename T>
class RunOnDestroyHelper final { … };
template <typename T, typename V>
requires(std::constructible_from<T, V>)
base::OnceCallback<void(T)> WrapAsAutorunCallback(
base::OnceCallback<void(T)> callback,
V arg_on_destroy) { … }
}
PlusAddressHttpClientImpl::PlusAddressHttpClientImpl(
signin::IdentityManager* identity_manager,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory)
: … { … }
PlusAddressHttpClientImpl::~PlusAddressHttpClientImpl() = default;
void PlusAddressHttpClientImpl::ReservePlusAddress(
const url::Origin& origin,
bool refresh,
PlusAddressRequestCallback on_completed) { … }
void PlusAddressHttpClientImpl::ConfirmPlusAddress(
const url::Origin& origin,
const PlusAddress& plus_address,
PlusAddressRequestCallback on_completed) { … }
void PlusAddressHttpClientImpl::PreallocatePlusAddresses(
PreallocatePlusAddressesCallback callback) { … }
void PlusAddressHttpClientImpl::Reset() { … }
void PlusAddressHttpClientImpl::ReservePlusAddressInternal(
const url::Origin& origin,
bool refresh,
PlusAddressRequestCallback on_completed,
std::optional<std::string> auth_token) { … }
void PlusAddressHttpClientImpl::ConfirmPlusAddressInternal(
const url::Origin& origin,
const PlusAddress& plus_address,
PlusAddressRequestCallback on_completed,
std::optional<std::string> auth_token) { … }
void PlusAddressHttpClientImpl::PreallocatePlusAddressesInternal(
PreallocatePlusAddressesCallback callback,
std::optional<std::string> auth_token) { … }
void PlusAddressHttpClientImpl::OnReserveOrConfirmPlusAddressComplete(
UrlLoaderList::iterator it,
PlusAddressNetworkRequestType type,
base::TimeTicks request_start,
PlusAddressRequestCallback on_completed,
std::unique_ptr<std::string> response) { … }
void PlusAddressHttpClientImpl::OnPreallocationComplete(
UrlLoaderList::iterator it,
base::TimeTicks request_start,
PreallocatePlusAddressesCallback on_completed,
std::unique_ptr<std::string> response) { … }
void PlusAddressHttpClientImpl::GetAuthToken(TokenReadyCallback callback) { … }
void PlusAddressHttpClientImpl::OnTokenFetched(
TokenReadyCallback callback,
GoogleServiceAuthError error,
signin::AccessTokenInfo access_token_info) { … }
std::unique_ptr<network::ResourceRequest>
PlusAddressHttpClientImpl::CreateRequest(std::string_view endpoint,
std::string_view method,
std::string_view auth_token) const { … }
}