chromium/components/plus_addresses/plus_address_http_client_impl.cc

// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#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 =;

// See docs/network_traffic_annotations.md for reference.
// TODO(b/295556954): Update the description and trigger fields when possible.
//                    Also replace the policy_exception when we have a policy.
constexpr net::NetworkTrafficAnnotationTag kReservePlusAddressAnnotation =;

// TODO(b/277532955): Update the description and trigger fields when possible.
//                    Also replace the policy_exception when we have a policy.
constexpr net::NetworkTrafficAnnotationTag kConfirmPlusAddressAnnotation =;

constexpr net::NetworkTrafficAnnotationTag kPreallocatePlusAddressesAnnotation =;

std::optional<GURL> ValidateAndGetUrl() {}

// Returns the HTTP response code for the response in the `loader`. If there is
// none, it returns `std::nullopt`.
std::optional<int> GetResponseCode(network::SimpleURLLoader* loader) {}

// Helper wrapper around a `base::OnceCallback` that runs the `callback` with
// argument `arg_on_destroy` if the callback is destroyed and has not been run
// at that point in time.
template <typename T>
class RunOnDestroyHelper final {};

// Given a `base::OnceCallback<void(T)>` `callback`, it returns another
// `base::OnceCallback` of the same signature with the property that the
// returned callback is run with argument `arg_on_destroy` on its destruction if
// it has not been run before.
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) {}

}  // namespace

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 {}

}  // namespace plus_addresses