| Index: chrome/browser/safe_browsing/certificate_reporting_service.cc
|
| diff --git a/chrome/browser/safe_browsing/certificate_reporting_service.cc b/chrome/browser/safe_browsing/certificate_reporting_service.cc
|
| index bbe31f85cf4c977afb40742ac2993c77820800a1..9f57fa5c31ae9b9702cb5577217a633b3333b699 100644
|
| --- a/chrome/browser/safe_browsing/certificate_reporting_service.cc
|
| +++ b/chrome/browser/safe_browsing/certificate_reporting_service.cc
|
| @@ -5,10 +5,24 @@
|
| #include "base/bind_helpers.h"
|
| #include "base/time/clock.h"
|
| #include "base/time/default_clock.h"
|
| +#include "chrome/browser/profiles/profile.h"
|
| #include "chrome/browser/safe_browsing/certificate_reporting_service.h"
|
| +#include "chrome/browser/safe_browsing/safe_browsing_service.h"
|
| +#include "components/prefs/pref_service.h"
|
| +#include "components/safe_browsing_db/safe_browsing_prefs.h"
|
| #include "content/public/browser/browser_thread.h"
|
|
|
| namespace {
|
| +// Maximum age in seconds until a report is dropped from the retry list.
|
| +// By default, reports older than a day are ignored and never retried again.
|
| +static const uint64_t kMaxReportAgeInSeconds = 86400;
|
| +
|
| +// Maximum number of reports to be kept in the report retry list. If an incoming
|
| +// report has a more recent creation date than the oldest report in the list,
|
| +// the oldest report is removed from the list and the incoming report is added.
|
| +// Otherwise, the incoming report is ignored.
|
| +const size_t kMaxReportCountInQueue = 5;
|
| +
|
| // Compare function that orders Reports in reverse chronological order (i.e.
|
| // oldest item is last).
|
| bool ReportCompareFunc(const CertificateReportingService::Report& item1,
|
| @@ -16,6 +30,43 @@ bool ReportCompareFunc(const CertificateReportingService::Report& item1,
|
| return item1.creation_time > item2.creation_time;
|
| }
|
|
|
| +// Observes SafeBrowsing preferences and notifies CertificateReportingService
|
| +// when preferences change. There is one instance of this class per
|
| +// CertificateReportingService and each instance is owned by the
|
| +// CertificateReportingService it notifies.
|
| +class SafeBrowsingPreferenceObserver
|
| + : public CertificateReportingService::PreferenceObserver {
|
| + public:
|
| + SafeBrowsingPreferenceObserver(
|
| + const PrefService& prefs,
|
| + safe_browsing::SafeBrowsingService* safe_browsing_service,
|
| + CertificateReportingService* certificate_reporting_service)
|
| + : safe_browsing_service_(safe_browsing_service),
|
| + prefs_(prefs),
|
| + certificate_reporting_service_(certificate_reporting_service),
|
| + safe_browsing_state_subscription_(
|
| + safe_browsing_service->RegisterStateCallback(
|
| + base::Bind(&SafeBrowsingPreferenceObserver::OnPreferenceChanged,
|
| + base::Unretained(this)))) {}
|
| +
|
| + ~SafeBrowsingPreferenceObserver() override {}
|
| +
|
| + // CertificateReportingService::PreferenceObserver implementation:
|
| + void OnPreferenceChanged() override {
|
| + const bool enabled = safe_browsing_service_ &&
|
| + safe_browsing_service_->enabled_by_prefs() &&
|
| + safe_browsing::IsExtendedReportingEnabled(prefs_);
|
| + certificate_reporting_service_->SetEnabled(enabled);
|
| + }
|
| +
|
| + private:
|
| + const safe_browsing::SafeBrowsingService* safe_browsing_service_;
|
| + const PrefService& prefs_;
|
| + CertificateReportingService* certificate_reporting_service_;
|
| + std::unique_ptr<safe_browsing::SafeBrowsingService::StateSubscription>
|
| + safe_browsing_state_subscription_;
|
| +};
|
| +
|
| } // namespace
|
|
|
| // static
|
| @@ -156,8 +207,21 @@ void CertificateReportingService::Reporter::SuccessCallback(int report_id) {
|
| base::Unretained(event_observer_), report_id, true));
|
| }
|
|
|
| +// static
|
| +CertificateReportingService* CertificateReportingService::Create(
|
| + safe_browsing::SafeBrowsingService* safe_browsing_service,
|
| + Profile* profile) {
|
| + return new CertificateReportingService(
|
| + safe_browsing_service, safe_browsing_service->url_request_context(),
|
| + profile, std::unique_ptr<EventObserver>(new EventObserver()),
|
| + kMaxReportCountInQueue,
|
| + base::TimeDelta::FromSeconds(kMaxReportAgeInSeconds), nullptr);
|
| +}
|
| +
|
| CertificateReportingService::CertificateReportingService(
|
| + safe_browsing::SafeBrowsingService* safe_browsing_service,
|
| scoped_refptr<net::URLRequestContextGetter> url_request_context_getter,
|
| + Profile* profile,
|
| std::unique_ptr<EventObserver> event_observer,
|
| size_t max_queued_report_count,
|
| base::TimeDelta max_report_age,
|
| @@ -170,6 +234,14 @@ CertificateReportingService::CertificateReportingService(
|
| test_clock_(test_clock),
|
| made_send_attempt_(false) {
|
| DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
| + // Observe changes in SafeBrowsing preferences.
|
| + preference_observer_.reset(new SafeBrowsingPreferenceObserver(
|
| + *profile->GetPrefs(), safe_browsing_service, this));
|
| + // Subscribe to SafeBrowsing shutdown notifications.
|
| + safe_browsing_service_shutdown_subscription_ =
|
| + safe_browsing_service->RegisterShutdownCallback(base::Bind(
|
| + &CertificateReportingService::Shutdown, base::Unretained(this)));
|
| +
|
| content::BrowserThread::PostTaskAndReply(
|
| content::BrowserThread::IO, FROM_HERE,
|
| base::Bind(&CertificateReportingService::InitializeOnIOThread,
|
|
|