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|. Ownership of |request_context| is not
38 // transferred, so it must outlive the CertificateReportSender.
39 CertificateReportSender(URLRequestContext
* request_context
,
40 CookiesPreference cookies_preference
);
42 ~CertificateReportSender() override
;
44 // TransportSecurityState::ReportSender
45 void Send(const GURL
& report_uri
, const std::string
& report
) override
;
47 // net::URLRequest::Delegate
48 void OnResponseStarted(URLRequest
* request
) override
;
49 void OnReadCompleted(URLRequest
* request
, int bytes_read
) override
;
52 // Creates a URLRequest with which to send a certificate report to the
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
);
61 // Performs post-report cleanup.
62 void RequestComplete(net::URLRequest
* request
);
64 net::URLRequestContext
* const request_context_
;
66 CookiesPreference cookies_preference_
;
68 // Owns the contained requests.
69 std::set
<URLRequest
*> inflight_requests_
;
71 DISALLOW_COPY_AND_ASSIGN(CertificateReportSender
);
76 #endif // NET_URL_REQUEST_CERTIFICATE_REPORT_H_