blob: c7671d1f9b66509086606be34f96d6b056970e9c [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"
14
15class GURL;
16
17namespace base {
18class Value;
bncd479b3c2017-05-24 18:54:5319} // namespace base
juliatuttle381d77e2017-04-07 18:54:1220
21namespace net {
22
23class ReportingContext;
juliatuttle381d77e2017-04-07 18:54:1224struct ReportingPolicy;
25class URLRequestContext;
26
27// The external interface to the Reporting system, used by the embedder of //net
28// and also other parts of //net.
29class NET_EXPORT ReportingService {
30 public:
31 virtual ~ReportingService();
32
33 // Creates a ReportingService. |policy| will be copied. |request_context| must
juliatuttle42c57312017-04-28 03:01:3034 // outlive the ReportingService.
juliatuttle381d77e2017-04-07 18:54:1235 static std::unique_ptr<ReportingService> Create(
36 const ReportingPolicy& policy,
juliatuttle42c57312017-04-28 03:01:3037 URLRequestContext* request_context);
juliatuttle381d77e2017-04-07 18:54:1238
39 // Creates a ReportingService for testing purposes using an
40 // already-constructed ReportingContext. The ReportingService will take
41 // ownership of |reporting_context| and destroy it when the service is
42 // destroyed.
43 static std::unique_ptr<ReportingService> CreateForTesting(
44 std::unique_ptr<ReportingContext> reporting_context);
45
46 // Queues a report for delivery. |url| is the URL that originated the report.
Douglas Creagerf6cb49f72018-07-19 20:14:5347 // |user_agent| is the User-Agent header that was used for the request.
juliatuttle381d77e2017-04-07 18:54:1248 // |group| is the endpoint group to which the report should be delivered.
49 // |type| is the type of the report. |body| is the body of the report.
50 //
51 // The Reporting system will take ownership of |body|; all other parameters
52 // will be copied.
53 virtual void QueueReport(const GURL& url,
Douglas Creagerf6cb49f72018-07-19 20:14:5354 const std::string& user_agent,
juliatuttle381d77e2017-04-07 18:54:1255 const std::string& group,
56 const std::string& type,
Julia Tuttle107e30672018-03-29 18:48:4257 std::unique_ptr<const base::Value> body,
58 int depth) = 0;
juliatuttle381d77e2017-04-07 18:54:1259
60 // Processes a Report-To header. |url| is the URL that originated the header;
61 // |header_value| is the normalized value of the Report-To header.
62 virtual void ProcessHeader(const GURL& url,
63 const std::string& header_value) = 0;
64
juliatuttleaeb1abc2017-05-04 21:14:3865 // Removes browsing data from the Reporting system. See
66 // ReportingBrowsingDataRemover for more details.
67 virtual void RemoveBrowsingData(
68 int data_type_mask,
Julia Tuttle227a6ff2017-12-19 19:44:2469 const base::RepeatingCallback<bool(const GURL&)>& origin_filter) = 0;
juliatuttleaeb1abc2017-05-04 21:14:3870
Eric Orthb812a442018-05-04 20:26:4871 // Like RemoveBrowsingData except removes data for all origins without a
72 // filter.
73 virtual void RemoveAllBrowsingData(int data_type_mask) = 0;
74
Lily Chen91b51e62019-03-01 16:46:0775 // Shuts down the Reporting service so that no new headers or reports are
76 // processed, and pending uploads are cancelled.
77 virtual void OnShutdown() = 0;
78
Julia Tuttle91a655d2018-01-26 18:03:0379 virtual const ReportingPolicy& GetPolicy() const = 0;
80
Douglas Creager853b2092018-04-13 23:03:2781 virtual base::Value StatusAsValue() const;
82
Lily Chen91b51e62019-03-01 16:46:0783 virtual ReportingContext* GetContextForTesting() const = 0;
84
juliatuttle381d77e2017-04-07 18:54:1285 protected:
86 ReportingService() {}
87
88 private:
89 DISALLOW_COPY_AND_ASSIGN(ReportingService);
90};
91
92} // namespace net
93
94#endif // NET_REPORTING_REPORTING_SERVICE_H_