blob: 233608c0b2ac59a74c96d536ab1e000d65e2d6d5 [file] [log] [blame]
juliatuttle381d77e2017-04-07 18:54:121// Copyright 2017 The Chromium Authors. All rights reserved.
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 NET_REPORTING_REPORTING_SERVICE_H_
6#define NET_REPORTING_REPORTING_SERVICE_H_
7
8#include <memory>
9#include <string>
10
11#include "base/callback.h"
12#include "base/macros.h"
13#include "net/base/net_export.h"
Lily Chen731a95c2019-05-06 22:27:2214#include "net/reporting/reporting_cache.h"
juliatuttle381d77e2017-04-07 18:54:1215
16class GURL;
17
18namespace base {
19class Value;
bncd479b3c2017-05-24 18:54:5320} // namespace base
juliatuttle381d77e2017-04-07 18:54:1221
22namespace net {
23
24class ReportingContext;
juliatuttle381d77e2017-04-07 18:54:1225struct ReportingPolicy;
26class URLRequestContext;
27
28// The external interface to the Reporting system, used by the embedder of //net
29// and also other parts of //net.
30class NET_EXPORT ReportingService {
31 public:
32 virtual ~ReportingService();
33
34 // Creates a ReportingService. |policy| will be copied. |request_context| must
Lily Chen731a95c2019-05-06 22:27:2235 // outlive the ReportingService. |store| must outlive the ReportingService.
36 // If |store| is null, the ReportingCache will be in-memory only.
juliatuttle381d77e2017-04-07 18:54:1237 static std::unique_ptr<ReportingService> Create(
38 const ReportingPolicy& policy,
Lily Chen731a95c2019-05-06 22:27:2239 URLRequestContext* request_context,
40 ReportingCache::PersistentReportingStore* store);
juliatuttle381d77e2017-04-07 18:54:1241
42 // Creates a ReportingService for testing purposes using an
43 // already-constructed ReportingContext. The ReportingService will take
44 // ownership of |reporting_context| and destroy it when the service is
45 // destroyed.
46 static std::unique_ptr<ReportingService> CreateForTesting(
47 std::unique_ptr<ReportingContext> reporting_context);
48
49 // Queues a report for delivery. |url| is the URL that originated the report.
Douglas Creagerf6cb49f72018-07-19 20:14:5350 // |user_agent| is the User-Agent header that was used for the request.
juliatuttle381d77e2017-04-07 18:54:1251 // |group| is the endpoint group to which the report should be delivered.
52 // |type| is the type of the report. |body| is the body of the report.
53 //
54 // The Reporting system will take ownership of |body|; all other parameters
55 // will be copied.
56 virtual void QueueReport(const GURL& url,
Douglas Creagerf6cb49f72018-07-19 20:14:5357 const std::string& user_agent,
juliatuttle381d77e2017-04-07 18:54:1258 const std::string& group,
59 const std::string& type,
Julia Tuttle107e30672018-03-29 18:48:4260 std::unique_ptr<const base::Value> body,
61 int depth) = 0;
juliatuttle381d77e2017-04-07 18:54:1262
63 // Processes a Report-To header. |url| is the URL that originated the header;
64 // |header_value| is the normalized value of the Report-To header.
65 virtual void ProcessHeader(const GURL& url,
66 const std::string& header_value) = 0;
67
juliatuttleaeb1abc2017-05-04 21:14:3868 // Removes browsing data from the Reporting system. See
69 // ReportingBrowsingDataRemover for more details.
70 virtual void RemoveBrowsingData(
71 int data_type_mask,
Julia Tuttle227a6ff2017-12-19 19:44:2472 const base::RepeatingCallback<bool(const GURL&)>& origin_filter) = 0;
juliatuttleaeb1abc2017-05-04 21:14:3873
Eric Orthb812a442018-05-04 20:26:4874 // Like RemoveBrowsingData except removes data for all origins without a
75 // filter.
76 virtual void RemoveAllBrowsingData(int data_type_mask) = 0;
77
Lily Chen91b51e62019-03-01 16:46:0778 // Shuts down the Reporting service so that no new headers or reports are
79 // processed, and pending uploads are cancelled.
80 virtual void OnShutdown() = 0;
81
Julia Tuttle91a655d2018-01-26 18:03:0382 virtual const ReportingPolicy& GetPolicy() const = 0;
83
Douglas Creager853b2092018-04-13 23:03:2784 virtual base::Value StatusAsValue() const;
85
Lily Chen91b51e62019-03-01 16:46:0786 virtual ReportingContext* GetContextForTesting() const = 0;
87
juliatuttle381d77e2017-04-07 18:54:1288 protected:
89 ReportingService() {}
90
91 private:
92 DISALLOW_COPY_AND_ASSIGN(ReportingService);
93};
94
95} // namespace net
96
97#endif // NET_REPORTING_REPORTING_SERVICE_H_