Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / net / url_request / certificate_report_sender.cc
blob0ff637bc47227383048669bb60af87d2d4939827
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 #include "net/url_request/certificate_report_sender.h"
7 #include "base/stl_util.h"
8 #include "net/base/elements_upload_data_stream.h"
9 #include "net/base/load_flags.h"
10 #include "net/base/request_priority.h"
11 #include "net/base/upload_bytes_element_reader.h"
12 #include "net/url_request/url_request_context.h"
13 #include "net/url_request/url_request_status.h"
15 namespace net {
17 CertificateReportSender::CertificateReportSender(
18 URLRequestContext* request_context,
19 CookiesPreference cookies_preference)
20 : request_context_(request_context),
21 cookies_preference_(cookies_preference) {}
23 CertificateReportSender::~CertificateReportSender() {
24 // Cancel all of the uncompleted requests.
25 STLDeleteElements(&inflight_requests_);
28 void CertificateReportSender::Send(const GURL& report_uri,
29 const std::string& report) {
30 scoped_ptr<URLRequest> url_request =
31 request_context_->CreateRequest(report_uri, DEFAULT_PRIORITY, this);
33 int load_flags =
34 LOAD_BYPASS_CACHE | LOAD_DISABLE_CACHE | LOAD_DO_NOT_SEND_AUTH_DATA;
35 if (cookies_preference_ != SEND_COOKIES) {
36 load_flags |= LOAD_DO_NOT_SEND_COOKIES | LOAD_DO_NOT_SAVE_COOKIES;
38 url_request->SetLoadFlags(load_flags);
40 url_request->set_method("POST");
42 scoped_ptr<UploadElementReader> reader(
43 UploadOwnedBytesElementReader::CreateWithString(report));
44 url_request->set_upload(
45 ElementsUploadDataStream::CreateWithReader(reader.Pass(), 0));
47 URLRequest* raw_url_request = url_request.get();
48 inflight_requests_.insert(url_request.release());
49 raw_url_request->Start();
52 void CertificateReportSender::OnResponseStarted(URLRequest* request) {
53 // TODO(estark): call a callback so that the caller can print a
54 // warning on failure.
55 DVLOG(1) << "Failed to send certificate report for " << request->url().host();
57 CHECK_GT(inflight_requests_.erase(request), 0u);
58 // Clean up the request, which cancels it.
59 delete request;
62 void CertificateReportSender::OnReadCompleted(URLRequest* request,
63 int bytes_read) {
64 NOTREACHED();
67 } // namespace net