blob: c305410a1a6a5113e9d9aeddfdc45bfa471ed2f0 [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;
24class ReportingDelegate;
25struct ReportingPolicy;
26class 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
35 // outlive the ReportingService. The ReportingService will take ownership of
36 // |delegate| and destroy it when the service is destroyed.
37 static std::unique_ptr<ReportingService> Create(
38 const ReportingPolicy& policy,
39 URLRequestContext* request_context,
40 std::unique_ptr<ReportingDelegate> delegate);
41
42 // Creates a ReportingService for testing purposes using an
43 // already-constructed ReportingContext. The ReportingService will take
44 // ownership of |reporting_context| and destroy it when the service is
45 // destroyed.
46 static std::unique_ptr<ReportingService> CreateForTesting(
47 std::unique_ptr<ReportingContext> reporting_context);
48
49 // Queues a report for delivery. |url| is the URL that originated the report.
50 // |group| is the endpoint group to which the report should be delivered.
51 // |type| is the type of the report. |body| is the body of the report.
52 //
53 // The Reporting system will take ownership of |body|; all other parameters
54 // will be copied.
55 virtual void QueueReport(const GURL& url,
56 const std::string& group,
57 const std::string& type,
58 std::unique_ptr<const base::Value> body) = 0;
59
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
65 protected:
66 ReportingService() {}
67
68 private:
69 DISALLOW_COPY_AND_ASSIGN(ReportingService);
70};
71
72} // namespace net
73
74#endif // NET_REPORTING_REPORTING_SERVICE_H_