blob: 839fa73e8ef2600112a54489243c1a23c311149b [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.
48 // |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,
54 const std::string& group,
55 const std::string& type,
Julia Tuttle107e30672018-03-29 18:48:4256 std::unique_ptr<const base::Value> body,
57 int depth) = 0;
juliatuttle381d77e2017-04-07 18:54:1258
59 // Processes a Report-To header. |url| is the URL that originated the header;
60 // |header_value| is the normalized value of the Report-To header.
61 virtual void ProcessHeader(const GURL& url,
62 const std::string& header_value) = 0;
63
juliatuttleaeb1abc2017-05-04 21:14:3864 // Removes browsing data from the Reporting system. See
65 // ReportingBrowsingDataRemover for more details.
66 virtual void RemoveBrowsingData(
67 int data_type_mask,
Julia Tuttle227a6ff2017-12-19 19:44:2468 const base::RepeatingCallback<bool(const GURL&)>& origin_filter) = 0;
juliatuttleaeb1abc2017-05-04 21:14:3869
Julia Tuttle107e30672018-03-29 18:48:4270 // Checks how many uploads deep |request| is: 0 if it's not an upload, n+1 if
71 // it's an upload reporting on requests of at most depth n.
72 virtual int GetUploadDepth(const URLRequest& request) = 0;
Julia Tuttle4667c1c2017-12-19 18:27:3873
Julia Tuttle91a655d2018-01-26 18:03:0374 virtual const ReportingPolicy& GetPolicy() const = 0;
75
Douglas Creager853b2092018-04-13 23:03:2776 virtual base::Value StatusAsValue() const;
77
juliatuttle381d77e2017-04-07 18:54:1278 protected:
79 ReportingService() {}
80
81 private:
82 DISALLOW_COPY_AND_ASSIGN(ReportingService);
83};
84
85} // namespace net
86
87#endif // NET_REPORTING_REPORTING_SERVICE_H_