| 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 #include "net/url_request/certificate_report_sender.h" | 5 #include "net/url_request/certificate_report_sender.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "net/base/elements_upload_data_stream.h" | 10 #include "net/base/elements_upload_data_stream.h" |
| 11 #include "net/base/load_flags.h" | 11 #include "net/base/load_flags.h" |
| 12 #include "net/base/request_priority.h" | 12 #include "net/base/request_priority.h" |
| 13 #include "net/base/upload_bytes_element_reader.h" | 13 #include "net/base/upload_bytes_element_reader.h" |
| 14 #include "net/url_request/url_request_context.h" | 14 #include "net/url_request/url_request_context.h" |
| 15 #include "net/url_request/url_request_status.h" | 15 #include "net/url_request/url_request_status.h" |
| 16 | 16 |
| 17 namespace net { | 17 namespace net { |
| 18 | 18 |
| 19 CertificateReportSender::CertificateReportSender( | 19 CertificateReportSender::CertificateReportSender( |
| 20 URLRequestContext* request_context, | 20 URLRequestContext* request_context, |
| 21 CookiesPreference cookies_preference) | 21 CookiesPreference cookies_preference) |
| 22 : CertificateReportSender(request_context, |
| 23 cookies_preference, |
| 24 base::Callback<void(URLRequest*)>()) {} |
| 25 |
| 26 CertificateReportSender::CertificateReportSender( |
| 27 URLRequestContext* request_context, |
| 28 CookiesPreference cookies_preference, |
| 29 const base::Callback<void(URLRequest*)>& error_callback) |
| 22 : request_context_(request_context), | 30 : request_context_(request_context), |
| 23 cookies_preference_(cookies_preference) {} | 31 cookies_preference_(cookies_preference), |
| 32 error_callback_(error_callback) {} |
| 24 | 33 |
| 25 CertificateReportSender::~CertificateReportSender() { | 34 CertificateReportSender::~CertificateReportSender() { |
| 26 // Cancel all of the uncompleted requests. | 35 // Cancel all of the uncompleted requests. |
| 27 STLDeleteElements(&inflight_requests_); | 36 STLDeleteElements(&inflight_requests_); |
| 28 } | 37 } |
| 29 | 38 |
| 30 void CertificateReportSender::Send(const GURL& report_uri, | 39 void CertificateReportSender::Send(const GURL& report_uri, |
| 31 const std::string& report) { | 40 const std::string& report) { |
| 32 scoped_ptr<URLRequest> url_request = | 41 scoped_ptr<URLRequest> url_request = |
| 33 request_context_->CreateRequest(report_uri, DEFAULT_PRIORITY, this); | 42 request_context_->CreateRequest(report_uri, DEFAULT_PRIORITY, this); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 45 UploadOwnedBytesElementReader::CreateWithString(report)); | 54 UploadOwnedBytesElementReader::CreateWithString(report)); |
| 46 url_request->set_upload( | 55 url_request->set_upload( |
| 47 ElementsUploadDataStream::CreateWithReader(std::move(reader), 0)); | 56 ElementsUploadDataStream::CreateWithReader(std::move(reader), 0)); |
| 48 | 57 |
| 49 URLRequest* raw_url_request = url_request.get(); | 58 URLRequest* raw_url_request = url_request.get(); |
| 50 inflight_requests_.insert(url_request.release()); | 59 inflight_requests_.insert(url_request.release()); |
| 51 raw_url_request->Start(); | 60 raw_url_request->Start(); |
| 52 } | 61 } |
| 53 | 62 |
| 54 void CertificateReportSender::OnResponseStarted(URLRequest* request) { | 63 void CertificateReportSender::OnResponseStarted(URLRequest* request) { |
| 55 // TODO(estark): call a callback so that the caller can print a | 64 if (!request->status().is_success()) { |
| 56 // warning on failure. | 65 DVLOG(1) << "Failed to send certificate report for " |
| 57 DVLOG(1) << "Failed to send certificate report for " << request->url().host(); | 66 << request->url().host(); |
| 67 if (!error_callback_.is_null()) |
| 68 error_callback_.Run(request); |
| 69 } |
| 58 | 70 |
| 59 CHECK_GT(inflight_requests_.erase(request), 0u); | 71 CHECK_GT(inflight_requests_.erase(request), 0u); |
| 60 // Clean up the request, which cancels it. | 72 // Clean up the request, which cancels it. |
| 61 delete request; | 73 delete request; |
| 62 } | 74 } |
| 63 | 75 |
| 64 void CertificateReportSender::OnReadCompleted(URLRequest* request, | 76 void CertificateReportSender::OnReadCompleted(URLRequest* request, |
| 65 int bytes_read) { | 77 int bytes_read) { |
| 66 NOTREACHED(); | 78 NOTREACHED(); |
| 67 } | 79 } |
| 68 | 80 |
| 69 } // namespace net | 81 } // namespace net |
| OLD | NEW |