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. | |
|
Ryan Sleevi
2015/06/26 20:03:46
// warning
estark
2015/07/07 21:59:28
Done.
| |
| 47 RequestComplete(request); | |
| 48 } | |
| 49 | |
| 50 void CertificateReportSenderImpl::OnReadCompleted(URLRequest* request, | |
| 51 int bytes_read) { | |
| 52 } | |
| 53 | |
| 54 scoped_ptr<URLRequest> CertificateReportSenderImpl::CreateURLRequest( | |
| 55 URLRequestContext* context, | |
| 56 const GURL& report_uri) { | |
| 57 scoped_ptr<URLRequest> request = | |
| 58 context->CreateRequest(report_uri, DEFAULT_PRIORITY, this); | |
| 59 if (cookies_preference_ != SEND_COOKIES) | |
| 60 request->SetLoadFlags(LOAD_DO_NOT_SEND_COOKIES | LOAD_DO_NOT_SAVE_COOKIES); | |
|
Ryan Sleevi
2015/06/26 20:03:46
DESIGN: Look through the other load flags to figur
estark
2015/07/07 21:59:28
I've changed it to be consistent with what other b
| |
| 61 return request.Pass(); | |
| 62 } | |
| 63 | |
| 64 void CertificateReportSenderImpl::RequestComplete(URLRequest* request) { | |
| 65 std::set<URLRequest*>::iterator i = inflight_requests_.find(request); | |
| 66 DCHECK(i != inflight_requests_.end()); | |
|
Ryan Sleevi
2015/06/26 20:03:46
Should this be a CHECK()? I can't recall what evil
estark
2015/07/07 21:59:28
Dereferencing end() is undefined behavior, so I su
| |
| 67 scoped_ptr<URLRequest> url_request(*i); | |
| 68 inflight_requests_.erase(i); | |
| 69 } | |
| 70 | |
| 71 } // namespace net | |
| OLD | NEW |