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" |
Lily Chen | 731a95c | 2019-05-06 22:27:22 | [diff] [blame] | 14 | #include "net/reporting/reporting_cache.h" |
juliatuttle | 381d77e | 2017-04-07 18:54:12 | [diff] [blame] | 15 | |
| 16 | class GURL; |
| 17 | |
| 18 | namespace base { |
| 19 | class Value; |
bnc | d479b3c | 2017-05-24 18:54:53 | [diff] [blame] | 20 | } // namespace base |
juliatuttle | 381d77e | 2017-04-07 18:54:12 | [diff] [blame] | 21 | |
| 22 | namespace net { |
| 23 | |
| 24 | class ReportingContext; |
juliatuttle | 381d77e | 2017-04-07 18:54:12 | [diff] [blame] | 25 | struct ReportingPolicy; |
| 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 |
Lily Chen | 731a95c | 2019-05-06 22:27:22 | [diff] [blame] | 35 | // outlive the ReportingService. |store| must outlive the ReportingService. |
| 36 | // If |store| is null, the ReportingCache will be in-memory only. |
juliatuttle | 381d77e | 2017-04-07 18:54:12 | [diff] [blame] | 37 | static std::unique_ptr<ReportingService> Create( |
| 38 | const ReportingPolicy& policy, |
Lily Chen | 731a95c | 2019-05-06 22:27:22 | [diff] [blame] | 39 | URLRequestContext* request_context, |
| 40 | ReportingCache::PersistentReportingStore* store); |
juliatuttle | 381d77e | 2017-04-07 18:54:12 | [diff] [blame] | 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. |
Douglas Creager | f6cb49f7 | 2018-07-19 20:14:53 | [diff] [blame] | 50 | // |user_agent| is the User-Agent header that was used for the request. |
juliatuttle | 381d77e | 2017-04-07 18:54:12 | [diff] [blame] | 51 | // |group| is the endpoint group to which the report should be delivered. |
| 52 | // |type| is the type of the report. |body| is the body of the report. |
| 53 | // |
| 54 | // The Reporting system will take ownership of |body|; all other parameters |
| 55 | // will be copied. |
| 56 | virtual void QueueReport(const GURL& url, |
Douglas Creager | f6cb49f7 | 2018-07-19 20:14:53 | [diff] [blame] | 57 | const std::string& user_agent, |
juliatuttle | 381d77e | 2017-04-07 18:54:12 | [diff] [blame] | 58 | const std::string& group, |
| 59 | const std::string& type, |
Julia Tuttle | 107e3067 | 2018-03-29 18:48:42 | [diff] [blame] | 60 | std::unique_ptr<const base::Value> body, |
| 61 | int depth) = 0; |
juliatuttle | 381d77e | 2017-04-07 18:54:12 | [diff] [blame] | 62 | |
| 63 | // Processes a Report-To header. |url| is the URL that originated the header; |
| 64 | // |header_value| is the normalized value of the Report-To header. |
| 65 | virtual void ProcessHeader(const GURL& url, |
| 66 | const std::string& header_value) = 0; |
| 67 | |
juliatuttle | aeb1abc | 2017-05-04 21:14:38 | [diff] [blame] | 68 | // Removes browsing data from the Reporting system. See |
| 69 | // ReportingBrowsingDataRemover for more details. |
| 70 | virtual void RemoveBrowsingData( |
| 71 | int data_type_mask, |
Julia Tuttle | 227a6ff | 2017-12-19 19:44:24 | [diff] [blame] | 72 | const base::RepeatingCallback<bool(const GURL&)>& origin_filter) = 0; |
juliatuttle | aeb1abc | 2017-05-04 21:14:38 | [diff] [blame] | 73 | |
Eric Orth | b812a44 | 2018-05-04 20:26:48 | [diff] [blame] | 74 | // Like RemoveBrowsingData except removes data for all origins without a |
| 75 | // filter. |
| 76 | virtual void RemoveAllBrowsingData(int data_type_mask) = 0; |
| 77 | |
Lily Chen | 91b51e6 | 2019-03-01 16:46:07 | [diff] [blame] | 78 | // Shuts down the Reporting service so that no new headers or reports are |
| 79 | // processed, and pending uploads are cancelled. |
| 80 | virtual void OnShutdown() = 0; |
| 81 | |
Julia Tuttle | 91a655d | 2018-01-26 18:03:03 | [diff] [blame] | 82 | virtual const ReportingPolicy& GetPolicy() const = 0; |
| 83 | |
Douglas Creager | 853b209 | 2018-04-13 23:03:27 | [diff] [blame] | 84 | virtual base::Value StatusAsValue() const; |
| 85 | |
Lily Chen | 91b51e6 | 2019-03-01 16:46:07 | [diff] [blame] | 86 | virtual ReportingContext* GetContextForTesting() const = 0; |
| 87 | |
juliatuttle | 381d77e | 2017-04-07 18:54:12 | [diff] [blame] | 88 | protected: |
| 89 | ReportingService() {} |
| 90 | |
| 91 | private: |
| 92 | DISALLOW_COPY_AND_ASSIGN(ReportingService); |
| 93 | }; |
| 94 | |
| 95 | } // namespace net |
| 96 | |
| 97 | #endif // NET_REPORTING_REPORTING_SERVICE_H_ |