| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 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_URL_REQUEST_CERTIFICATE_REPORT_SENDER_H_ | |
| 6 #define NET_URL_REQUEST_CERTIFICATE_REPORT_SENDER_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 #include <set> | |
| 10 #include <string> | |
| 11 | |
| 12 #include "base/callback.h" | |
| 13 #include "base/macros.h" | |
| 14 #include "net/http/transport_security_state.h" | |
| 15 #include "net/url_request/url_request.h" | |
| 16 | |
| 17 class GURL; | |
| 18 | |
| 19 namespace net { | |
| 20 | |
| 21 class URLRequestContext; | |
| 22 | |
| 23 // CertificateReportSender asynchronously sends serialized certificate | |
| 24 // reports to a URI. It takes serialized reports as a sequence of bytes | |
| 25 // so as to be agnostic to the format of the report being sent (JSON, | |
| 26 // protobuf, etc.) and the particular data that it contains. Multiple | |
| 27 // reports can be in-flight at once. This class owns inflight requests | |
| 28 // and cleans them up when necessary. | |
| 29 class NET_EXPORT CertificateReportSender | |
| 30 : public URLRequest::Delegate, | |
| 31 public TransportSecurityState::ReportSender { | |
| 32 public: | |
| 33 using ErrorCallback = base::Callback<void(const GURL&, int)>; | |
| 34 | |
| 35 // Represents whether or not to send cookies along with reports. | |
| 36 enum CookiesPreference { SEND_COOKIES, DO_NOT_SEND_COOKIES }; | |
| 37 | |
| 38 // Constructs a CertificateReportSender that sends reports with the | |
| 39 // given |request_context| and includes or excludes cookies based on | |
| 40 // |cookies_preference|. |request_context| must outlive the | |
| 41 // CertificateReportSender. | |
| 42 CertificateReportSender(URLRequestContext* request_context, | |
| 43 CookiesPreference cookies_preference); | |
| 44 | |
| 45 // Constructs a CertificateReportSender that sends reports with the | |
| 46 // given |request_context| and includes or excludes cookies based on | |
| 47 // |cookies_preference|. |request_context| must outlive the | |
| 48 // CertificateReportSender. When sending a report results in an error, | |
| 49 // |error_callback| is called with the report URI and net error as | |
| 50 // arguments. | |
| 51 CertificateReportSender(URLRequestContext* request_context, | |
| 52 CookiesPreference cookies_preference, | |
| 53 const ErrorCallback& error_callback); | |
| 54 | |
| 55 ~CertificateReportSender() override; | |
| 56 | |
| 57 // TransportSecurityState::ReportSender implementation. | |
| 58 void Send(const GURL& report_uri, const std::string& report) override; | |
| 59 void SetErrorCallback(const ErrorCallback& error_callback) override; | |
| 60 | |
| 61 // net::URLRequest::Delegate implementation. | |
| 62 void OnResponseStarted(URLRequest* request) override; | |
| 63 void OnReadCompleted(URLRequest* request, int bytes_read) override; | |
| 64 | |
| 65 private: | |
| 66 net::URLRequestContext* const request_context_; | |
| 67 | |
| 68 CookiesPreference cookies_preference_; | |
| 69 | |
| 70 // Owns the contained requests. | |
| 71 std::set<URLRequest*> inflight_requests_; | |
| 72 | |
| 73 // Called when a sent report results in an error. | |
| 74 ErrorCallback error_callback_; | |
| 75 | |
| 76 DISALLOW_COPY_AND_ASSIGN(CertificateReportSender); | |
| 77 }; | |
| 78 | |
| 79 } // namespace net | |
| 80 | |
| 81 #endif // NET_URL_REQUEST_CERTIFICATE_REPORT_H_ | |
| OLD | NEW |