Chromium Code Reviews| Index: chrome/browser/safe_browsing/certificate_reporting_service.h |
| diff --git a/chrome/browser/safe_browsing/certificate_reporting_service.h b/chrome/browser/safe_browsing/certificate_reporting_service.h |
| index 6c45e7edcbd824aac15229b6d14e4f654e76f401..fffb32f86fbe311bee2879eda1e70ff9118513d7 100644 |
| --- a/chrome/browser/safe_browsing/certificate_reporting_service.h |
| +++ b/chrome/browser/safe_browsing/certificate_reporting_service.h |
| @@ -10,6 +10,7 @@ |
| #include <string> |
| #include <vector> |
| +#include "base/callback_list.h" |
| #include "base/macros.h" |
| #include "base/memory/weak_ptr.h" |
| #include "base/threading/thread_checker.h" |
| @@ -18,6 +19,8 @@ |
| #include "components/keyed_service/core/keyed_service.h" |
| #include "net/url_request/url_request_context_getter.h" |
| +class Profile; |
| + |
| namespace base { |
| class Clock; |
| } |
| @@ -26,6 +29,10 @@ namespace net { |
| class URLRequestContextGetter; |
| } |
| +namespace safe_browsing { |
| +class SafeBrowsingService; |
| +} |
| + |
| // This service initiates uploads of invalid certificate reports and retries any |
| // failed uploads. Each report is retried until it's older than a certain time |
| // to live (TTL). Reports older than this TTL are dropped and no more retried, |
| @@ -37,7 +44,14 @@ class URLRequestContextGetter; |
| // service. SafeBrowsing service is created before CertificateReportingService, |
| // but is also shut down before any KeyedService is shut down. This means that |
| // CertificateReportingService cannot depend on SafeBrowsing's url request being |
| -// available at all times, and it should know when SafeBrowsing shuts down. |
| +// available at all times, and it should know when SafeBrowsing shuts down. It |
| +// does this by subscribing to SafeBrowsing service shut downs when it's |
|
Jialiu Lin
2016/12/16 01:55:24
nit s/"SafeBrowsingService"/"SafeBrowsing service"
meacer
2016/12/16 20:26:35
Done.
|
| +// created. When SafeBrowsing service shuts down, CertificateReportingService |
| +// also shuts down. |
| +// |
| +// This class also observes SafeBrowsing preference changes to enable/disable |
| +// reporting. It does this by creating a PreferenceObserver that notifies |
| +// this service of changes in SafeBrowsing and extended reporting preferences. |
| class CertificateReportingService : public KeyedService { |
| public: |
| // Represents a report to be sent. |
| @@ -129,13 +143,24 @@ class CertificateReportingService : public KeyedService { |
| DISALLOW_COPY_AND_ASSIGN(Reporter); |
| }; |
| + // Observes SafeBrowsing preference changes. |
| + class PreferenceObserver { |
| + public: |
| + // Called when SafeBrowsing enabled state changes. |
| + virtual void OnPreferenceChanged() = 0; |
| + |
| + virtual ~PreferenceObserver() {} |
|
estark
2016/12/16 01:57:58
nit: looks weird to me to have the destructor at t
meacer
2016/12/16 20:26:35
Done.
|
| + }; |
| + |
| CertificateReportingService( |
| + safe_browsing::SafeBrowsingService* safe_browsing_service, |
| scoped_refptr<net::URLRequestContextGetter> url_request_context_getter, |
| + Profile* profile, |
| uint8_t server_public_key[/* 32 */], |
| uint32_t server_public_key_version, |
| size_t max_queued_report_count, |
| base::TimeDelta max_report_age, |
| - std::unique_ptr<base::Clock> clock); |
| + base::Clock* clock); |
| ~CertificateReportingService() override; |
| @@ -154,12 +179,8 @@ class CertificateReportingService : public KeyedService { |
| // once the service is initialized. |
| void SetEnabled(bool enabled); |
| - // Getters and setters for testing. |
| + // Getters for testing. |
| Reporter* GetReporterForTesting() const; |
| - void SetMaxQueuedReportCountForTesting(size_t max_report_count); |
| - void SetClockForTesting(std::unique_ptr<base::Clock> clock); |
| - void SetMaxReportAgeForTesting(base::TimeDelta max_report_age); |
| - |
| static GURL GetReportingURLForTesting(); |
| private: |
| @@ -194,6 +215,16 @@ class CertificateReportingService : public KeyedService { |
| net::URLRequestContext* url_request_context_; |
| std::unique_ptr<Reporter> reporter_; |
| + // Observes SafeBrowsing preference changes (SB is enabled/disabled, extended |
| + // reporting is enabled/disabled). |
| + std::unique_ptr<PreferenceObserver> preference_observer_; |
| + |
| + // Subscription for url request context shutdowns. When this subscription is |
| + // notified, it means SafeBrowsing service is shutting down, and this service |
| + // must also shut down. |
| + std::unique_ptr<base::CallbackList<void(void)>::Subscription> |
| + safe_browsing_service_shutdown_subscription_; |
| + |
| // Maximum number of reports to be queued for retry. |
| size_t max_queued_report_count_; |
| @@ -202,11 +233,7 @@ class CertificateReportingService : public KeyedService { |
| // this age is ignored and is not re-uploaded. |
| base::TimeDelta max_report_age_; |
| - std::unique_ptr<base::Clock> clock_; |
| - |
| - // Whether a send has ever been made. Used to verify that test setters are |
| - // only called after initialization. |
| - bool made_send_attempt_; |
| + base::Clock* clock_; |
| // Encryption parameters. |
| uint8_t* server_public_key_; |