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