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; |
bnc | d479b3c | 2017-05-24 18:54:53 | [diff] [blame] | 19 | } // namespace base |
juliatuttle | 381d77e | 2017-04-07 18:54:12 | [diff] [blame] | 20 | |
| 21 | namespace net { |
| 22 | |
| 23 | class ReportingContext; |
juliatuttle | 381d77e | 2017-04-07 18:54:12 | [diff] [blame] | 24 | struct ReportingPolicy; |
Julia Tuttle | 4667c1c | 2017-12-19 18:27:38 | [diff] [blame] | 25 | class URLRequest; |
juliatuttle | 381d77e | 2017-04-07 18:54:12 | [diff] [blame] | 26 | class URLRequestContext; |
| 27 | |
| 28 | // The external interface to the Reporting system, used by the embedder of //net |
| 29 | // and also other parts of //net. |
| 30 | class NET_EXPORT ReportingService { |
| 31 | public: |
| 32 | virtual ~ReportingService(); |
| 33 | |
| 34 | // Creates a ReportingService. |policy| will be copied. |request_context| must |
juliatuttle | 42c5731 | 2017-04-28 03:01:30 | [diff] [blame] | 35 | // outlive the ReportingService. |
juliatuttle | 381d77e | 2017-04-07 18:54:12 | [diff] [blame] | 36 | static std::unique_ptr<ReportingService> Create( |
| 37 | const ReportingPolicy& policy, |
juliatuttle | 42c5731 | 2017-04-28 03:01:30 | [diff] [blame] | 38 | URLRequestContext* request_context); |
juliatuttle | 381d77e | 2017-04-07 18:54:12 | [diff] [blame] | 39 | |
| 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 | |
juliatuttle | aeb1abc | 2017-05-04 21:14:38 | [diff] [blame] | 63 | // Removes browsing data from the Reporting system. See |
| 64 | // ReportingBrowsingDataRemover for more details. |
| 65 | virtual void RemoveBrowsingData( |
| 66 | int data_type_mask, |
Julia Tuttle | 227a6ff | 2017-12-19 19:44:24 | [diff] [blame] | 67 | const base::RepeatingCallback<bool(const GURL&)>& origin_filter) = 0; |
juliatuttle | aeb1abc | 2017-05-04 21:14:38 | [diff] [blame] | 68 | |
Julia Tuttle | 4667c1c | 2017-12-19 18:27:38 | [diff] [blame] | 69 | // 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 | |
juliatuttle | 381d77e | 2017-04-07 18:54:12 | [diff] [blame] | 73 | 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_ |