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

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: add missing NET_EXPORT Created 5 years, 4 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 CertificateReportSender::~CertificateReportSender() {
24 STLDeleteElements(&inflight_requests_);
25 }
26
27 void CertificateReportSender::Send(const GURL& report_uri,
28 const std::string& report) {
29 scoped_ptr<URLRequest> url_request =
30 CreateURLRequest(request_context_, report_uri);
31 url_request->set_method("POST");
32
33 scoped_ptr<UploadElementReader> reader(
34 UploadOwnedBytesElementReader::CreateWithString(report));
35 url_request->set_upload(
36 ElementsUploadDataStream::CreateWithReader(reader.Pass(), 0));
37
38 URLRequest* raw_url_request = url_request.get();
39 inflight_requests_.insert(url_request.release());
40 raw_url_request->Start();
41 }
42
43 void CertificateReportSender::OnResponseStarted(URLRequest* request) {
44 // TODO(estark): call a callback so that the caller can print a
45 // warning on failure.
46 RequestComplete(request);
47 }
48
49 void CertificateReportSender::OnReadCompleted(URLRequest* request,
50 int bytes_read) {
51 NOTREACHED();
52 }
53
54 scoped_ptr<URLRequest> CertificateReportSender::CreateURLRequest(
55 URLRequestContext* context,
56 const GURL& report_uri) {
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) {
62 load_flags =
63 load_flags | LOAD_DO_NOT_SEND_COOKIES | LOAD_DO_NOT_SAVE_COOKIES;
64 }
65 request->SetLoadFlags(load_flags);
66 return request.Pass();
67 }
68
69 void CertificateReportSender::RequestComplete(URLRequest* request) {
70 std::set<URLRequest*>::iterator i = inflight_requests_.find(request);
71 CHECK(i != inflight_requests_.end());
72 scoped_ptr<URLRequest> url_request(*i);
73 inflight_requests_.erase(i);
74 }
75
76 } // namespace net
OLDNEW
« 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