#include "chrome/browser/enterprise/connectors/analysis/local_binary_upload_service.h"
#include <algorithm>
#include <memory>
#include <optional>
#include "base/metrics/histogram_functions.h"
#include "base/notreached.h"
#include "base/ranges/algorithm.h"
#include "base/syslog_logging.h"
#include "base/task/thread_pool.h"
#include "base/threading/scoped_blocking_call.h"
#include "chrome/browser/enterprise/connectors/common.h"
#include "chrome/browser/enterprise/signals/system_signals_service_host_factory.h"
#include "chrome/browser/safe_browsing/cloud_content_scanning/deep_scanning_utils.h"
#include "components/device_signals/core/browser/system_signals_service_host.h"
#include "components/enterprise/connectors/core/analysis_settings.h"
#include "content/public/browser/browser_thread.h"
#include "third_party/content_analysis_sdk/src/browser/include/content_analysis/sdk/analysis_client.h"
namespace enterprise_connectors {
namespace {
content_analysis::sdk::Client::Config SDKConfigFromRequest(
const safe_browsing::BinaryUploadService::Request* request) { … }
content_analysis::sdk::Client::Config SDKConfigFromAck(
const safe_browsing::BinaryUploadService::Ack* ack) { … }
content_analysis::sdk::Client::Config SDKConfigFromCancel(
const safe_browsing::BinaryUploadService::CancelRequests* cancel) { … }
content_analysis::sdk::ContentAnalysisRequest ConvertChromeRequestToSDKRequest(
const ContentAnalysisRequest& req) { … }
ContentAnalysisResponse ConvertSDKResponseToChromeResponse(
const content_analysis::sdk::ContentAnalysisResponse& res) { … }
content_analysis::sdk::ContentAnalysisAcknowledgement ConvertChromeAckToSDKAck(
const ContentAnalysisAcknowledgement& ack) { … }
int SendAckToSDK(
scoped_refptr<ContentAnalysisSdkManager::WrappedClient> wrapped,
content_analysis::sdk::ContentAnalysisAcknowledgement sdk_ack) { … }
int SendCancelToSDK(
scoped_refptr<ContentAnalysisSdkManager::WrappedClient> wrapped,
content_analysis::sdk::ContentAnalysisCancelRequests sdk_cancel) { … }
std::optional<content_analysis::sdk::ContentAnalysisResponse> SendRequestToSDK(
scoped_refptr<ContentAnalysisSdkManager::WrappedClient> wrapped,
content_analysis::sdk::ContentAnalysisRequest sdk_request) { … }
#if defined(_DEBUG)
void DumpSdkAnalysisResponse(
const char* prefix,
LocalBinaryUploadService::Request::Id id,
const content_analysis::sdk::ContentAnalysisResponse& response) { … }
void DumpAnalysisResponse(const char* prefix,
LocalBinaryUploadService::Request::Id id,
const ContentAnalysisResponse& response) { … }
#endif
}
LocalBinaryUploadService::RequestInfo::RequestInfo(
std::unique_ptr<LocalBinaryUploadService::Request> request,
base::OnceClosure closure)
: … { … }
LocalBinaryUploadService::RequestInfo::RequestInfo(
RequestInfo&& other) noexcept = default;
LocalBinaryUploadService::RequestInfo&
LocalBinaryUploadService::RequestInfo::operator=(RequestInfo&& other) noexcept =
default;
LocalBinaryUploadService::RequestInfo::~RequestInfo() noexcept = default;
LocalBinaryUploadService::LocalBinaryUploadService(Profile* profile)
: … { … }
LocalBinaryUploadService::~LocalBinaryUploadService() { … }
void LocalBinaryUploadService::MaybeUploadForDeepScanning(
std::unique_ptr<Request> request) { … }
void LocalBinaryUploadService::MaybeAcknowledge(std::unique_ptr<Ack> ack) { … }
void LocalBinaryUploadService::MaybeCancelRequests(
std::unique_ptr<CancelRequests> cancel) { … }
base::WeakPtr<safe_browsing::BinaryUploadService>
LocalBinaryUploadService::AsWeakPtr() { … }
device_signals::mojom::SystemSignalsService*
LocalBinaryUploadService::GetSystemSignalsService() { … }
void LocalBinaryUploadService::StartAgentVerification(
const content_analysis::sdk::Client::Config& config,
base::span<const char* const> subject_names) { … }
void LocalBinaryUploadService::OnFileSystemSignals(
content_analysis::sdk::Client::Config config,
base::span<const char* const> subject_names,
const std::vector<device_signals::FileSystemItem>& items) { … }
bool LocalBinaryUploadService::IsAgentVerified(
const content_analysis::sdk::Client::Config& config) { … }
bool LocalBinaryUploadService::IsAgentBeingVerified(
const content_analysis::sdk::Client::Config& config) { … }
void LocalBinaryUploadService::ResetClient(
const content_analysis::sdk::Client::Config& config) { … }
void LocalBinaryUploadService::DoLocalContentAnalysis(Request::Id id,
Result result,
Request::Data data) { … }
void LocalBinaryUploadService::HandleResponse(
scoped_refptr<ContentAnalysisSdkManager::WrappedClient> wrapped,
safe_browsing::BinaryUploadService::Request::Data data,
std::optional<content_analysis::sdk::ContentAnalysisResponse>
sdk_response) { … }
void LocalBinaryUploadService::DoSendAck(
scoped_refptr<ContentAnalysisSdkManager::WrappedClient> wrapped,
std::unique_ptr<safe_browsing::BinaryUploadService::Ack> ack) { … }
void LocalBinaryUploadService::DoSendCancel(
scoped_refptr<ContentAnalysisSdkManager::WrappedClient> wrapped,
std::unique_ptr<safe_browsing::BinaryUploadService::CancelRequests>
cancel) { … }
void LocalBinaryUploadService::HandleAckResponse(
scoped_refptr<ContentAnalysisSdkManager::WrappedClient> wrapped,
int status) { … }
void LocalBinaryUploadService::HandleCancelResponse(
scoped_refptr<ContentAnalysisSdkManager::WrappedClient> wrapped,
std::unique_ptr<safe_browsing::BinaryUploadService::CancelRequests> cancel,
int status) { … }
LocalBinaryUploadService::Request::Id
LocalBinaryUploadService::FindRequestByToken(
const content_analysis::sdk::ContentAnalysisResponse& sdk_response) { … }
void LocalBinaryUploadService::ProcessNextPendingRequest() { … }
bool LocalBinaryUploadService::ProcessRequest(Request::Id id) { … }
void LocalBinaryUploadService::FinishRequest(Request::Id id,
Result result,
ContentAnalysisResponse response) { … }
void LocalBinaryUploadService::SendCancelRequestsIfNeeded() { … }
void LocalBinaryUploadService::OnTimeout(Request::Id id) { … }
void LocalBinaryUploadService::RetryActiveRequestsSoonOrFailAllRequests(
const content_analysis::sdk::Client::Config& config) { … }
void LocalBinaryUploadService::StartConnectionRetry() { … }
void LocalBinaryUploadService::OnConnectionRetry() { … }
bool LocalBinaryUploadService::ConnectionRetryInProgress() { … }
void LocalBinaryUploadService::RecordRequestMetrics(
const RequestInfo& info,
Result result,
const enterprise_connectors::ContentAnalysisResponse& response) { … }
}