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 "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 = | |
|
agl
2015/08/07 23:10:01
this can use the |= operator.
estark
2015/08/10 05:34:26
Done.
| |
| 37 load_flags | LOAD_DO_NOT_SEND_COOKIES | LOAD_DO_NOT_SAVE_COOKIES; | |
| 38 } | |
| 39 url_request->SetLoadFlags(load_flags); | |
| 40 | |
| 32 url_request->set_method("POST"); | 41 url_request->set_method("POST"); |
| 33 | 42 |
| 34 scoped_ptr<UploadElementReader> reader( | 43 scoped_ptr<UploadElementReader> reader( |
| 35 UploadOwnedBytesElementReader::CreateWithString(report)); | 44 UploadOwnedBytesElementReader::CreateWithString(report)); |
| 36 url_request->set_upload( | 45 url_request->set_upload( |
| 37 ElementsUploadDataStream::CreateWithReader(reader.Pass(), 0)); | 46 ElementsUploadDataStream::CreateWithReader(reader.Pass(), 0)); |
| 38 | 47 |
| 39 URLRequest* raw_url_request = url_request.get(); | 48 URLRequest* raw_url_request = url_request.get(); |
| 40 inflight_requests_.insert(url_request.release()); | 49 inflight_requests_.insert(url_request.release()); |
| 41 raw_url_request->Start(); | 50 raw_url_request->Start(); |
| 42 } | 51 } |
| 43 | 52 |
| 44 void CertificateReportSender::OnResponseStarted(URLRequest* request) { | 53 void CertificateReportSender::OnResponseStarted(URLRequest* request) { |
| 45 // TODO(estark): call a callback so that the caller can print a | 54 // TODO(estark): call a callback so that the caller can print a |
| 46 // warning on failure. | 55 // warning on failure. |
| 47 DVLOG(1) << "Failed to send certificate report for " << request->url().host(); | 56 DVLOG(1) << "Failed to send certificate report for " << request->url().host(); |
| 48 | 57 |
| 49 CHECK_GT(inflight_requests_.erase(request), 0u); | 58 CHECK_GT(inflight_requests_.erase(request), 0u); |
| 50 // Clean up the request, which cancels it. | 59 // Clean up the request, which cancels it. |
| 51 delete request; | 60 delete request; |
| 52 } | 61 } |
| 53 | 62 |
| 54 void CertificateReportSender::OnReadCompleted(URLRequest* request, | 63 void CertificateReportSender::OnReadCompleted(URLRequest* request, |
| 55 int bytes_read) { | 64 int bytes_read) { |
| 56 NOTREACHED(); | 65 NOTREACHED(); |
| 57 } | 66 } |
| 58 | 67 |
| 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 | 68 } // namespace net |
| OLD | NEW |