| 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) { |
| 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 base::Bind(&NetLogPingStartCallback, net_log_, fetcher->GetOriginalURL(), | 187 base::Bind(&NetLogPingStartCallback, net_log_, fetcher->GetOriginalURL(), |
| 180 report_base64)); | 188 report_base64)); |
| 181 | 189 |
| 182 fetcher->Start(); | 190 fetcher->Start(); |
| 183 safebrowsing_reports_.insert(std::move(fetcher)); | 191 safebrowsing_reports_.insert(std::move(fetcher)); |
| 184 } | 192 } |
| 185 | 193 |
| 186 void SafeBrowsingPingManager::ReportInvalidCertificateChain( | 194 void SafeBrowsingPingManager::ReportInvalidCertificateChain( |
| 187 const std::string& serialized_report) { | 195 const std::string& serialized_report) { |
| 188 DCHECK(certificate_error_reporter_); | 196 DCHECK(certificate_error_reporter_); |
| 189 certificate_error_reporter_->SendExtendedReportingReport(serialized_report); | 197 certificate_error_reporter_->SendExtendedReportingReport( |
| 198 serialized_report, base::Closure(), base::Bind(RecordUMAOnFailure)); |
| 190 } | 199 } |
| 191 | 200 |
| 192 void SafeBrowsingPingManager::SetCertificateErrorReporterForTesting( | 201 void SafeBrowsingPingManager::SetCertificateErrorReporterForTesting( |
| 193 std::unique_ptr<certificate_reporting::ErrorReporter> | 202 std::unique_ptr<certificate_reporting::ErrorReporter> |
| 194 certificate_error_reporter) { | 203 certificate_error_reporter) { |
| 195 certificate_error_reporter_ = std::move(certificate_error_reporter); | 204 certificate_error_reporter_ = std::move(certificate_error_reporter); |
| 196 } | 205 } |
| 197 | 206 |
| 198 void SafeBrowsingPingManager::ReportPermissionAction( | 207 void SafeBrowsingPingManager::ReportPermissionAction( |
| 199 const PermissionReportInfo& report_info) { | 208 const PermissionReportInfo& report_info) { |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 version_.c_str()); | 299 version_.c_str()); |
| 291 std::string api_key = google_apis::GetAPIKey(); | 300 std::string api_key = google_apis::GetAPIKey(); |
| 292 if (!api_key.empty()) { | 301 if (!api_key.empty()) { |
| 293 base::StringAppendF(&url, "&key=%s", | 302 base::StringAppendF(&url, "&key=%s", |
| 294 net::EscapeQueryParamValue(api_key, true).c_str()); | 303 net::EscapeQueryParamValue(api_key, true).c_str()); |
| 295 } | 304 } |
| 296 return GURL(url); | 305 return GURL(url); |
| 297 } | 306 } |
| 298 | 307 |
| 299 } // namespace safe_browsing | 308 } // namespace safe_browsing |
| OLD | NEW |