| 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 "chrome/browser/safe_browsing/services_delegate_impl.h" | 5 #include "chrome/browser/safe_browsing/services_delegate_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/metrics/field_trial.h" |
| 12 #include "base/strings/string_util.h" |
| 11 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 13 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 12 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
| 15 #include "components/safe_browsing_db/v4_local_database_manager.h" |
| 13 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 14 | 17 |
| 15 namespace safe_browsing { | 18 namespace safe_browsing { |
| 16 | 19 |
| 20 namespace { |
| 21 const base::Feature kSafeBrowsingV4LocalDatabaseManagerEnabled { |
| 22 "SafeBrowsingV4LocalDatabaseManagerEnabled", |
| 23 base::FEATURE_DISABLED_BY_DEFAULT |
| 24 }; |
| 25 } // namespace |
| 26 |
| 17 // static | 27 // static |
| 18 std::unique_ptr<ServicesDelegate> ServicesDelegate::Create( | 28 std::unique_ptr<ServicesDelegate> ServicesDelegate::Create( |
| 19 SafeBrowsingService* safe_browsing_service) { | 29 SafeBrowsingService* safe_browsing_service) { |
| 20 return base::WrapUnique( | 30 return base::WrapUnique( |
| 21 new ServicesDelegateImpl(safe_browsing_service, nullptr)); | 31 new ServicesDelegateImpl(safe_browsing_service, nullptr)); |
| 22 } | 32 } |
| 23 | 33 |
| 24 // static | 34 // static |
| 25 std::unique_ptr<ServicesDelegate> ServicesDelegate::CreateForTest( | 35 std::unique_ptr<ServicesDelegate> ServicesDelegate::CreateForTest( |
| 26 SafeBrowsingService* safe_browsing_service, | 36 SafeBrowsingService* safe_browsing_service, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 45 net::URLRequestContextGetter* context_getter) { | 55 net::URLRequestContextGetter* context_getter) { |
| 46 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 56 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 47 #if defined(SAFE_BROWSING_CSD) | 57 #if defined(SAFE_BROWSING_CSD) |
| 48 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 58 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 49 switches::kDisableClientSidePhishingDetection)) { | 59 switches::kDisableClientSidePhishingDetection)) { |
| 50 csd_service_.reset(ClientSideDetectionService::Create(context_getter)); | 60 csd_service_.reset(ClientSideDetectionService::Create(context_getter)); |
| 51 } | 61 } |
| 52 #endif // defined(SAFE_BROWSING_CSD) | 62 #endif // defined(SAFE_BROWSING_CSD) |
| 53 } | 63 } |
| 54 | 64 |
| 55 void ServicesDelegateImpl::InitializeServices() { | 65 void ServicesDelegateImpl::Initialize() { |
| 56 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 66 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 57 download_service_.reset( | 67 download_service_.reset( |
| 58 (services_creator_ && | 68 (services_creator_ && |
| 59 services_creator_->CanCreateDownloadProtectionService()) | 69 services_creator_->CanCreateDownloadProtectionService()) |
| 60 ? services_creator_->CreateDownloadProtectionService() | 70 ? services_creator_->CreateDownloadProtectionService() |
| 61 : CreateDownloadProtectionService()); | 71 : CreateDownloadProtectionService()); |
| 62 incident_service_.reset( | 72 incident_service_.reset( |
| 63 (services_creator_ && | 73 (services_creator_ && |
| 64 services_creator_->CanCreateIncidentReportingService()) | 74 services_creator_->CanCreateIncidentReportingService()) |
| 65 ? services_creator_->CreateIncidentReportingService() | 75 ? services_creator_->CreateIncidentReportingService() |
| 66 : CreateIncidentReportingService()); | 76 : CreateIncidentReportingService()); |
| 67 resource_request_detector_.reset( | 77 resource_request_detector_.reset( |
| 68 (services_creator_ && | 78 (services_creator_ && |
| 69 services_creator_->CanCreateResourceRequestDetector()) | 79 services_creator_->CanCreateResourceRequestDetector()) |
| 70 ? services_creator_->CreateResourceRequestDetector() | 80 ? services_creator_->CreateResourceRequestDetector() |
| 71 : CreateResourceRequestDetector()); | 81 : CreateResourceRequestDetector()); |
| 82 |
| 83 if (IsV4LocalDatabaseManagerEnabled()) { |
| 84 v4_local_database_manager_ = CreateV4LocalDatabaseManager(); |
| 85 } |
| 72 } | 86 } |
| 73 | 87 |
| 74 void ServicesDelegateImpl::ShutdownServices() { | 88 void ServicesDelegateImpl::ShutdownServices() { |
| 75 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 89 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 76 // The IO thread is going away, so make sure the ClientSideDetectionService | 90 // The IO thread is going away, so make sure the ClientSideDetectionService |
| 77 // dtor executes now since it may call the dtor of URLFetcher which relies | 91 // dtor executes now since it may call the dtor of URLFetcher which relies |
| 78 // on it. | 92 // on it. |
| 79 csd_service_.reset(); | 93 csd_service_.reset(); |
| 80 | 94 |
| 81 resource_request_detector_.reset(); | 95 resource_request_detector_.reset(); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 IncidentReportingService* | 157 IncidentReportingService* |
| 144 ServicesDelegateImpl::CreateIncidentReportingService() { | 158 ServicesDelegateImpl::CreateIncidentReportingService() { |
| 145 return new IncidentReportingService(safe_browsing_service_); | 159 return new IncidentReportingService(safe_browsing_service_); |
| 146 } | 160 } |
| 147 | 161 |
| 148 ResourceRequestDetector* ServicesDelegateImpl::CreateResourceRequestDetector() { | 162 ResourceRequestDetector* ServicesDelegateImpl::CreateResourceRequestDetector() { |
| 149 return new ResourceRequestDetector(safe_browsing_service_->database_manager(), | 163 return new ResourceRequestDetector(safe_browsing_service_->database_manager(), |
| 150 incident_service_->GetIncidentReceiver()); | 164 incident_service_->GetIncidentReceiver()); |
| 151 } | 165 } |
| 152 | 166 |
| 167 void ServicesDelegateImpl::StartOnIOThread( |
| 168 net::URLRequestContextGetter* url_request_context_getter, |
| 169 const V4ProtocolConfig& v4_config) { |
| 170 if (v4_local_database_manager_.get()) { |
| 171 v4_local_database_manager_->StartOnIOThread(url_request_context_getter, |
| 172 v4_config); |
| 173 } |
| 174 } |
| 175 |
| 176 void ServicesDelegateImpl::StopOnIOThread(bool shutdown) { |
| 177 if (v4_local_database_manager_.get()) { |
| 178 v4_local_database_manager_->StopOnIOThread(shutdown); |
| 179 } |
| 180 } |
| 181 |
| 182 V4LocalDatabaseManager* ServicesDelegateImpl::CreateV4LocalDatabaseManager() { |
| 183 return new V4LocalDatabaseManager(); |
| 184 } |
| 185 |
| 186 bool ServicesDelegateImpl::IsV4LocalDatabaseManagerEnabled() { |
| 187 return base::FeatureList::IsEnabled( |
| 188 kSafeBrowsingV4LocalDatabaseManagerEnabled); |
| 189 } |
| 190 |
| 153 } // namespace safe_browsing | 191 } // namespace safe_browsing |
| OLD | NEW |