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.
5 #ifndef NET_URL_REQUEST_CERTIFICATE_REPORT_SENDER_H_
6 #define NET_URL_REQUEST_CERTIFICATE_REPORT_SENDER_H_
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"
20 class URLRequestContext
;
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
{
32 // Represents whether or not to send cookies along with reports.
33 enum CookiesPreference
{ SEND_COOKIES
, DO_NOT_SEND_COOKIES
};
35 // Constructs a CertificateReportSender that sends reports with the
36 // given |request_context| and includes or excludes cookies based on
37 // |cookies_preference|. |request_context| must outlive the
38 // CertificateReportSender.
39 CertificateReportSender(URLRequestContext
* request_context
,
40 CookiesPreference cookies_preference
);
42 ~CertificateReportSender() override
;
44 // TransportSecurityState::ReportSender implementation.
45 void Send(const GURL
& report_uri
, const std::string
& report
) override
;
47 // net::URLRequest::Delegate implementation.
48 void OnResponseStarted(URLRequest
* request
) override
;
49 void OnReadCompleted(URLRequest
* request
, int bytes_read
) override
;
52 net::URLRequestContext
* const request_context_
;
54 CookiesPreference cookies_preference_
;
56 // Owns the contained requests.
57 std::set
<URLRequest
*> inflight_requests_
;
59 DISALLOW_COPY_AND_ASSIGN(CertificateReportSender
);
64 #endif // NET_URL_REQUEST_CERTIFICATE_REPORT_H_