Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2021 The Chromium Authors |
Nan Lin | 89244d6 | 2021-11-12 21:38:17 | [diff] [blame] | 2 | // 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 Quintanilla | dce5ba9b | 2023-06-16 18:49:44 | [diff] [blame] | 8 | #include <set> |
Nan Lin | 6a52078 | 2022-08-15 19:45:13 | [diff] [blame] | 9 | #include <vector> |
| 10 | |
Avi Drissman | adac2199 | 2023-01-11 23:46:39 | [diff] [blame] | 11 | #include "base/functional/callback_forward.h" |
Nan Lin | 89244d6 | 2021-11-12 21:38:17 | [diff] [blame] | 12 | #include "content/browser/aggregation_service/aggregatable_report_assembler.h" |
Nan Lin | 16e55f48 | 2021-12-10 15:05:47 | [diff] [blame] | 13 | #include "content/browser/aggregation_service/aggregatable_report_sender.h" |
Nan Lin | 6a52078 | 2022-08-15 19:45:13 | [diff] [blame] | 14 | #include "content/browser/aggregation_service/aggregation_service_storage.h" |
Alex Turner | 548c256c | 2023-07-28 16:08:47 | [diff] [blame] | 15 | #include "content/common/content_export.h" |
Alex Turner | b835b3a | 2022-07-21 21:42:18 | [diff] [blame] | 16 | #include "content/public/browser/storage_partition.h" |
Nan Lin | 89244d6 | 2021-11-12 21:38:17 | [diff] [blame] | 17 | |
Nan Lin | 16e55f48 | 2021-12-10 15:05:47 | [diff] [blame] | 18 | namespace base { |
Nan Lin | b771003b36 | 2022-01-19 21:05:53 | [diff] [blame] | 19 | class Time; |
Nan Lin | 16e55f48 | 2021-12-10 15:05:47 | [diff] [blame] | 20 | } // namespace base |
| 21 | |
Thomas Quintanilla | dce5ba9b | 2023-06-16 18:49:44 | [diff] [blame] | 22 | namespace url { |
| 23 | class Origin; |
| 24 | } // namespace url |
| 25 | |
Nan Lin | 89244d6 | 2021-11-12 21:38:17 | [diff] [blame] | 26 | namespace content { |
| 27 | |
Nan Lin | 55ad2a5a | 2022-08-15 21:32:57 | [diff] [blame] | 28 | class AggregationServiceObserver; |
Nan Lin | 89244d6 | 2021-11-12 21:38:17 | [diff] [blame] | 29 | class AggregatableReportRequest; |
| 30 | class BrowserContext; |
| 31 | |
| 32 | // External interface for the aggregation service. |
Alex Turner | 548c256c | 2023-07-28 16:08:47 | [diff] [blame] | 33 | class CONTENT_EXPORT AggregationService { |
Nan Lin | 89244d6 | 2021-11-12 21:38:17 | [diff] [blame] | 34 | public: |
| 35 | using AssemblyStatus = AggregatableReportAssembler::AssemblyStatus; |
| 36 | using AssemblyCallback = AggregatableReportAssembler::AssemblyCallback; |
| 37 | |
Alex Turner | c1754edb | 2022-08-29 18:59:38 | [diff] [blame] | 38 | // 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 Lin | 89244d6 | 2021-11-12 21:38:17 | [diff] [blame] | 43 | 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 Lin | 16e55f48 | 2021-12-10 15:05:47 | [diff] [blame] | 50 | // Constructs an AggregatableReport from the information in `report_request`. |
| 51 | // `callback` will be run once completed which returns the assembled report |
Dan McArdle | 08ad611 | 2023-11-21 20:39:47 | [diff] [blame] | 52 | // if successful, otherwise `std::nullopt` will be returned. |
Nan Lin | 89244d6 | 2021-11-12 21:38:17 | [diff] [blame] | 53 | virtual void AssembleReport(AggregatableReportRequest report_request, |
| 54 | AssemblyCallback callback) = 0; |
Nan Lin | 16e55f48 | 2021-12-10 15:05:47 | [diff] [blame] | 55 | |
Alex Turner | b835b3a | 2022-07-21 21:42:18 | [diff] [blame] | 56 | // 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 Lin | b771003b36 | 2022-01-19 21:05:53 | [diff] [blame] | 61 | virtual void ClearData(base::Time delete_begin, |
| 62 | base::Time delete_end, |
Alex Turner | b835b3a | 2022-07-21 21:42:18 | [diff] [blame] | 63 | StoragePartition::StorageKeyMatcherFunction filter, |
Nan Lin | b771003b36 | 2022-01-19 21:05:53 | [diff] [blame] | 64 | base::OnceClosure done) = 0; |
Alex Turner | 48e2530 | 2022-07-21 20:25:35 | [diff] [blame] | 65 | |
| 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 Lin | 6a52078 | 2022-08-15 19:45:13 | [diff] [blame] | 70 | |
Alex Turner | 4162376f | 2022-10-20 18:04:10 | [diff] [blame] | 71 | // Immediately assembles and then sends `report_request`. |
| 72 | virtual void AssembleAndSendReport( |
| 73 | AggregatableReportRequest report_request) = 0; |
| 74 | |
Nan Lin | 6a52078 | 2022-08-15 19:45:13 | [diff] [blame] | 75 | // 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 Lin | 55ad2a5a | 2022-08-15 21:32:57 | [diff] [blame] | 88 | |
Thomas Quintanilla | dce5ba9b | 2023-06-16 18:49:44 | [diff] [blame] | 89 | // 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 Lin | 55ad2a5a | 2022-08-15 21:32:57 | [diff] [blame] | 94 | virtual void AddObserver(AggregationServiceObserver* observer) = 0; |
| 95 | |
| 96 | virtual void RemoveObserver(AggregationServiceObserver* observer) = 0; |
Nan Lin | 89244d6 | 2021-11-12 21:38:17 | [diff] [blame] | 97 | }; |
| 98 | |
| 99 | } // namespace content |
| 100 | |
Lei Zhang | ed9be3a | 2021-11-17 22:01:18 | [diff] [blame] | 101 | #endif // CONTENT_BROWSER_AGGREGATION_SERVICE_AGGREGATION_SERVICE_H_ |