blob: a852d0f71348341f652c09d78552c032fd5ac37c [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;
Julia Tuttle4667c1c2017-12-19 18:27:3825class URLRequest;
juliatuttle381d77e2017-04-07 18:54:1226class 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
juliatuttle42c57312017-04-28 03:01:3035 // outlive the ReportingService.
juliatuttle381d77e2017-04-07 18:54:1236 static std::unique_ptr<ReportingService> Create(
37 const ReportingPolicy& policy,
juliatuttle42c57312017-04-28 03:01:3038 URLRequestContext* request_context);
juliatuttle381d77e2017-04-07 18:54:1239
40 // Creates a ReportingService for testing purposes using an
41 // already-constructed ReportingContext. The ReportingService will take
42 // ownership of |reporting_context| and destroy it when the service is
43 // destroyed.
44 static std::unique_ptr<ReportingService> CreateForTesting(
45 std::unique_ptr<ReportingContext> reporting_context);
46
47 // Queues a report for delivery. |url| is the URL that originated the report.
Douglas Creagerf6cb49f72018-07-19 20:14:5348 // |user_agent| is the User-Agent header that was used for the request.
juliatuttle381d77e2017-04-07 18:54:1249 // |group| is the endpoint group to which the report should be delivered.
50 // |type| is the type of the report. |body| is the body of the report.
51 //
52 // The Reporting system will take ownership of |body|; all other parameters
53 // will be copied.
54 virtual void QueueReport(const GURL& url,
Douglas Creagerf6cb49f72018-07-19 20:14:5355 const std::string& user_agent,
juliatuttle381d77e2017-04-07 18:54:1256 const std::string& group,
57 const std::string& type,
Julia Tuttle107e30672018-03-29 18:48:4258 std::unique_ptr<const base::Value> body,
59 int depth) = 0;
juliatuttle381d77e2017-04-07 18:54:1260
61 // Processes a Report-To header. |url| is the URL that originated the header;
62 // |header_value| is the normalized value of the Report-To header.
63 virtual void ProcessHeader(const GURL& url,
64 const std::string& header_value) = 0;
65
juliatuttleaeb1abc2017-05-04 21:14:3866 // Removes browsing data from the Reporting system. See
67 // ReportingBrowsingDataRemover for more details.
68 virtual void RemoveBrowsingData(
69 int data_type_mask,
Julia Tuttle227a6ff2017-12-19 19:44:2470 const base::RepeatingCallback<bool(const GURL&)>& origin_filter) = 0;
juliatuttleaeb1abc2017-05-04 21:14:3871
Eric Orthb812a442018-05-04 20:26:4872 // Like RemoveBrowsingData except removes data for all origins without a
73 // filter.
74 virtual void RemoveAllBrowsingData(int data_type_mask) = 0;
75
Julia Tuttle107e30672018-03-29 18:48:4276 // Checks how many uploads deep |request| is: 0 if it's not an upload, n+1 if
77 // it's an upload reporting on requests of at most depth n.
78 virtual int GetUploadDepth(const URLRequest& request) = 0;
Julia Tuttle4667c1c2017-12-19 18:27:3879
Julia Tuttle91a655d2018-01-26 18:03:0380 virtual const ReportingPolicy& GetPolicy() const = 0;
81
Douglas Creager853b2092018-04-13 23:03:2782 virtual base::Value StatusAsValue() const;
83
juliatuttle381d77e2017-04-07 18:54:1284 protected:
85 ReportingService() {}
86
87 private:
88 DISALLOW_COPY_AND_ASSIGN(ReportingService);
89};
90
91} // namespace net
92
93#endif // NET_REPORTING_REPORTING_SERVICE_H_