| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/safe_browsing/ping_manager.h" | 5 #include "chrome/browser/safe_browsing/ping_manager.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/metrics/histogram_macros.h" |
| 13 #include "base/metrics/sparse_histogram.h" |
| 12 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 13 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 14 #include "base/values.h" | 16 #include "base/values.h" |
| 15 #include "chrome/browser/safe_browsing/permission_reporter.h" | 17 #include "chrome/browser/safe_browsing/permission_reporter.h" |
| 16 #include "components/certificate_reporting/error_reporter.h" | 18 #include "components/certificate_reporting/error_reporter.h" |
| 17 #include "components/data_use_measurement/core/data_use_user_data.h" | 19 #include "components/data_use_measurement/core/data_use_user_data.h" |
| 18 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 19 #include "google_apis/google_api_keys.h" | 21 #include "google_apis/google_api_keys.h" |
| 20 #include "net/base/escape.h" | 22 #include "net/base/escape.h" |
| 21 #include "net/base/load_flags.h" | 23 #include "net/base/load_flags.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 const net::URLRequestStatus& status, | 62 const net::URLRequestStatus& status, |
| 61 net::NetLogCaptureMode) { | 63 net::NetLogCaptureMode) { |
| 62 std::unique_ptr<base::DictionaryValue> event_params( | 64 std::unique_ptr<base::DictionaryValue> event_params( |
| 63 new base::DictionaryValue()); | 65 new base::DictionaryValue()); |
| 64 event_params->SetInteger("status", status.status()); | 66 event_params->SetInteger("status", status.status()); |
| 65 event_params->SetInteger("error", status.error()); | 67 event_params->SetInteger("error", status.error()); |
| 66 net_log.source().AddToEventParameters(event_params.get()); | 68 net_log.source().AddToEventParameters(event_params.get()); |
| 67 return std::move(event_params); | 69 return std::move(event_params); |
| 68 } | 70 } |
| 69 | 71 |
| 72 // Records an UMA histogram of the net errors when certificate reports |
| 73 // fail to send. |
| 74 void RecordUMAOnFailure(const GURL& report_uri, int net_error, int report_id) { |
| 75 UMA_HISTOGRAM_SPARSE_SLOWLY("SSL.CertificateErrorReportFailure", -net_error); |
| 76 } |
| 77 |
| 70 } // namespace | 78 } // namespace |
| 71 | 79 |
| 72 namespace safe_browsing { | 80 namespace safe_browsing { |
| 73 | 81 |
| 74 // SafeBrowsingPingManager implementation ---------------------------------- | 82 // SafeBrowsingPingManager implementation ---------------------------------- |
| 75 | 83 |
| 76 // static | 84 // static |
| 77 std::unique_ptr<SafeBrowsingPingManager> SafeBrowsingPingManager::Create( | 85 std::unique_ptr<SafeBrowsingPingManager> SafeBrowsingPingManager::Create( |
| 78 net::URLRequestContextGetter* request_context_getter, | 86 net::URLRequestContextGetter* request_context_getter, |
| 79 const SafeBrowsingProtocolConfig& config) { | 87 const SafeBrowsingProtocolConfig& config) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 92 | 100 |
| 93 if (request_context_getter) { | 101 if (request_context_getter) { |
| 94 net::ReportSender::CookiesPreference cookies_preference; | 102 net::ReportSender::CookiesPreference cookies_preference; |
| 95 GURL certificate_upload_url; | 103 GURL certificate_upload_url; |
| 96 cookies_preference = net::ReportSender::DO_NOT_SEND_COOKIES; | 104 cookies_preference = net::ReportSender::DO_NOT_SEND_COOKIES; |
| 97 certificate_upload_url = GURL(kExtendedReportingUploadUrlInsecure); | 105 certificate_upload_url = GURL(kExtendedReportingUploadUrlInsecure); |
| 98 | 106 |
| 99 certificate_error_reporter_.reset(new certificate_reporting::ErrorReporter( | 107 certificate_error_reporter_.reset(new certificate_reporting::ErrorReporter( |
| 100 request_context_getter->GetURLRequestContext(), certificate_upload_url, | 108 request_context_getter->GetURLRequestContext(), certificate_upload_url, |
| 101 cookies_preference)); | 109 cookies_preference)); |
| 110 certificate_error_reporter_->SetErrorCallback( |
| 111 base::Bind(&RecordUMAOnFailure)); |
| 102 | 112 |
| 103 permission_reporter_.reset( | 113 permission_reporter_.reset( |
| 104 new PermissionReporter(request_context_getter->GetURLRequestContext())); | 114 new PermissionReporter(request_context_getter->GetURLRequestContext())); |
| 105 | 115 |
| 106 net_log_ = net::NetLogWithSource::Make( | 116 net_log_ = net::NetLogWithSource::Make( |
| 107 request_context_getter->GetURLRequestContext()->net_log(), | 117 request_context_getter->GetURLRequestContext()->net_log(), |
| 108 net::NetLogSourceType::SAFE_BROWSING); | 118 net::NetLogSourceType::SAFE_BROWSING); |
| 109 } | 119 } |
| 110 | 120 |
| 111 version_ = SafeBrowsingProtocolManagerHelper::Version(); | 121 version_ = SafeBrowsingProtocolManagerHelper::Version(); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 base::Bind(&NetLogPingStartCallback, net_log_, fetcher->GetOriginalURL(), | 189 base::Bind(&NetLogPingStartCallback, net_log_, fetcher->GetOriginalURL(), |
| 180 report_base64)); | 190 report_base64)); |
| 181 | 191 |
| 182 fetcher->Start(); | 192 fetcher->Start(); |
| 183 safebrowsing_reports_.insert(std::move(fetcher)); | 193 safebrowsing_reports_.insert(std::move(fetcher)); |
| 184 } | 194 } |
| 185 | 195 |
| 186 void SafeBrowsingPingManager::ReportInvalidCertificateChain( | 196 void SafeBrowsingPingManager::ReportInvalidCertificateChain( |
| 187 const std::string& serialized_report) { | 197 const std::string& serialized_report) { |
| 188 DCHECK(certificate_error_reporter_); | 198 DCHECK(certificate_error_reporter_); |
| 189 certificate_error_reporter_->SendExtendedReportingReport(serialized_report); | 199 certificate_error_reporter_->SendExtendedReportingReport(serialized_report, |
| 200 0); |
| 190 } | 201 } |
| 191 | 202 |
| 192 void SafeBrowsingPingManager::SetCertificateErrorReporterForTesting( | 203 void SafeBrowsingPingManager::SetCertificateErrorReporterForTesting( |
| 193 std::unique_ptr<certificate_reporting::ErrorReporter> | 204 std::unique_ptr<certificate_reporting::ErrorReporter> |
| 194 certificate_error_reporter) { | 205 certificate_error_reporter) { |
| 195 certificate_error_reporter_ = std::move(certificate_error_reporter); | 206 certificate_error_reporter_ = std::move(certificate_error_reporter); |
| 196 } | 207 } |
| 197 | 208 |
| 198 void SafeBrowsingPingManager::ReportPermissionAction( | 209 void SafeBrowsingPingManager::ReportPermissionAction( |
| 199 const PermissionReportInfo& report_info) { | 210 const PermissionReportInfo& report_info) { |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 version_.c_str()); | 301 version_.c_str()); |
| 291 std::string api_key = google_apis::GetAPIKey(); | 302 std::string api_key = google_apis::GetAPIKey(); |
| 292 if (!api_key.empty()) { | 303 if (!api_key.empty()) { |
| 293 base::StringAppendF(&url, "&key=%s", | 304 base::StringAppendF(&url, "&key=%s", |
| 294 net::EscapeQueryParamValue(api_key, true).c_str()); | 305 net::EscapeQueryParamValue(api_key, true).c_str()); |
| 295 } | 306 } |
| 296 return GURL(url); | 307 return GURL(url); |
| 297 } | 308 } |
| 298 | 309 |
| 299 } // namespace safe_browsing | 310 } // namespace safe_browsing |
| OLD | NEW |