juliatuttle | 381d77e | 2017-04-07 18:54:12 | [diff] [blame] | 1 | // 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 | |
| 15 | class GURL; |
| 16 | |
| 17 | namespace base { |
| 18 | class Value; |
| 19 | } // namespace |
| 20 | |
| 21 | namespace net { |
| 22 | |
| 23 | class ReportingContext; |
juliatuttle | 381d77e | 2017-04-07 18:54:12 | [diff] [blame] | 24 | struct ReportingPolicy; |
| 25 | class URLRequestContext; |
| 26 | |
| 27 | // The external interface to the Reporting system, used by the embedder of //net |
| 28 | // and also other parts of //net. |
| 29 | class NET_EXPORT ReportingService { |
| 30 | public: |
| 31 | virtual ~ReportingService(); |
| 32 | |
| 33 | // Creates a ReportingService. |policy| will be copied. |request_context| must |
juliatuttle | 42c5731 | 2017-04-28 03:01:30 | [diff] [blame^] | 34 | // outlive the ReportingService. |
juliatuttle | 381d77e | 2017-04-07 18:54:12 | [diff] [blame] | 35 | static std::unique_ptr<ReportingService> Create( |
| 36 | const ReportingPolicy& policy, |
juliatuttle | 42c5731 | 2017-04-28 03:01:30 | [diff] [blame^] | 37 | URLRequestContext* request_context); |
juliatuttle | 381d77e | 2017-04-07 18:54:12 | [diff] [blame] | 38 | |
| 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_ |