blob: aa7dc40e369f640f5d30e208d43851b86010d26d [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,
56 std::unique_ptr<const base::Value> body) = 0;
57
58 // Processes a Report-To header. |url| is the URL that originated the header;
59 // |header_value| is the normalized value of the Report-To header.
60 virtual void ProcessHeader(const GURL& url,
61 const std::string& header_value) = 0;
62
juliatuttleaeb1abc2017-05-04 21:14:3863 // Removes browsing data from the Reporting system. See
64 // ReportingBrowsingDataRemover for more details.
65 virtual void RemoveBrowsingData(
66 int data_type_mask,
Julia Tuttle227a6ff2017-12-19 19:44:2467 const base::RepeatingCallback<bool(const GURL&)>& origin_filter) = 0;
juliatuttleaeb1abc2017-05-04 21:14:3868
Julia Tuttle4667c1c2017-12-19 18:27:3869 // Checks whether |request| is a Reporting upload, to avoid loops of reporting
70 // about report uploads.
71 virtual bool RequestIsUpload(const URLRequest& request) = 0;
72
juliatuttle381d77e2017-04-07 18:54:1273 protected:
74 ReportingService() {}
75
76 private:
77 DISALLOW_COPY_AND_ASSIGN(ReportingService);
78};
79
80} // namespace net
81
82#endif // NET_REPORTING_REPORTING_SERVICE_H_