| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ssl/chrome_expect_ct_reporter.h" | 5 #include "chrome/browser/ssl/chrome_expect_ct_reporter.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/feature_list.h" | 11 #include "base/feature_list.h" |
| 12 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
| 15 #include "base/metrics/sparse_histogram.h" | 15 #include "base/metrics/sparse_histogram.h" |
| 16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 18 #include "base/values.h" | 18 #include "base/values.h" |
| 19 #include "chrome/common/chrome_features.h" | 19 #include "chrome/common/chrome_features.h" |
| 20 #include "net/url_request/certificate_report_sender.h" | 20 #include "net/url_request/report_sender.h" |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 std::string TimeToISO8601(const base::Time& t) { | 24 std::string TimeToISO8601(const base::Time& t) { |
| 25 base::Time::Exploded exploded; | 25 base::Time::Exploded exploded; |
| 26 t.UTCExplode(&exploded); | 26 t.UTCExplode(&exploded); |
| 27 return base::StringPrintf( | 27 return base::StringPrintf( |
| 28 "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", exploded.year, exploded.month, | 28 "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", exploded.year, exploded.month, |
| 29 exploded.day_of_month, exploded.hour, exploded.minute, exploded.second, | 29 exploded.day_of_month, exploded.hour, exploded.minute, exploded.second, |
| 30 exploded.millisecond); | 30 exploded.millisecond); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 // Records an UMA histogram of the net errors when Expect CT reports | 107 // Records an UMA histogram of the net errors when Expect CT reports |
| 108 // fails to send. | 108 // fails to send. |
| 109 void RecordUMAOnFailure(const GURL& report_uri, int net_error) { | 109 void RecordUMAOnFailure(const GURL& report_uri, int net_error) { |
| 110 UMA_HISTOGRAM_SPARSE_SLOWLY("SSL.ExpectCTReportFailure", net_error); | 110 UMA_HISTOGRAM_SPARSE_SLOWLY("SSL.ExpectCTReportFailure", net_error); |
| 111 } | 111 } |
| 112 | 112 |
| 113 } // namespace | 113 } // namespace |
| 114 | 114 |
| 115 ChromeExpectCTReporter::ChromeExpectCTReporter( | 115 ChromeExpectCTReporter::ChromeExpectCTReporter( |
| 116 net::URLRequestContext* request_context) | 116 net::URLRequestContext* request_context) |
| 117 : report_sender_(new net::CertificateReportSender( | 117 : report_sender_( |
| 118 request_context, | 118 new net::ReportSender(request_context, |
| 119 net::CertificateReportSender::DO_NOT_SEND_COOKIES, | 119 net::ReportSender::DO_NOT_SEND_COOKIES, |
| 120 base::Bind(RecordUMAOnFailure))) {} | 120 base::Bind(RecordUMAOnFailure))) {} |
| 121 | 121 |
| 122 ChromeExpectCTReporter::~ChromeExpectCTReporter() {} | 122 ChromeExpectCTReporter::~ChromeExpectCTReporter() {} |
| 123 | 123 |
| 124 void ChromeExpectCTReporter::OnExpectCTFailed( | 124 void ChromeExpectCTReporter::OnExpectCTFailed( |
| 125 const net::HostPortPair& host_port_pair, | 125 const net::HostPortPair& host_port_pair, |
| 126 const GURL& report_uri, | 126 const GURL& report_uri, |
| 127 const net::SSLInfo& ssl_info) { | 127 const net::SSLInfo& ssl_info) { |
| 128 if (report_uri.is_empty()) | 128 if (report_uri.is_empty()) |
| 129 return; | 129 return; |
| 130 | 130 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 std::string serialized_report; | 170 std::string serialized_report; |
| 171 if (!base::JSONWriter::Write(report, &serialized_report)) { | 171 if (!base::JSONWriter::Write(report, &serialized_report)) { |
| 172 LOG(ERROR) << "Failed to serialize Expect CT report"; | 172 LOG(ERROR) << "Failed to serialize Expect CT report"; |
| 173 return; | 173 return; |
| 174 } | 174 } |
| 175 | 175 |
| 176 UMA_HISTOGRAM_BOOLEAN("SSL.ExpectCTReportSendingAttempt", true); | 176 UMA_HISTOGRAM_BOOLEAN("SSL.ExpectCTReportSendingAttempt", true); |
| 177 | 177 |
| 178 report_sender_->Send(report_uri, serialized_report); | 178 report_sender_->Send(report_uri, serialized_report); |
| 179 } | 179 } |
| OLD | NEW |