#include "content/browser/aggregation_service/aggregation_service_impl.h"
#include <stdint.h>
#include <memory>
#include <optional>
#include <set>
#include <utility>
#include <vector>
#include "base/barrier_closure.h"
#include "base/check_op.h"
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/ptr_util.h"
#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
#include "base/metrics/histogram_functions.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool.h"
#include "base/task/updateable_sequenced_task_runner.h"
#include "base/time/default_clock.h"
#include "base/time/time.h"
#include "base/timer/elapsed_timer.h"
#include "base/values.h"
#include "content/browser/aggregation_service/aggregatable_report.h"
#include "content/browser/aggregation_service/aggregatable_report_assembler.h"
#include "content/browser/aggregation_service/aggregatable_report_scheduler.h"
#include "content/browser/aggregation_service/aggregatable_report_sender.h"
#include "content/browser/aggregation_service/aggregation_service_observer.h"
#include "content/browser/aggregation_service/aggregation_service_storage.h"
#include "content/browser/aggregation_service/aggregation_service_storage_sql.h"
#include "content/browser/aggregation_service/public_key.h"
#include "content/browser/storage_partition_impl.h"
#include "content/public/browser/storage_partition.h"
#include "url/gurl.h"
#include "url/origin.h"
namespace content {
namespace {
scoped_refptr<base::UpdateableSequencedTaskRunner> CreateStorageTaskRunner() { … }
}
AggregationServiceImpl::AggregationServiceImpl(
bool run_in_memory,
const base::FilePath& user_data_directory,
StoragePartitionImpl* storage_partition)
: … { … }
AggregationServiceImpl::~AggregationServiceImpl() = default;
std::unique_ptr<AggregationServiceImpl>
AggregationServiceImpl::CreateForTesting(
bool run_in_memory,
const base::FilePath& user_data_directory,
const base::Clock* clock,
std::unique_ptr<AggregatableReportScheduler> scheduler,
std::unique_ptr<AggregatableReportAssembler> assembler,
std::unique_ptr<AggregatableReportSender> sender) { … }
AggregationServiceImpl::AggregationServiceImpl(
bool run_in_memory,
const base::FilePath& user_data_directory,
const base::Clock* clock,
std::unique_ptr<AggregatableReportScheduler> scheduler,
std::unique_ptr<AggregatableReportAssembler> assembler,
std::unique_ptr<AggregatableReportSender> sender)
: … { … }
void AggregationServiceImpl::AssembleReport(
AggregatableReportRequest report_request,
AssemblyCallback callback) { … }
void AggregationServiceImpl::SendReport(
const GURL& url,
const AggregatableReport& report,
std::optional<AggregatableReportRequest::DelayType> delay_type,
SendCallback callback) { … }
void AggregationServiceImpl::SendReport(
const GURL& url,
const base::Value& contents,
std::optional<AggregatableReportRequest::DelayType> delay_type,
SendCallback callback) { … }
const base::SequenceBound<AggregationServiceStorage>&
AggregationServiceImpl::GetStorage() { … }
void AggregationServiceImpl::OnUserVisibleTaskStarted() { … }
void AggregationServiceImpl::ClearData(
base::Time delete_begin,
base::Time delete_end,
StoragePartition::StorageKeyMatcherFunction filter,
base::OnceClosure done) { … }
void AggregationServiceImpl::OnUserVisibleTaskComplete() { … }
void AggregationServiceImpl::OnClearDataComplete() { … }
void AggregationServiceImpl::ScheduleReport(
AggregatableReportRequest report_request) { … }
void AggregationServiceImpl::AssembleAndSendReport(
AggregatableReportRequest report_request) { … }
void AggregationServiceImpl::AssembleAndSendReportImpl(
AggregatableReportRequest report_request,
std::optional<AggregationServiceStorage::RequestId> request_id,
base::OnceClosure done) { … }
void AggregationServiceImpl::OnScheduledReportTimeReached(
std::vector<AggregationServiceStorage::RequestAndId> requests_and_ids) { … }
void AggregationServiceImpl::OnReportAssemblyComplete(
base::OnceClosure done,
std::optional<AggregationServiceStorage::RequestId> request_id,
GURL reporting_url,
base::ElapsedTimer elapsed_timer,
AggregatableReportRequest report_request,
std::optional<AggregatableReport> report,
AggregatableReportAssembler::AssemblyStatus status) { … }
void AggregationServiceImpl::OnReportSendingComplete(
base::OnceClosure done,
AggregatableReportRequest report_request,
std::optional<AggregationServiceStorage::RequestId> request_id,
AggregatableReport report,
base::ElapsedTimer sending_timer,
AggregatableReportSender::RequestStatus status) { … }
void AggregationServiceImpl::SetPublicKeysForTesting(
const GURL& url,
const PublicKeyset& keyset) { … }
void AggregationServiceImpl::AssembleAndSendReports(
std::vector<AggregationServiceStorage::RequestAndId> requests_and_ids,
base::RepeatingClosure done) { … }
void AggregationServiceImpl::GetPendingReportRequestsForWebUI(
base::OnceCallback<
void(std::vector<AggregationServiceStorage::RequestAndId>)> callback) { … }
void AggregationServiceImpl::SendReportsForWebUI(
const std::vector<AggregationServiceStorage::RequestId>& ids,
base::OnceClosure reports_sent_callback) { … }
void AggregationServiceImpl::OnGetRequestsToSendFromWebUI(
base::OnceClosure reports_sent_callback,
std::vector<AggregationServiceStorage::RequestAndId> requests_and_ids) { … }
void AggregationServiceImpl::GetPendingReportReportingOrigins(
base::OnceCallback<void(std::set<url::Origin>)> callback) { … }
void AggregationServiceImpl::AddObserver(AggregationServiceObserver* observer) { … }
void AggregationServiceImpl::RemoveObserver(
AggregationServiceObserver* observer) { … }
void AggregationServiceImpl::NotifyReportHandled(
const AggregatableReportRequest& request,
std::optional<AggregationServiceStorage::RequestId> request_id,
const std::optional<AggregatableReport>& report,
AggregationServiceObserver::ReportStatus status) { … }
void AggregationServiceImpl::NotifyRequestStorageModified() { … }
}