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 #include "base/time/default_clock.h" |
| 6 #include "chrome/browser/browser_process.h" |
| 7 #include "chrome/browser/profiles/profile.h" |
5 #include "chrome/browser/safe_browsing/certificate_reporting_service.h" | 8 #include "chrome/browser/safe_browsing/certificate_reporting_service.h" |
6 #include "chrome/browser/safe_browsing/certificate_reporting_service_factory.h" | 9 #include "chrome/browser/safe_browsing/certificate_reporting_service_factory.h" |
| 10 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
7 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 11 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
8 | 12 |
| 13 namespace { |
| 14 |
| 15 // Maximum age in seconds until a report is dropped from the retry list. |
| 16 // By default, reports older than a day are ignored and never retried again. |
| 17 static const uint64_t kMaxReportAgeInSeconds = 86400; |
| 18 |
| 19 // Maximum number of reports to be kept in the report retry list. If an incoming |
| 20 // report has a more recent creation date than the oldest report in the list, |
| 21 // the oldest report is removed from the list and the incoming report is added. |
| 22 // Otherwise, the incoming report is ignored. |
| 23 const size_t kMaxReportCountInQueue = 5; |
| 24 |
| 25 } // namespace |
| 26 |
9 // static | 27 // static |
10 CertificateReportingServiceFactory* | 28 CertificateReportingServiceFactory* |
11 CertificateReportingServiceFactory::GetInstance() { | 29 CertificateReportingServiceFactory::GetInstance() { |
12 return base::Singleton<CertificateReportingServiceFactory>::get(); | 30 return base::Singleton<CertificateReportingServiceFactory>::get(); |
13 } | 31 } |
14 | 32 |
15 // static | 33 // static |
16 CertificateReportingService* | 34 CertificateReportingService* |
17 CertificateReportingServiceFactory::GetForBrowserContext( | 35 CertificateReportingServiceFactory::GetForBrowserContext( |
18 content::BrowserContext* context) { | 36 content::BrowserContext* context) { |
19 return static_cast<CertificateReportingService*>( | 37 return static_cast<CertificateReportingService*>( |
20 GetInstance()->GetServiceForBrowserContext(context, true)); | 38 GetInstance()->GetServiceForBrowserContext(context, true)); |
21 } | 39 } |
22 | 40 |
| 41 void CertificateReportingServiceFactory::SetReportEncryptionParamsForTesting( |
| 42 uint8_t* server_public_key, |
| 43 uint32_t server_public_key_version) { |
| 44 server_public_key_ = server_public_key; |
| 45 server_public_key_version_ = server_public_key_version; |
| 46 } |
| 47 |
| 48 void CertificateReportingServiceFactory::SetClockForTesting( |
| 49 std::unique_ptr<base::Clock> clock) { |
| 50 clock_ = std::move(clock); |
| 51 } |
| 52 |
| 53 void CertificateReportingServiceFactory::SetQueuedReportTTLForTesting( |
| 54 base::TimeDelta queued_report_ttl) { |
| 55 queued_report_ttl_ = queued_report_ttl; |
| 56 } |
| 57 |
| 58 void CertificateReportingServiceFactory::SetMaxQueuedReportCountForTesting( |
| 59 size_t max_queued_report_count) { |
| 60 max_queued_report_count_ = max_queued_report_count; |
| 61 } |
| 62 |
23 CertificateReportingServiceFactory::CertificateReportingServiceFactory() | 63 CertificateReportingServiceFactory::CertificateReportingServiceFactory() |
24 : BrowserContextKeyedServiceFactory( | 64 : BrowserContextKeyedServiceFactory( |
25 "cert_reporting::Factory", | 65 "cert_reporting::Factory", |
26 BrowserContextDependencyManager::GetInstance()) {} | 66 BrowserContextDependencyManager::GetInstance()), |
| 67 server_public_key_(nullptr), |
| 68 server_public_key_version_(0), |
| 69 clock_(new base::DefaultClock()), |
| 70 queued_report_ttl_(base::TimeDelta::FromSeconds(kMaxReportAgeInSeconds)), |
| 71 max_queued_report_count_(kMaxReportCountInQueue) {} |
27 | 72 |
28 CertificateReportingServiceFactory::~CertificateReportingServiceFactory() {} | 73 CertificateReportingServiceFactory::~CertificateReportingServiceFactory() {} |
29 | 74 |
30 KeyedService* CertificateReportingServiceFactory::BuildServiceInstanceFor( | 75 KeyedService* CertificateReportingServiceFactory::BuildServiceInstanceFor( |
31 content::BrowserContext* profile) const { | 76 content::BrowserContext* profile) const { |
32 // TODO(crbug.com/554323): Create a real CertificateReportingService here. | 77 safe_browsing::SafeBrowsingService* safe_browsing_service = |
33 return nullptr; | 78 g_browser_process->safe_browsing_service(); |
| 79 return new CertificateReportingService( |
| 80 safe_browsing_service, safe_browsing_service->url_request_context(), |
| 81 static_cast<Profile*>(profile), server_public_key_, |
| 82 server_public_key_version_, max_queued_report_count_, queued_report_ttl_, |
| 83 clock_.get()); |
34 } | 84 } |
35 | 85 |
36 content::BrowserContext* | 86 content::BrowserContext* |
37 CertificateReportingServiceFactory::GetBrowserContextToUse( | 87 CertificateReportingServiceFactory::GetBrowserContextToUse( |
38 content::BrowserContext* context) const { | 88 content::BrowserContext* context) const { |
39 return context; | 89 return context; |
40 } | 90 } |
OLD | NEW |