blob: 831e07119666717df47c4de497a77e03b94c60c9 [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;
19} // namespace
20
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.
47 // |group| is the endpoint group to which the report should be delivered.
48 // |type| is the type of the report. |body| is the body of the report.
49 //
50 // The Reporting system will take ownership of |body|; all other parameters
51 // will be copied.
52 virtual void QueueReport(const GURL& url,
53 const std::string& group,
54 const std::string& type,
55 std::unique_ptr<const base::Value> body) = 0;
56
57 // Processes a Report-To header. |url| is the URL that originated the header;
58 // |header_value| is the normalized value of the Report-To header.
59 virtual void ProcessHeader(const GURL& url,
60 const std::string& header_value) = 0;
61
62 protected:
63 ReportingService() {}
64
65 private:
66 DISALLOW_COPY_AND_ASSIGN(ReportingService);
67};
68
69} // namespace net
70
71#endif // NET_REPORTING_REPORTING_SERVICE_H_