Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "net/http/certificate_report_sender_impl.h" | |
| 6 | |
| 7 #include "base/stl_util.h" | |
| 8 #include "net/base/elements_upload_data_stream.h" | |
| 9 #include "net/base/load_flags.h" | |
| 10 #include "net/base/request_priority.h" | |
| 11 #include "net/base/upload_bytes_element_reader.h" | |
| 12 #include "net/url_request/url_request_context.h" | |
| 13 #include "net/url_request/url_request_status.h" | |
| 14 | |
| 15 namespace net { | |
| 16 | |
| 17 CertificateReportSenderImpl::CertificateReportSenderImpl( | |
| 18 URLRequestContext* request_context, | |
| 19 CookiesPreference cookies_preference) | |
| 20 : request_context_(request_context), | |
| 21 cookies_preference_(cookies_preference) { | |
| 22 } | |
| 23 | |
| 24 CertificateReportSenderImpl::~CertificateReportSenderImpl() { | |
| 25 STLDeleteElements(&inflight_requests_); | |
| 26 } | |
| 27 | |
| 28 void CertificateReportSenderImpl::Send(const GURL& report_uri, | |
| 29 const std::string& report) { | |
| 30 scoped_ptr<URLRequest> url_request = | |
| 31 CreateURLRequest(request_context_, report_uri); | |
| 32 url_request->set_method("POST"); | |
| 33 | |
| 34 scoped_ptr<UploadElementReader> reader( | |
| 35 UploadOwnedBytesElementReader::CreateWithString(report)); | |
| 36 url_request->set_upload( | |
| 37 ElementsUploadDataStream::CreateWithReader(reader.Pass(), 0)); | |
| 38 | |
| 39 URLRequest* raw_url_request = url_request.get(); | |
| 40 inflight_requests_.insert(url_request.release()); | |
| 41 raw_url_request->Start(); | |
| 42 } | |
| 43 | |
| 44 void CertificateReportSenderImpl::OnResponseStarted(URLRequest* request) { | |
| 45 // TODO(estark): call a callback so that the caller can print a | |
| 46 // warning on failure. | |
| 47 RequestComplete(request); | |
| 48 } | |
| 49 | |
| 50 void CertificateReportSenderImpl::OnReadCompleted(URLRequest* request, | |
| 51 int bytes_read) { | |
|
davidben
2015/07/23 00:09:42
Optional: Since you don't call Read, perhaps a NOT
estark
2015/07/23 02:41:21
Done.
| |
| 52 } | |
| 53 | |
| 54 scoped_ptr<URLRequest> CertificateReportSenderImpl::CreateURLRequest( | |
| 55 URLRequestContext* context, | |
| 56 const GURL& report_uri) { | |
|
davidben
2015/07/23 00:09:42
Optional: You probably can just inline this method
estark
2015/07/23 02:41:21
Tests for ChromeFraudulentCertificateReporter over
davidben
2015/07/24 18:54:11
Ah sorry, I'd missed that.
| |
| 57 scoped_ptr<URLRequest> request = | |
| 58 context->CreateRequest(report_uri, DEFAULT_PRIORITY, this); | |
| 59 int load_flags = | |
| 60 LOAD_BYPASS_CACHE | LOAD_DISABLE_CACHE | LOAD_DO_NOT_SEND_AUTH_DATA; | |
| 61 if (cookies_preference_ != SEND_COOKIES) | |
|
davidben
2015/07/23 00:09:41
Nit: The body is more than one line, so I'd put th
estark
2015/07/23 02:41:21
Done.
| |
| 62 load_flags = | |
| 63 load_flags | LOAD_DO_NOT_SEND_COOKIES | LOAD_DO_NOT_SAVE_COOKIES; | |
| 64 request->SetLoadFlags(load_flags); | |
| 65 return request.Pass(); | |
| 66 } | |
| 67 | |
| 68 void CertificateReportSenderImpl::RequestComplete(URLRequest* request) { | |
| 69 std::set<URLRequest*>::iterator i = inflight_requests_.find(request); | |
| 70 CHECK(i != inflight_requests_.end()); | |
| 71 scoped_ptr<URLRequest> url_request(*i); | |
| 72 inflight_requests_.erase(i); | |
| 73 } | |
| 74 | |
| 75 } // namespace net | |
| OLD | NEW |