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