| 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" |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 145 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 146 inflight_reports_.insert(std::make_pair(report.report_id, report)); | 146 inflight_reports_.insert(std::make_pair(report.report_id, report)); |
| 147 error_reporter_->SendExtendedReportingReport( | 147 error_reporter_->SendExtendedReportingReport( |
| 148 report.serialized_report, | 148 report.serialized_report, |
| 149 base::Bind(&CertificateReportingService::Reporter::SuccessCallback, | 149 base::Bind(&CertificateReportingService::Reporter::SuccessCallback, |
| 150 weak_factory_.GetWeakPtr(), report.report_id), | 150 weak_factory_.GetWeakPtr(), report.report_id), |
| 151 base::Bind(&CertificateReportingService::Reporter::ErrorCallback, | 151 base::Bind(&CertificateReportingService::Reporter::ErrorCallback, |
| 152 weak_factory_.GetWeakPtr(), report.report_id)); | 152 weak_factory_.GetWeakPtr(), report.report_id)); |
| 153 } | 153 } |
| 154 | 154 |
| 155 void CertificateReportingService::Reporter::ErrorCallback(int report_id, | 155 void CertificateReportingService::Reporter::ErrorCallback( |
| 156 const GURL& url, | 156 int report_id, |
| 157 int error) { | 157 const GURL& url, |
| 158 int net_error, |
| 159 int http_response_code) { |
| 158 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 160 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 159 RecordUMAOnFailure(error); | 161 RecordUMAOnFailure(net_error); |
| 160 if (retries_enabled_) { | 162 if (retries_enabled_) { |
| 161 auto it = inflight_reports_.find(report_id); | 163 auto it = inflight_reports_.find(report_id); |
| 162 DCHECK(it != inflight_reports_.end()); | 164 DCHECK(it != inflight_reports_.end()); |
| 163 retry_list_->Add(it->second); | 165 retry_list_->Add(it->second); |
| 164 } | 166 } |
| 165 CHECK_GT(inflight_reports_.erase(report_id), 0u); | 167 CHECK_GT(inflight_reports_.erase(report_id), 0u); |
| 166 } | 168 } |
| 167 | 169 |
| 168 void CertificateReportingService::Reporter::SuccessCallback(int report_id) { | 170 void CertificateReportingService::Reporter::SuccessCallback(int report_id) { |
| 169 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 171 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 } | 323 } |
| 322 | 324 |
| 323 void CertificateReportingService::OnPreferenceChanged() { | 325 void CertificateReportingService::OnPreferenceChanged() { |
| 324 safe_browsing::SafeBrowsingService* safe_browsing_service_ = | 326 safe_browsing::SafeBrowsingService* safe_browsing_service_ = |
| 325 g_browser_process->safe_browsing_service(); | 327 g_browser_process->safe_browsing_service(); |
| 326 const bool enabled = safe_browsing_service_ && | 328 const bool enabled = safe_browsing_service_ && |
| 327 safe_browsing_service_->enabled_by_prefs() && | 329 safe_browsing_service_->enabled_by_prefs() && |
| 328 safe_browsing::IsExtendedReportingEnabled(pref_service_); | 330 safe_browsing::IsExtendedReportingEnabled(pref_service_); |
| 329 SetEnabled(enabled); | 331 SetEnabled(enabled); |
| 330 } | 332 } |
| OLD | NEW |