#include "chrome/browser/safe_browsing/extension_telemetry/extension_telemetry_uploader.h"
#include <memory>
#include <utility>
#include "base/functional/bind.h"
#include "base/metrics/histogram_functions.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "components/safe_browsing/core/browser/sync/safe_browsing_primary_account_token_fetcher.h"
#include "components/safe_browsing/core/common/utils.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "net/base/load_flags.h"
#include "net/http/http_status_code.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"
namespace safe_browsing {
namespace {
constexpr const char kUploadUrl[] = …;
constexpr net::NetworkTrafficAnnotationTag
kSafeBrowsingExtensionTelemetryTrafficAnnotation = …;
const int kInitialBackoffSeconds = …;
const int kBackoffFactor = …;
const int kMaxRetryAttempts = …;
void RecordUploadSize(size_t size) { … }
void RecordUploadSuccess(bool success) { … }
void RecordUploadRetries(int num_retries) { … }
void RecordNetworkResponseCodeOrError(int code_or_error) { … }
void RecordUploadDuration(bool success, base::TimeDelta delta) { … }
}
ExtensionTelemetryUploader::~ExtensionTelemetryUploader() = default;
ExtensionTelemetryUploader::ExtensionTelemetryUploader(
OnUploadCallback callback,
const scoped_refptr<network::SharedURLLoaderFactory>& url_loader_factory,
std::unique_ptr<std::string> upload_data,
std::unique_ptr<SafeBrowsingTokenFetcher> token_fetcher)
: … { … }
void ExtensionTelemetryUploader::Start() { … }
std::string ExtensionTelemetryUploader::GetUploadURLForTest() { … }
void ExtensionTelemetryUploader::MaybeSendRequestWithAccessToken() { … }
void ExtensionTelemetryUploader::SendRequest(const std::string& access_token) { … }
void ExtensionTelemetryUploader::OnURLLoaderComplete(
std::unique_ptr<std::string> response_body) { … }
void ExtensionTelemetryUploader::RetryOrFinish(
int net_error,
int response_code,
const std::string& response_data) { … }
}