| 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 | 4 |
| 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_CERTIFICATE_REPORTING_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_CERTIFICATE_REPORTING_SERVICE_H_ |
| 6 #define CHROME_BROWSER_SAFE_BROWSING_CERTIFICATE_REPORTING_SERVICE_H_ | 6 #define CHROME_BROWSER_SAFE_BROWSING_CERTIFICATE_REPORTING_SERVICE_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/callback_list.h" | 13 #include "base/callback_list.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/threading/thread_checker.h" | 16 #include "base/threading/thread_checker.h" |
| 17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 18 #include "components/certificate_reporting/error_reporter.h" | 18 #include "components/certificate_reporting/error_reporter.h" |
| 19 #include "components/keyed_service/core/keyed_service.h" | 19 #include "components/keyed_service/core/keyed_service.h" |
| 20 #include "net/url_request/url_request_context_getter.h" | 20 #include "net/url_request/url_request_context_getter.h" |
| 21 | 21 |
| 22 class Profile; |
| 23 |
| 22 namespace base { | 24 namespace base { |
| 23 class Clock; | 25 class Clock; |
| 24 } | 26 } |
| 25 | 27 |
| 26 namespace net { | 28 namespace net { |
| 27 class URLRequestContext; | 29 class URLRequestContext; |
| 28 class URLRequestContextGetter; | 30 class URLRequestContextGetter; |
| 29 } | 31 } |
| 30 | 32 |
| 33 namespace safe_browsing { |
| 34 class SafeBrowsingService; |
| 35 } |
| 36 |
| 31 // This service initiates uploads of invalid certificate reports and retries any | 37 // This service initiates uploads of invalid certificate reports and retries any |
| 32 // failed uploads. Each report is retried until it's older than a certain time | 38 // failed uploads. Each report is retried until it's older than a certain time |
| 33 // to live (TTL). Reports older than this TTL are dropped and no more retried, | 39 // to live (TTL). Reports older than this TTL are dropped and no more retried, |
| 34 // so that the retry list doesn't grow indefinitely. | 40 // so that the retry list doesn't grow indefinitely. |
| 35 // | 41 // |
| 36 // Lifetime and dependencies: | 42 // Lifetime and dependencies: |
| 37 // | 43 // |
| 38 // CertificateReportingService uses the url request context from SafeBrowsing | 44 // CertificateReportingService uses the url request context from SafeBrowsing |
| 39 // service. SafeBrowsing service is created before this service, but is also | 45 // service. SafeBrowsing service is created before this service, but is also |
| 40 // shut down before any KeyedService is shut down. This means that this class | 46 // shut down before any KeyedService is shut down. This means that this class |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 // Current report id, starting from zero and monotonically incrementing. | 162 // Current report id, starting from zero and monotonically incrementing. |
| 157 int current_report_id_; | 163 int current_report_id_; |
| 158 | 164 |
| 159 std::map<int, Report> inflight_reports_; | 165 std::map<int, Report> inflight_reports_; |
| 160 | 166 |
| 161 base::WeakPtrFactory<Reporter> weak_factory_; | 167 base::WeakPtrFactory<Reporter> weak_factory_; |
| 162 | 168 |
| 163 DISALLOW_COPY_AND_ASSIGN(Reporter); | 169 DISALLOW_COPY_AND_ASSIGN(Reporter); |
| 164 }; | 170 }; |
| 165 | 171 |
| 172 // Observes SafeBrowsing preference changes. An instance of this is created by |
| 173 // ChromeContentBrowserClient to notify the service when SafeBrowsing |
| 174 // or extended reporting is enabled/disabled. This class is introduced to |
| 175 // decouple chrome/browser/ssl from SafeBrowsing. |
| 176 class PreferenceObserver { |
| 177 public: |
| 178 // Called when SafeBrowsing preference changes. |
| 179 virtual void OnPreferenceChanged() = 0; |
| 180 |
| 181 virtual ~PreferenceObserver() {} |
| 182 }; |
| 183 |
| 184 static CertificateReportingService* Create( |
| 185 safe_browsing::SafeBrowsingService* safe_browsing_service, |
| 186 Profile* profile); |
| 187 // Constructor for unit tests: |
| 166 CertificateReportingService( | 188 CertificateReportingService( |
| 189 safe_browsing::SafeBrowsingService* safe_browsing_service, |
| 167 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter, | 190 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter, |
| 191 Profile* profile, |
| 168 std::unique_ptr<EventObserver> event_observer, | 192 std::unique_ptr<EventObserver> event_observer, |
| 169 size_t max_queued_report_count, | 193 size_t max_queued_report_count, |
| 170 base::TimeDelta max_report_age, | 194 base::TimeDelta max_report_age, |
| 171 base::Clock* test_clock); | 195 base::Clock* test_clock); |
| 172 | 196 |
| 173 ~CertificateReportingService() override; | 197 ~CertificateReportingService() override; |
| 174 | 198 |
| 175 // KeyedService implementation: | 199 // KeyedService implementation: |
| 176 void Shutdown() override; | 200 void Shutdown() override; |
| 177 | 201 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 | 253 |
| 230 // If true, reporting is enabled. When SafeBrowsing preferences change, this | 254 // If true, reporting is enabled. When SafeBrowsing preferences change, this |
| 231 // might be set to false. | 255 // might be set to false. |
| 232 bool enabled_; | 256 bool enabled_; |
| 233 | 257 |
| 234 // scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; | 258 // scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; |
| 235 net::URLRequestContext* url_request_context_; | 259 net::URLRequestContext* url_request_context_; |
| 236 | 260 |
| 237 std::unique_ptr<Reporter> reporter_; | 261 std::unique_ptr<Reporter> reporter_; |
| 238 | 262 |
| 263 // Observes SafeBrowsing preference changes (SB is enabled/disabled, extended |
| 264 // reporting is enabled/disabled). |
| 265 std::unique_ptr<PreferenceObserver> preference_observer_; |
| 266 |
| 239 // Subscription for url request context shutdowns. When this subscription is | 267 // Subscription for url request context shutdowns. When this subscription is |
| 240 // notified, it means that the SafeBrowsing service is shutting down, and this | 268 // notified, it means that the SafeBrowsing service is shutting down, and this |
| 241 // service must also shut down. | 269 // service must also shut down. |
| 242 std::unique_ptr<base::CallbackList<void(void)>::Subscription> | 270 std::unique_ptr<base::CallbackList<void(void)>::Subscription> |
| 243 safe_browsing_service_shutdown_subscription_; | 271 safe_browsing_service_shutdown_subscription_; |
| 244 | 272 |
| 245 // Observes events from this service. Default implementation doesn't do | 273 // Observes events from this service. Default implementation doesn't do |
| 246 // anything. Tests use this to keep track of sent/failed reports etc. | 274 // anything. Tests use this to keep track of sent/failed reports etc. |
| 247 std::unique_ptr<EventObserver> event_observer_; | 275 std::unique_ptr<EventObserver> event_observer_; |
| 248 | 276 |
| 249 // Maximum number of reports to be queued for retry. | 277 // Maximum number of reports to be queued for retry. |
| 250 size_t max_queued_report_count_; | 278 size_t max_queued_report_count_; |
| 251 | 279 |
| 252 // Maximum age of the reports to be queued for retry, from the time the | 280 // Maximum age of the reports to be queued for retry, from the time the |
| 253 // certificate error was first encountered by the user. Any report older than | 281 // certificate error was first encountered by the user. Any report older than |
| 254 // this age is ignored and is not re-uploaded. | 282 // this age is ignored and is not re-uploaded. |
| 255 base::TimeDelta max_report_age_; | 283 base::TimeDelta max_report_age_; |
| 256 | 284 |
| 257 // Test clock. If null, system clock is used. | 285 // Test clock. If null, system clock is used. |
| 258 base::Clock* test_clock_; | 286 base::Clock* test_clock_; |
| 259 | 287 |
| 260 // Whether a send has ever been made. Used to verify that test setters are | 288 // Whether a send has ever been made. Used to verify that test setters are |
| 261 // only called after initialization. | 289 // only called after initialization. |
| 262 bool made_send_attempt_; | 290 bool made_send_attempt_; |
| 263 | 291 |
| 264 DISALLOW_COPY_AND_ASSIGN(CertificateReportingService); | 292 DISALLOW_COPY_AND_ASSIGN(CertificateReportingService); |
| 265 }; | 293 }; |
| 266 | 294 |
| 267 #endif // CHROME_BROWSER_SAFE_BROWSING_CERTIFICATE_REPORTING_SERVICE_H_ | 295 #endif // CHROME_BROWSER_SAFE_BROWSING_CERTIFICATE_REPORTING_SERVICE_H_ |
| OLD | NEW |