| 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, | 22 : CertificateReportSender(request_context, |
| 23 cookies_preference, | 23 cookies_preference, |
| 24 base::Callback<void(URLRequest*)>()) {} | 24 ErrorCallback()) {} |
| 25 | 25 |
| 26 CertificateReportSender::CertificateReportSender( | 26 CertificateReportSender::CertificateReportSender( |
| 27 URLRequestContext* request_context, | 27 URLRequestContext* request_context, |
| 28 CookiesPreference cookies_preference, | 28 CookiesPreference cookies_preference, |
| 29 const base::Callback<void(URLRequest*)>& error_callback) | 29 const ErrorCallback& error_callback) |
| 30 : request_context_(request_context), | 30 : request_context_(request_context), |
| 31 cookies_preference_(cookies_preference), | 31 cookies_preference_(cookies_preference), |
| 32 error_callback_(error_callback) {} | 32 error_callback_(error_callback) {} |
| 33 | 33 |
| 34 CertificateReportSender::~CertificateReportSender() { | 34 CertificateReportSender::~CertificateReportSender() { |
| 35 // Cancel all of the uncompleted requests. | 35 // Cancel all of the uncompleted requests. |
| 36 STLDeleteElements(&inflight_requests_); | 36 STLDeleteElements(&inflight_requests_); |
| 37 } | 37 } |
| 38 | 38 |
| 39 void CertificateReportSender::Send(const GURL& report_uri, | 39 void CertificateReportSender::Send(const GURL& report_uri, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 53 scoped_ptr<UploadElementReader> reader( | 53 scoped_ptr<UploadElementReader> reader( |
| 54 UploadOwnedBytesElementReader::CreateWithString(report)); | 54 UploadOwnedBytesElementReader::CreateWithString(report)); |
| 55 url_request->set_upload( | 55 url_request->set_upload( |
| 56 ElementsUploadDataStream::CreateWithReader(std::move(reader), 0)); | 56 ElementsUploadDataStream::CreateWithReader(std::move(reader), 0)); |
| 57 | 57 |
| 58 URLRequest* raw_url_request = url_request.get(); | 58 URLRequest* raw_url_request = url_request.get(); |
| 59 inflight_requests_.insert(url_request.release()); | 59 inflight_requests_.insert(url_request.release()); |
| 60 raw_url_request->Start(); | 60 raw_url_request->Start(); |
| 61 } | 61 } |
| 62 | 62 |
| 63 void CertificateReportSender::SetErrorCallback( |
| 64 const ErrorCallback& error_callback) { |
| 65 error_callback_ = error_callback; |
| 66 } |
| 67 |
| 63 void CertificateReportSender::OnResponseStarted(URLRequest* request) { | 68 void CertificateReportSender::OnResponseStarted(URLRequest* request) { |
| 64 if (!request->status().is_success()) { | 69 if (!request->status().is_success()) { |
| 65 DVLOG(1) << "Failed to send certificate report for " | 70 DVLOG(1) << "Failed to send certificate report for " |
| 66 << request->url().host(); | 71 << request->url().host(); |
| 67 if (!error_callback_.is_null()) | 72 if (!error_callback_.is_null()) |
| 68 error_callback_.Run(request); | 73 error_callback_.Run(request->url(), request->status().error()); |
| 69 } | 74 } |
| 70 | 75 |
| 71 CHECK_GT(inflight_requests_.erase(request), 0u); | 76 CHECK_GT(inflight_requests_.erase(request), 0u); |
| 72 // Clean up the request, which cancels it. | 77 // Clean up the request, which cancels it. |
| 73 delete request; | 78 delete request; |
| 74 } | 79 } |
| 75 | 80 |
| 76 void CertificateReportSender::OnReadCompleted(URLRequest* request, | 81 void CertificateReportSender::OnReadCompleted(URLRequest* request, |
| 77 int bytes_read) { | 82 int bytes_read) { |
| 78 NOTREACHED(); | 83 NOTREACHED(); |
| 79 } | 84 } |
| 80 | 85 |
| 81 } // namespace net | 86 } // namespace net |
| OLD | NEW |