Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(571)

Unified Diff: net/url_request/certificate_report_sender.cc

Issue 1212973002: Add net::CertificateReportSender for handling cert report sending (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add missing NET_EXPORT Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/url_request/certificate_report_sender.h ('k') | net/url_request/certificate_report_sender_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/url_request/certificate_report_sender.cc
diff --git a/net/url_request/certificate_report_sender.cc b/net/url_request/certificate_report_sender.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0361a328c242241ca762bd1a1a6c1e2b4e748ebf
--- /dev/null
+++ b/net/url_request/certificate_report_sender.cc
@@ -0,0 +1,76 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/url_request/certificate_report_sender.h"
+
+#include "base/stl_util.h"
+#include "net/base/elements_upload_data_stream.h"
+#include "net/base/load_flags.h"
+#include "net/base/request_priority.h"
+#include "net/base/upload_bytes_element_reader.h"
+#include "net/url_request/url_request_context.h"
+#include "net/url_request/url_request_status.h"
+
+namespace net {
+
+CertificateReportSender::CertificateReportSender(
+ URLRequestContext* request_context,
+ CookiesPreference cookies_preference)
+ : request_context_(request_context),
+ cookies_preference_(cookies_preference) {}
+
+CertificateReportSender::~CertificateReportSender() {
+ STLDeleteElements(&inflight_requests_);
+}
+
+void CertificateReportSender::Send(const GURL& report_uri,
+ const std::string& report) {
+ scoped_ptr<URLRequest> url_request =
+ CreateURLRequest(request_context_, report_uri);
+ url_request->set_method("POST");
+
+ scoped_ptr<UploadElementReader> reader(
+ UploadOwnedBytesElementReader::CreateWithString(report));
+ url_request->set_upload(
+ ElementsUploadDataStream::CreateWithReader(reader.Pass(), 0));
+
+ URLRequest* raw_url_request = url_request.get();
+ inflight_requests_.insert(url_request.release());
+ raw_url_request->Start();
+}
+
+void CertificateReportSender::OnResponseStarted(URLRequest* request) {
+ // TODO(estark): call a callback so that the caller can print a
+ // warning on failure.
+ RequestComplete(request);
+}
+
+void CertificateReportSender::OnReadCompleted(URLRequest* request,
+ int bytes_read) {
+ NOTREACHED();
+}
+
+scoped_ptr<URLRequest> CertificateReportSender::CreateURLRequest(
+ URLRequestContext* context,
+ const GURL& report_uri) {
+ scoped_ptr<URLRequest> request =
+ context->CreateRequest(report_uri, DEFAULT_PRIORITY, this);
+ int load_flags =
+ LOAD_BYPASS_CACHE | LOAD_DISABLE_CACHE | LOAD_DO_NOT_SEND_AUTH_DATA;
+ if (cookies_preference_ != SEND_COOKIES) {
+ load_flags =
+ load_flags | LOAD_DO_NOT_SEND_COOKIES | LOAD_DO_NOT_SAVE_COOKIES;
+ }
+ request->SetLoadFlags(load_flags);
+ return request.Pass();
+}
+
+void CertificateReportSender::RequestComplete(URLRequest* request) {
+ std::set<URLRequest*>::iterator i = inflight_requests_.find(request);
+ CHECK(i != inflight_requests_.end());
+ scoped_ptr<URLRequest> url_request(*i);
+ inflight_requests_.erase(i);
+}
+
+} // namespace net
« no previous file with comments | « net/url_request/certificate_report_sender.h ('k') | net/url_request/certificate_report_sender_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698