#include "components/metrics/net/net_metrics_log_uploader.h"
#include <sstream>
#include <string_view>
#include "base/base64.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/statistics_recorder.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "components/encrypted_messages/encrypted_message.pb.h"
#include "components/encrypted_messages/message_encrypter.h"
#include "components/metrics/metrics_log.h"
#include "components/metrics/metrics_log_uploader.h"
#include "net/base/load_flags.h"
#include "net/base/url_util.h"
#include "net/traffic_annotation/network_traffic_annotation.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 "third_party/metrics_proto/chrome_user_metrics_extension.pb.h"
#include "third_party/metrics_proto/reporting_info.pb.h"
#include "third_party/zlib/google/compression_utils.h"
#include "url/gurl.h"
namespace {
const char kEncryptedMessageLabel[] = …;
const uint8_t kServerPublicKey[] = …;
const uint32_t kServerPublicKeyVersion = …;
constexpr char kNoUploadUrlsReasonMsg[] = …;
net::NetworkTrafficAnnotationTag GetNetworkTrafficAnnotation(
const metrics::MetricsLogUploader::MetricServiceType& service_type,
const metrics::LogMetadata& log_metadata) { … }
std::string SerializeReportingInfo(
const metrics::ReportingInfo& reporting_info) { … }
bool EncryptString(const std::string& plaintext, std::string* encrypted) { … }
bool EncryptAndBase64EncodeString(const std::string& plaintext,
std::string* encoded) { … }
#ifndef NDEBUG
void LogUploadingHistograms(const std::string& compressed_log_data) { … }
#endif
}
namespace metrics {
NetMetricsLogUploader::NetMetricsLogUploader(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
const GURL& server_url,
std::string_view mime_type,
MetricsLogUploader::MetricServiceType service_type,
const MetricsLogUploader::UploadCallback& on_upload_complete)
: … { … }
NetMetricsLogUploader::NetMetricsLogUploader(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
const GURL& server_url,
const GURL& insecure_server_url,
std::string_view mime_type,
MetricsLogUploader::MetricServiceType service_type,
const MetricsLogUploader::UploadCallback& on_upload_complete)
: … { … }
NetMetricsLogUploader::~NetMetricsLogUploader() = default;
void NetMetricsLogUploader::UploadLog(const std::string& compressed_log_data,
const LogMetadata& log_metadata,
const std::string& log_hash,
const std::string& log_signature,
const ReportingInfo& reporting_info) { … }
void NetMetricsLogUploader::UploadLogToURL(
const std::string& compressed_log_data,
const LogMetadata& log_metadata,
const std::string& log_hash,
const std::string& log_signature,
const ReportingInfo& reporting_info,
const GURL& url) { … }
void NetMetricsLogUploader::HTTPFallbackAborted() { … }
void NetMetricsLogUploader::OnURLLoadComplete(
std::unique_ptr<std::string> response_body) { … }
}