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

Side by Side 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: pare down reporter interface to just Send() 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 unified diff | Download patch
OLDNEW
(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/url_request/certificate_report_sender.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 CertificateReportSender::CertificateReportSender(
18 URLRequestContext* request_context,
19 CookiesPreference cookies_preference)
20 : request_context_(request_context),
21 cookies_preference_(cookies_preference) {
22 }
23
24 CertificateReportSender::~CertificateReportSender() {
25 STLDeleteElements(&inflight_requests_);
26 }
27
28 void CertificateReportSender::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 CertificateReportSender::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 CertificateReportSender::OnReadCompleted(URLRequest* request,
51 int bytes_read) {
52 NOTREACHED();
53 }
54
55 scoped_ptr<URLRequest> CertificateReportSender::CreateURLRequest(
56 URLRequestContext* context,
57 const GURL& report_uri) {
58 scoped_ptr<URLRequest> request =
59 context->CreateRequest(report_uri, DEFAULT_PRIORITY, this);
60 int load_flags =
61 LOAD_BYPASS_CACHE | LOAD_DISABLE_CACHE | LOAD_DO_NOT_SEND_AUTH_DATA;
62 if (cookies_preference_ != SEND_COOKIES) {
63 load_flags =
64 load_flags | LOAD_DO_NOT_SEND_COOKIES | LOAD_DO_NOT_SAVE_COOKIES;
65 }
66 request->SetLoadFlags(load_flags);
67 return request.Pass();
68 }
69
70 void CertificateReportSender::RequestComplete(URLRequest* request) {
71 std::set<URLRequest*>::iterator i = inflight_requests_.find(request);
72 CHECK(i != inflight_requests_.end());
73 scoped_ptr<URLRequest> url_request(*i);
74 inflight_requests_.erase(i);
75 }
76
77 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698