Chromium Code Reviews| 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 #include "chrome/browser/safe_browsing/certificate_reporting_service.h" | 4 #include "chrome/browser/safe_browsing/certificate_reporting_service.h" |
| 5 | 5 |
| 6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
| 7 #include "base/metrics/histogram_macros.h" | 7 #include "base/metrics/histogram_macros.h" |
| 8 #include "base/metrics/sparse_histogram.h" | 8 #include "base/metrics/sparse_histogram.h" |
| 9 #include "base/time/clock.h" | 9 #include "base/time/clock.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 12 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 13 #include "components/certificate_reporting/error_report.h" | |
| 13 #include "components/prefs/pref_service.h" | 14 #include "components/prefs/pref_service.h" |
| 14 #include "components/safe_browsing_db/safe_browsing_prefs.h" | 15 #include "components/safe_browsing_db/safe_browsing_prefs.h" |
| 15 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 19 // URL to upload invalid certificate chain reports. An HTTP URL is used because | 20 // URL to upload invalid certificate chain reports. An HTTP URL is used because |
| 20 // a client seeing an invalid cert might not be able to make an HTTPS connection | 21 // a client seeing an invalid cert might not be able to make an HTTPS connection |
| 21 // to report it. | 22 // to report it. |
| 22 const char kExtendedReportingUploadUrl[] = | 23 const char kExtendedReportingUploadUrl[] = |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 | 103 |
| 103 void CertificateReportingService::Reporter::SendPending() { | 104 void CertificateReportingService::Reporter::SendPending() { |
| 104 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 105 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 105 if (!retries_enabled_) { | 106 if (!retries_enabled_) { |
| 106 return; | 107 return; |
| 107 } | 108 } |
| 108 const base::Time now = clock_->Now(); | 109 const base::Time now = clock_->Now(); |
| 109 // Copy pending reports and clear the retry list. | 110 // Copy pending reports and clear the retry list. |
| 110 std::vector<Report> items = retry_list_->items(); | 111 std::vector<Report> items = retry_list_->items(); |
| 111 retry_list_->Clear(); | 112 retry_list_->Clear(); |
| 112 for (const Report& report : items) { | 113 for (Report& report : items) { |
| 113 if (report.creation_time < now - report_ttl_) { | 114 if (report.creation_time < now - report_ttl_) { |
| 114 // Report too old, ignore. | 115 // Report too old, ignore. |
| 115 continue; | 116 continue; |
| 116 } | 117 } |
| 118 if (!report.is_retried) { | |
| 119 // If this is the first retry, deserialize the report, set its retry bit | |
| 120 // and serialize again. | |
| 121 certificate_reporting::ErrorReport error_report; | |
| 122 if (!error_report.InitializeFromString(report.serialized_report)) { | |
| 123 LOG(ERROR) << "Cannot deserialize report"; | |
|
estark
2017/01/13 23:26:22
Is this possible? maybe should just be DCHECK(erro
meacer
2017/01/17 22:24:27
cert_report_helper seemed to imply it was possible
| |
| 124 continue; | |
| 125 } | |
| 126 error_report.SetIsRetryUpload(true); | |
| 127 if (!error_report.Serialize(&report.serialized_report)) { | |
| 128 LOG(ERROR) << "Cannot serialize report"; | |
| 129 continue; | |
| 130 } | |
| 131 } | |
| 132 report.is_retried = true; | |
| 117 SendInternal(report); | 133 SendInternal(report); |
| 118 } | 134 } |
| 119 } | 135 } |
| 120 | 136 |
| 121 size_t | 137 size_t |
| 122 CertificateReportingService::Reporter::inflight_report_count_for_testing() | 138 CertificateReportingService::Reporter::inflight_report_count_for_testing() |
| 123 const { | 139 const { |
| 124 return inflight_reports_.size(); | 140 return inflight_reports_.size(); |
| 125 } | 141 } |
| 126 | 142 |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 310 } | 326 } |
| 311 | 327 |
| 312 void CertificateReportingService::OnPreferenceChanged() { | 328 void CertificateReportingService::OnPreferenceChanged() { |
| 313 safe_browsing::SafeBrowsingService* safe_browsing_service_ = | 329 safe_browsing::SafeBrowsingService* safe_browsing_service_ = |
| 314 g_browser_process->safe_browsing_service(); | 330 g_browser_process->safe_browsing_service(); |
| 315 const bool enabled = safe_browsing_service_ && | 331 const bool enabled = safe_browsing_service_ && |
| 316 safe_browsing_service_->enabled_by_prefs() && | 332 safe_browsing_service_->enabled_by_prefs() && |
| 317 safe_browsing::IsExtendedReportingEnabled(pref_service_); | 333 safe_browsing::IsExtendedReportingEnabled(pref_service_); |
| 318 SetEnabled(enabled); | 334 SetEnabled(enabled); |
| 319 } | 335 } |
| OLD | NEW |