| 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 "base/stl_util.h" | 7 #include "base/stl_util.h" |
| 8 #include "net/base/elements_upload_data_stream.h" | 8 #include "net/base/elements_upload_data_stream.h" |
| 9 #include "net/base/load_flags.h" | 9 #include "net/base/load_flags.h" |
| 10 #include "net/base/request_priority.h" | 10 #include "net/base/request_priority.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 cookies_preference_(cookies_preference) {} | 21 cookies_preference_(cookies_preference) {} |
| 22 | 22 |
| 23 CertificateReportSender::~CertificateReportSender() { | 23 CertificateReportSender::~CertificateReportSender() { |
| 24 // Cancel all of the uncompleted requests. | 24 // Cancel all of the uncompleted requests. |
| 25 STLDeleteElements(&inflight_requests_); | 25 STLDeleteElements(&inflight_requests_); |
| 26 } | 26 } |
| 27 | 27 |
| 28 void CertificateReportSender::Send(const GURL& report_uri, | 28 void CertificateReportSender::Send(const GURL& report_uri, |
| 29 const std::string& report) { | 29 const std::string& report) { |
| 30 scoped_ptr<URLRequest> url_request = | 30 scoped_ptr<URLRequest> url_request = |
| 31 CreateURLRequest(request_context_, report_uri); | 31 request_context_->CreateRequest(report_uri, DEFAULT_PRIORITY, this); |
| 32 |
| 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; |
| 37 } |
| 38 url_request->SetLoadFlags(load_flags); |
| 39 |
| 32 url_request->set_method("POST"); | 40 url_request->set_method("POST"); |
| 33 | 41 |
| 34 scoped_ptr<UploadElementReader> reader( | 42 scoped_ptr<UploadElementReader> reader( |
| 35 UploadOwnedBytesElementReader::CreateWithString(report)); | 43 UploadOwnedBytesElementReader::CreateWithString(report)); |
| 36 url_request->set_upload( | 44 url_request->set_upload( |
| 37 ElementsUploadDataStream::CreateWithReader(reader.Pass(), 0)); | 45 ElementsUploadDataStream::CreateWithReader(reader.Pass(), 0)); |
| 38 | 46 |
| 39 URLRequest* raw_url_request = url_request.get(); | 47 URLRequest* raw_url_request = url_request.get(); |
| 40 inflight_requests_.insert(url_request.release()); | 48 inflight_requests_.insert(url_request.release()); |
| 41 raw_url_request->Start(); | 49 raw_url_request->Start(); |
| 42 } | 50 } |
| 43 | 51 |
| 44 void CertificateReportSender::OnResponseStarted(URLRequest* request) { | 52 void CertificateReportSender::OnResponseStarted(URLRequest* request) { |
| 45 // TODO(estark): call a callback so that the caller can print a | 53 // TODO(estark): call a callback so that the caller can print a |
| 46 // warning on failure. | 54 // warning on failure. |
| 47 DVLOG(1) << "Failed to send certificate report for " << request->url().host(); | 55 DVLOG(1) << "Failed to send certificate report for " << request->url().host(); |
| 48 | 56 |
| 49 CHECK_GT(inflight_requests_.erase(request), 0u); | 57 CHECK_GT(inflight_requests_.erase(request), 0u); |
| 50 // Clean up the request, which cancels it. | 58 // Clean up the request, which cancels it. |
| 51 delete request; | 59 delete request; |
| 52 } | 60 } |
| 53 | 61 |
| 54 void CertificateReportSender::OnReadCompleted(URLRequest* request, | 62 void CertificateReportSender::OnReadCompleted(URLRequest* request, |
| 55 int bytes_read) { | 63 int bytes_read) { |
| 56 NOTREACHED(); | 64 NOTREACHED(); |
| 57 } | 65 } |
| 58 | 66 |
| 59 scoped_ptr<URLRequest> CertificateReportSender::CreateURLRequest( | |
| 60 URLRequestContext* context, | |
| 61 const GURL& report_uri) { | |
| 62 scoped_ptr<URLRequest> request = | |
| 63 context->CreateRequest(report_uri, DEFAULT_PRIORITY, this); | |
| 64 int load_flags = | |
| 65 LOAD_BYPASS_CACHE | LOAD_DISABLE_CACHE | LOAD_DO_NOT_SEND_AUTH_DATA; | |
| 66 if (cookies_preference_ != SEND_COOKIES) { | |
| 67 load_flags = | |
| 68 load_flags | LOAD_DO_NOT_SEND_COOKIES | LOAD_DO_NOT_SAVE_COOKIES; | |
| 69 } | |
| 70 request->SetLoadFlags(load_flags); | |
| 71 return request.Pass(); | |
| 72 } | |
| 73 | |
| 74 } // namespace net | 67 } // namespace net |
| OLD | NEW |