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