| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef NET_URL_REQUEST_CERTIFICATE_REPORT_SENDER_H_ | 5 #ifndef NET_URL_REQUEST_CERTIFICATE_REPORT_SENDER_H_ |
| 6 #define NET_URL_REQUEST_CERTIFICATE_REPORT_SENDER_H_ | 6 #define NET_URL_REQUEST_CERTIFICATE_REPORT_SENDER_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 // CertificateReportSender asynchronously sends serialized certificate | 23 // CertificateReportSender asynchronously sends serialized certificate |
| 24 // reports to a URI. It takes serialized reports as a sequence of bytes | 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, | 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 | 26 // protobuf, etc.) and the particular data that it contains. Multiple |
| 27 // reports can be in-flight at once. This class owns inflight requests | 27 // reports can be in-flight at once. This class owns inflight requests |
| 28 // and cleans them up when necessary. | 28 // and cleans them up when necessary. |
| 29 class NET_EXPORT CertificateReportSender | 29 class NET_EXPORT CertificateReportSender |
| 30 : public URLRequest::Delegate, | 30 : public URLRequest::Delegate, |
| 31 public TransportSecurityState::ReportSender { | 31 public TransportSecurityState::ReportSender { |
| 32 public: | 32 public: |
| 33 using ErrorCallback = base::Callback<void(const GURL&, int)>; |
| 34 |
| 33 // Represents whether or not to send cookies along with reports. | 35 // Represents whether or not to send cookies along with reports. |
| 34 enum CookiesPreference { SEND_COOKIES, DO_NOT_SEND_COOKIES }; | 36 enum CookiesPreference { SEND_COOKIES, DO_NOT_SEND_COOKIES }; |
| 35 | 37 |
| 36 // Constructs a CertificateReportSender that sends reports with the | 38 // Constructs a CertificateReportSender that sends reports with the |
| 37 // given |request_context| and includes or excludes cookies based on | 39 // given |request_context| and includes or excludes cookies based on |
| 38 // |cookies_preference|. |request_context| must outlive the | 40 // |cookies_preference|. |request_context| must outlive the |
| 39 // CertificateReportSender. | 41 // CertificateReportSender. |
| 40 CertificateReportSender(URLRequestContext* request_context, | 42 CertificateReportSender(URLRequestContext* request_context, |
| 41 CookiesPreference cookies_preference); | 43 CookiesPreference cookies_preference); |
| 42 | 44 |
| 43 // Constructs a CertificateReportSender that sends reports with the | 45 // Constructs a CertificateReportSender that sends reports with the |
| 44 // given |request_context| and includes or excludes cookies based on | 46 // given |request_context| and includes or excludes cookies based on |
| 45 // |cookies_preference|. |request_context| must outlive the | 47 // |cookies_preference|. |request_context| must outlive the |
| 46 // CertificateReportSender. When sending a report results in an error, | 48 // CertificateReportSender. When sending a report results in an error, |
| 47 // |error_callback| is called with a pointer to the URLRequest as an | 49 // |error_callback| is called with the report URI and net error as |
| 48 // argument. | 50 // arguments. |
| 49 CertificateReportSender( | 51 CertificateReportSender(URLRequestContext* request_context, |
| 50 URLRequestContext* request_context, | 52 CookiesPreference cookies_preference, |
| 51 CookiesPreference cookies_preference, | 53 const ErrorCallback& error_callback); |
| 52 const base::Callback<void(URLRequest*)>& error_callback); | |
| 53 | 54 |
| 54 ~CertificateReportSender() override; | 55 ~CertificateReportSender() override; |
| 55 | 56 |
| 56 // TransportSecurityState::ReportSender implementation. | 57 // TransportSecurityState::ReportSender implementation. |
| 57 void Send(const GURL& report_uri, const std::string& report) override; | 58 void Send(const GURL& report_uri, const std::string& report) override; |
| 59 void SetErrorCallback(const ErrorCallback& error_callback) override; |
| 58 | 60 |
| 59 // net::URLRequest::Delegate implementation. | 61 // net::URLRequest::Delegate implementation. |
| 60 void OnResponseStarted(URLRequest* request) override; | 62 void OnResponseStarted(URLRequest* request) override; |
| 61 void OnReadCompleted(URLRequest* request, int bytes_read) override; | 63 void OnReadCompleted(URLRequest* request, int bytes_read) override; |
| 62 | 64 |
| 63 private: | 65 private: |
| 64 net::URLRequestContext* const request_context_; | 66 net::URLRequestContext* const request_context_; |
| 65 | 67 |
| 66 CookiesPreference cookies_preference_; | 68 CookiesPreference cookies_preference_; |
| 67 | 69 |
| 68 // Owns the contained requests. | 70 // Owns the contained requests. |
| 69 std::set<URLRequest*> inflight_requests_; | 71 std::set<URLRequest*> inflight_requests_; |
| 70 | 72 |
| 71 // Called when a sent report results in an error. | 73 // Called when a sent report results in an error. |
| 72 base::Callback<void(URLRequest* request)> error_callback_; | 74 ErrorCallback error_callback_; |
| 73 | 75 |
| 74 DISALLOW_COPY_AND_ASSIGN(CertificateReportSender); | 76 DISALLOW_COPY_AND_ASSIGN(CertificateReportSender); |
| 75 }; | 77 }; |
| 76 | 78 |
| 77 } // namespace net | 79 } // namespace net |
| 78 | 80 |
| 79 #endif // NET_URL_REQUEST_CERTIFICATE_REPORT_H_ | 81 #endif // NET_URL_REQUEST_CERTIFICATE_REPORT_H_ |
| OLD | NEW |