#include "components/supervised_user/core/browser/proto_fetcher.h"
#include <memory>
#include <optional>
#include <string>
#include <string_view>
#include <utility>
#include "base/check_op.h"
#include "base/functional/bind.h"
#include "base/functional/callback_forward.h"
#include "base/memory/scoped_refptr.h"
#include "base/metrics/histogram_functions.h"
#include "base/notreached.h"
#include "base/strings/strcat.h"
#include "base/strings/string_util.h"
#include "base/time/time.h"
#include "base/timer/elapsed_timer.h"
#include "base/types/expected.h"
#include "base/types/optional_util.h"
#include "base/version_info/channel.h"
#include "components/signin/public/identity_manager/access_token_info.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "components/supervised_user/core/browser/fetcher_config.h"
#include "components/supervised_user/core/browser/proto/kidsmanagement_messages.pb.h"
#include "components/supervised_user/core/browser/proto/test.pb.h"
#include "components/supervised_user/core/common/supervised_user_constants.h"
#include "google_apis/common/api_key_request_util.h"
#include "google_apis/gaia/google_service_auth_error.h"
#include "net/base/request_priority.h"
#include "net/http/http_status_code.h"
#include "proto_fetcher.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/mojom/fetch_api.mojom-shared.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "third_party/protobuf/src/google/protobuf/message_lite.h"
#include "url/gurl.h"
namespace supervised_user {
namespace {
const int kUrlLoaderRetryCount = …;
bool IsLoadingSuccessful(const network::SimpleURLLoader& loader) { … }
bool HasHttpOkResponse(const network::SimpleURLLoader& loader) { … }
int HttpStatusOrNetError(const network::SimpleURLLoader& loader) { … }
std::string CreateAuthorizationHeader(
const signin::AccessTokenInfo& access_token_info) { … }
constexpr std::string_view kSystemParameters("alt=proto");
GURL CreateRequestUrl(const FetcherConfig& config,
const FetcherConfig::PathArgs& args) { … }
std::unique_ptr<network::SimpleURLLoader> InitializeSimpleUrlLoader(
const std::optional<signin::AccessTokenInfo> access_token_info,
const FetcherConfig& fetcher_config,
const FetcherConfig::PathArgs& args,
std::optional<version_info::Channel> channel,
const std::optional<std::string>& payload) { … }
}
base::TimeDelta Stopwatch::Lap() { … }
base::TimeDelta Stopwatch::Elapsed() const { … }
Metrics::Metrics(std::string_view basename) : … { … }
std::optional<Metrics> Metrics::FromConfig(
const FetcherConfig& config) { … }
void Metrics::RecordStatus(const ProtoFetcherStatus& status) const { … }
void Metrics::RecordLatency() const { … }
void Metrics::RecordAccessTokenLatency(
GoogleServiceAuthError::State auth_error_state) { … }
void Metrics::RecordApiLatency(
ProtoFetcherStatus::HttpStatusOrNetErrorType http_status_or_net_error) { … }
void Metrics::RecordStatusLatency(const ProtoFetcherStatus& status) const { … }
void Metrics::RecordAuthError(const GoogleServiceAuthError& auth_error) const { … }
void Metrics::RecordHttpStatusOrNetError(
const ProtoFetcherStatus& status) const { … }
std::string Metrics::GetMetricKey(MetricType metric_type) const { … }
std::string Metrics::GetFullHistogramName(MetricType metric_type) const { … }
std::string Metrics::GetFullHistogramName(MetricType metric_type,
ProtoFetcherStatus status) const { … }
std::string Metrics::GetFullHistogramName(
MetricType metric_type,
GoogleServiceAuthError::State auth_error_state) const { … }
std::string Metrics::GetFullHistogramName(
MetricType metric_type,
ProtoFetcherStatus::HttpStatusOrNetErrorType http_status_or_net_error)
const { … }
std::string Metrics::ToMetricEnumLabel(const ProtoFetcherStatus& status) { … }
OverallMetrics::OverallMetrics(std::string_view basename) : … { … }
std::optional<OverallMetrics> OverallMetrics::FromConfig(
const FetcherConfig& config) { … }
void OverallMetrics::RecordStatusLatency(
const ProtoFetcherStatus& status) const { … }
std::string OverallMetrics::GetMetricKey(MetricType metric_type) const { … }
void OverallMetrics::RecordRetryCount(int count) const { … }
AbstractProtoFetcher::AbstractProtoFetcher(
signin::IdentityManager& identity_manager,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
std::string_view payload,
const FetcherConfig& fetcher_config,
const FetcherConfig::PathArgs& args,
std::optional<version_info::Channel> channel)
: … { … }
AbstractProtoFetcher::~AbstractProtoFetcher() = default;
bool AbstractProtoFetcher::IsMetricsRecordingEnabled() const { … }
void AbstractProtoFetcher::RecordMetrics(const ProtoFetcherStatus& status) { … }
void AbstractProtoFetcher::OnAccessTokenFetchComplete(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
base::expected<signin::AccessTokenInfo, GoogleServiceAuthError>
access_token) { … }
void AbstractProtoFetcher::OnSimpleUrlLoaderComplete(
std::unique_ptr<std::string> response_body) { … }
std::optional<std::string> AbstractProtoFetcher::GetRequestPayload() const { … }
StatusFetcher::StatusFetcher(
signin::IdentityManager& identity_manager,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
std::string_view payload,
const FetcherConfig& fetcher_config,
const FetcherConfig::PathArgs& args,
std::optional<version_info::Channel> channel,
Callback callback)
: … { … }
StatusFetcher::~StatusFetcher() = default;
void StatusFetcher::OnError(const ProtoFetcherStatus& status) { … }
void StatusFetcher::OnResponse(std::unique_ptr<std::string> response_body) { … }
void StatusFetcher::OnStatus(const ProtoFetcherStatus& status) { … }
}