blob: eca02e230dd48f81746e591d13d89941e929937e [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2021 The Chromium Authors
Nan Lin89244d62021-11-12 21:38:172// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CONTENT_BROWSER_AGGREGATION_SERVICE_AGGREGATION_SERVICE_H_
6#define CONTENT_BROWSER_AGGREGATION_SERVICE_AGGREGATION_SERVICE_H_
7
Thomas Quintanilladce5ba9b2023-06-16 18:49:448#include <set>
Nan Lin6a520782022-08-15 19:45:139#include <vector>
10
Avi Drissmanadac21992023-01-11 23:46:3911#include "base/functional/callback_forward.h"
Nan Lin89244d62021-11-12 21:38:1712#include "content/browser/aggregation_service/aggregatable_report_assembler.h"
Nan Lin16e55f482021-12-10 15:05:4713#include "content/browser/aggregation_service/aggregatable_report_sender.h"
Nan Lin6a520782022-08-15 19:45:1314#include "content/browser/aggregation_service/aggregation_service_storage.h"
Alex Turner548c256c2023-07-28 16:08:4715#include "content/common/content_export.h"
Alex Turnerb835b3a2022-07-21 21:42:1816#include "content/public/browser/storage_partition.h"
Nan Lin89244d62021-11-12 21:38:1717
Nan Lin16e55f482021-12-10 15:05:4718namespace base {
Nan Linb771003b362022-01-19 21:05:5319class Time;
Nan Lin16e55f482021-12-10 15:05:4720} // namespace base
21
Thomas Quintanilladce5ba9b2023-06-16 18:49:4422namespace url {
23class Origin;
24} // namespace url
25
Nan Lin89244d62021-11-12 21:38:1726namespace content {
27
Nan Lin55ad2a5a2022-08-15 21:32:5728class AggregationServiceObserver;
Nan Lin89244d62021-11-12 21:38:1729class AggregatableReportRequest;
30class BrowserContext;
31
32// External interface for the aggregation service.
Alex Turner548c256c2023-07-28 16:08:4733class CONTENT_EXPORT AggregationService {
Nan Lin89244d62021-11-12 21:38:1734 public:
35 using AssemblyStatus = AggregatableReportAssembler::AssemblyStatus;
36 using AssemblyCallback = AggregatableReportAssembler::AssemblyCallback;
37
Alex Turnerc1754edb2022-08-29 18:59:3838 // No more report requests can be scheduled and not yet sent than this. Any
39 // additional requests will silently be dropped until there is more capacity.
40 // This ensures malicious actors cannot use unbounded memory or disk space.
41 static constexpr int kMaxStoredReportsPerReportingOrigin = 1000;
42
Nan Lin89244d62021-11-12 21:38:1743 virtual ~AggregationService() = default;
44
45 // Gets the AggregationService that should be used for handling aggregations
46 // in the given `browser_context`. Returns nullptr if aggregation service is
47 // not enabled.
48 static AggregationService* GetService(BrowserContext* browser_context);
49
Nan Lin16e55f482021-12-10 15:05:4750 // Constructs an AggregatableReport from the information in `report_request`.
51 // `callback` will be run once completed which returns the assembled report
Dan McArdle08ad6112023-11-21 20:39:4752 // if successful, otherwise `std::nullopt` will be returned.
Nan Lin89244d62021-11-12 21:38:1753 virtual void AssembleReport(AggregatableReportRequest report_request,
54 AssemblyCallback callback) = 0;
Nan Lin16e55f482021-12-10 15:05:4755
Alex Turnerb835b3a2022-07-21 21:42:1856 // Deletes all data in storage that were fetched/stored between `delete_begin`
57 // and `delete_end` time (inclusive). Null times are treated as unbounded
58 // lower or upper range. If `!filter.is_null()`, requests with a reporting
59 // origin that does *not* match the `filter` are retained (i.e. not cleared);
60 // `filter` does not affect public key deletion.
Nan Linb771003b362022-01-19 21:05:5361 virtual void ClearData(base::Time delete_begin,
62 base::Time delete_end,
Alex Turnerb835b3a2022-07-21 21:42:1863 StoragePartition::StorageKeyMatcherFunction filter,
Nan Linb771003b362022-01-19 21:05:5364 base::OnceClosure done) = 0;
Alex Turner48e25302022-07-21 20:25:3565
66 // Schedules `report_request` to be assembled and sent at its scheduled report
67 // time. It is stored on disk (unless in incognito) until then. See the
68 // `AggregatableReportScheduler` for details.
69 virtual void ScheduleReport(AggregatableReportRequest report_request) = 0;
Nan Lin6a520782022-08-15 19:45:1370
Alex Turner4162376f2022-10-20 18:04:1071 // Immediately assembles and then sends `report_request`.
72 virtual void AssembleAndSendReport(
73 AggregatableReportRequest report_request) = 0;
74
Nan Lin6a520782022-08-15 19:45:1375 // Gets all pending report requests that are currently stored. Used for
76 // populating WebUI.
77 // TODO(linnan): Consider enforcing a limit on the number of requests
78 // returned.
79 virtual void GetPendingReportRequestsForWebUI(
80 base::OnceCallback<void(
81 std::vector<AggregationServiceStorage::RequestAndId>)> callback) = 0;
82
83 // Sends the given reports immediately, and runs `reports_sent_callback` once
84 // they have all been sent.
85 virtual void SendReportsForWebUI(
86 const std::vector<AggregationServiceStorage::RequestId>& ids,
87 base::OnceClosure reports_sent_callback) = 0;
Nan Lin55ad2a5a2022-08-15 21:32:5788
Thomas Quintanilladce5ba9b2023-06-16 18:49:4489 // Runs `callback` with a set containing all the distinct reporting origins
90 // stored in the report request table.
91 virtual void GetPendingReportReportingOrigins(
92 base::OnceCallback<void(std::set<url::Origin>)> callback) = 0;
93
Nan Lin55ad2a5a2022-08-15 21:32:5794 virtual void AddObserver(AggregationServiceObserver* observer) = 0;
95
96 virtual void RemoveObserver(AggregationServiceObserver* observer) = 0;
Nan Lin89244d62021-11-12 21:38:1797};
98
99} // namespace content
100
Lei Zhanged9be3a2021-11-17 22:01:18101#endif // CONTENT_BROWSER_AGGREGATION_SERVICE_AGGREGATION_SERVICE_H_