OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/safe_browsing_service.h" | 5 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 SafeBrowsingURLRequestContextGetter::~SafeBrowsingURLRequestContextGetter() {} | 250 SafeBrowsingURLRequestContextGetter::~SafeBrowsingURLRequestContextGetter() {} |
251 | 251 |
252 // static | 252 // static |
253 SafeBrowsingServiceFactory* SafeBrowsingService::factory_ = NULL; | 253 SafeBrowsingServiceFactory* SafeBrowsingService::factory_ = NULL; |
254 | 254 |
255 // The default SafeBrowsingServiceFactory. Global, made a singleton so we | 255 // The default SafeBrowsingServiceFactory. Global, made a singleton so we |
256 // don't leak it. | 256 // don't leak it. |
257 class SafeBrowsingServiceFactoryImpl : public SafeBrowsingServiceFactory { | 257 class SafeBrowsingServiceFactoryImpl : public SafeBrowsingServiceFactory { |
258 public: | 258 public: |
259 SafeBrowsingService* CreateSafeBrowsingService() override { | 259 SafeBrowsingService* CreateSafeBrowsingService() override { |
260 return new SafeBrowsingService(V4FeatureList::GetV4UsageStatus()); | 260 return new SafeBrowsingService(); |
261 } | 261 } |
262 | 262 |
263 private: | 263 private: |
264 friend struct base::DefaultLazyInstanceTraits<SafeBrowsingServiceFactoryImpl>; | 264 friend struct base::DefaultLazyInstanceTraits<SafeBrowsingServiceFactoryImpl>; |
265 | 265 |
266 SafeBrowsingServiceFactoryImpl() { } | 266 SafeBrowsingServiceFactoryImpl() { } |
267 | 267 |
268 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceFactoryImpl); | 268 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceFactoryImpl); |
269 }; | 269 }; |
270 | 270 |
(...skipping 14 matching lines...) Expand all Loading... |
285 } | 285 } |
286 | 286 |
287 | 287 |
288 // static | 288 // static |
289 SafeBrowsingService* SafeBrowsingService::CreateSafeBrowsingService() { | 289 SafeBrowsingService* SafeBrowsingService::CreateSafeBrowsingService() { |
290 if (!factory_) | 290 if (!factory_) |
291 factory_ = g_safe_browsing_service_factory_impl.Pointer(); | 291 factory_ = g_safe_browsing_service_factory_impl.Pointer(); |
292 return factory_->CreateSafeBrowsingService(); | 292 return factory_->CreateSafeBrowsingService(); |
293 } | 293 } |
294 | 294 |
295 SafeBrowsingService::SafeBrowsingService( | 295 SafeBrowsingService::SafeBrowsingService() |
296 V4FeatureList::V4UsageStatus v4_usage_status) | |
297 : services_delegate_(ServicesDelegate::Create(this)), | 296 : services_delegate_(ServicesDelegate::Create(this)), |
298 estimated_extended_reporting_by_prefs_(SBER_LEVEL_OFF), | 297 estimated_extended_reporting_by_prefs_(SBER_LEVEL_OFF), |
299 enabled_(false), | 298 enabled_(false), |
300 enabled_by_prefs_(false), | 299 enabled_by_prefs_(false), |
301 use_v4_only_(v4_usage_status == V4FeatureList::V4UsageStatus::V4_ONLY), | 300 enabled_v4_only_(safe_browsing::V4FeatureList::IsV4OnlyEnabled()) {} |
302 v4_enabled_(v4_usage_status == | |
303 V4FeatureList::V4UsageStatus::V4_INSTANTIATED || | |
304 v4_usage_status == V4FeatureList::V4UsageStatus::V4_ONLY) {} | |
305 | 301 |
306 SafeBrowsingService::~SafeBrowsingService() { | 302 SafeBrowsingService::~SafeBrowsingService() { |
307 // We should have already been shut down. If we're still enabled, then the | 303 // We should have already been shut down. If we're still enabled, then the |
308 // database isn't going to be closed properly, which could lead to corruption. | 304 // database isn't going to be closed properly, which could lead to corruption. |
309 DCHECK(!enabled_); | 305 DCHECK(!enabled_); |
310 } | 306 } |
311 | 307 |
312 void SafeBrowsingService::Initialize() { | 308 void SafeBrowsingService::Initialize() { |
313 // Ensure FileTypePolicies's Singleton is instantiated during startup. | 309 // Ensure FileTypePolicies's Singleton is instantiated during startup. |
314 // This guarantees we'll log UMA metrics about its state. | 310 // This guarantees we'll log UMA metrics about its state. |
315 FileTypePolicies::GetInstance(); | 311 FileTypePolicies::GetInstance(); |
316 | 312 |
317 url_request_context_getter_ = new SafeBrowsingURLRequestContextGetter( | 313 url_request_context_getter_ = new SafeBrowsingURLRequestContextGetter( |
318 g_browser_process->system_request_context()); | 314 g_browser_process->system_request_context()); |
319 | 315 |
320 ui_manager_ = CreateUIManager(); | 316 ui_manager_ = CreateUIManager(); |
321 | 317 |
322 if (!use_v4_only_) { | 318 if (!enabled_v4_only_) { |
323 database_manager_ = CreateDatabaseManager(); | 319 database_manager_ = CreateDatabaseManager(); |
324 } | 320 } |
325 | 321 |
326 if (base::FeatureList::IsEnabled( | 322 if (base::FeatureList::IsEnabled( |
327 SafeBrowsingNavigationObserverManager::kDownloadAttribution)) { | 323 SafeBrowsingNavigationObserverManager::kDownloadAttribution)) { |
328 navigation_observer_manager_ = new SafeBrowsingNavigationObserverManager(); | 324 navigation_observer_manager_ = new SafeBrowsingNavigationObserverManager(); |
329 } | 325 } |
330 | 326 |
331 services_delegate_->Initialize(v4_enabled_); | 327 services_delegate_->Initialize(); |
332 services_delegate_->InitializeCsdService(url_request_context_getter_.get()); | 328 services_delegate_->InitializeCsdService(url_request_context_getter_.get()); |
333 | 329 |
334 // Track the safe browsing preference of existing profiles. | 330 // Track the safe browsing preference of existing profiles. |
335 // The SafeBrowsingService will be started if any existing profile has the | 331 // The SafeBrowsingService will be started if any existing profile has the |
336 // preference enabled. It will also listen for updates to the preferences. | 332 // preference enabled. It will also listen for updates to the preferences. |
337 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 333 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
338 if (profile_manager) { | 334 if (profile_manager) { |
339 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles(); | 335 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles(); |
340 // TODO(felt): I believe this for-loop is dead code. Confirm this and | 336 // TODO(felt): I believe this for-loop is dead code. Confirm this and |
341 // remove in a future CL. See https://codereview.chromium.org/1341533002/ | 337 // remove in a future CL. See https://codereview.chromium.org/1341533002/ |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 url_request_context_getter_->DisableQuicOnIOThread(); | 408 url_request_context_getter_->DisableQuicOnIOThread(); |
413 } | 409 } |
414 | 410 |
415 const scoped_refptr<SafeBrowsingUIManager>& | 411 const scoped_refptr<SafeBrowsingUIManager>& |
416 SafeBrowsingService::ui_manager() const { | 412 SafeBrowsingService::ui_manager() const { |
417 return ui_manager_; | 413 return ui_manager_; |
418 } | 414 } |
419 | 415 |
420 const scoped_refptr<SafeBrowsingDatabaseManager>& | 416 const scoped_refptr<SafeBrowsingDatabaseManager>& |
421 SafeBrowsingService::database_manager() const { | 417 SafeBrowsingService::database_manager() const { |
422 return use_v4_only_ ? v4_local_database_manager() : database_manager_; | 418 return enabled_v4_only_ ? v4_local_database_manager() : database_manager_; |
423 } | 419 } |
424 | 420 |
425 scoped_refptr<SafeBrowsingNavigationObserverManager> | 421 scoped_refptr<SafeBrowsingNavigationObserverManager> |
426 SafeBrowsingService::navigation_observer_manager() { | 422 SafeBrowsingService::navigation_observer_manager() { |
427 return navigation_observer_manager_; | 423 return navigation_observer_manager_; |
428 } | 424 } |
429 | 425 |
430 SafeBrowsingProtocolManager* SafeBrowsingService::protocol_manager() const { | 426 SafeBrowsingProtocolManager* SafeBrowsingService::protocol_manager() const { |
431 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 427 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
432 #if defined(SAFE_BROWSING_DB_LOCAL) | 428 #if defined(SAFE_BROWSING_DB_LOCAL) |
433 DCHECK(!use_v4_only_); | 429 DCHECK(!enabled_v4_only_); |
434 return protocol_manager_.get(); | 430 return protocol_manager_.get(); |
435 #else | 431 #else |
436 return nullptr; | 432 return nullptr; |
437 #endif | 433 #endif |
438 } | 434 } |
439 | 435 |
440 SafeBrowsingPingManager* SafeBrowsingService::ping_manager() const { | 436 SafeBrowsingPingManager* SafeBrowsingService::ping_manager() const { |
441 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 437 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
442 return ping_manager_.get(); | 438 return ping_manager_.get(); |
443 } | 439 } |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 #endif // defined(OS_WIN) | 549 #endif // defined(OS_WIN) |
554 | 550 |
555 return client_name; | 551 return client_name; |
556 } | 552 } |
557 | 553 |
558 // Any tests that create a DatabaseManager that isn't derived from | 554 // Any tests that create a DatabaseManager that isn't derived from |
559 // LocalSafeBrowsingDatabaseManager should override this to return NULL. | 555 // LocalSafeBrowsingDatabaseManager should override this to return NULL. |
560 SafeBrowsingProtocolManagerDelegate* | 556 SafeBrowsingProtocolManagerDelegate* |
561 SafeBrowsingService::GetProtocolManagerDelegate() { | 557 SafeBrowsingService::GetProtocolManagerDelegate() { |
562 #if defined(SAFE_BROWSING_DB_LOCAL) | 558 #if defined(SAFE_BROWSING_DB_LOCAL) |
563 DCHECK(!use_v4_only_); | 559 DCHECK(!enabled_v4_only_); |
564 return static_cast<LocalSafeBrowsingDatabaseManager*>( | 560 return static_cast<LocalSafeBrowsingDatabaseManager*>( |
565 database_manager_.get()); | 561 database_manager_.get()); |
566 #else | 562 #else |
567 NOTREACHED(); | 563 NOTREACHED(); |
568 return NULL; | 564 return NULL; |
569 #endif | 565 #endif |
570 } | 566 } |
571 | 567 |
572 void SafeBrowsingService::StartOnIOThread( | 568 void SafeBrowsingService::StartOnIOThread( |
573 net::URLRequestContextGetter* url_request_context_getter) { | 569 net::URLRequestContextGetter* url_request_context_getter) { |
574 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 570 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
575 if (enabled_) | 571 if (enabled_) |
576 return; | 572 return; |
577 enabled_ = true; | 573 enabled_ = true; |
578 | 574 |
579 SafeBrowsingProtocolConfig config = GetProtocolConfig(); | 575 SafeBrowsingProtocolConfig config = GetProtocolConfig(); |
580 V4ProtocolConfig v4_config = GetV4ProtocolConfig(); | 576 V4ProtocolConfig v4_config = GetV4ProtocolConfig(); |
581 | 577 |
582 services_delegate_->StartOnIOThread(url_request_context_getter, v4_config); | 578 services_delegate_->StartOnIOThread(url_request_context_getter, v4_config); |
583 | 579 |
584 #if defined(SAFE_BROWSING_DB_LOCAL) || defined(SAFE_BROWSING_DB_REMOTE) | 580 #if defined(SAFE_BROWSING_DB_LOCAL) || defined(SAFE_BROWSING_DB_REMOTE) |
585 if (!use_v4_only_) { | 581 if (!enabled_v4_only_) { |
586 DCHECK(database_manager_.get()); | 582 DCHECK(database_manager_.get()); |
587 database_manager_->StartOnIOThread(url_request_context_getter, v4_config); | 583 database_manager_->StartOnIOThread(url_request_context_getter, v4_config); |
588 } | 584 } |
589 #endif | 585 #endif |
590 | 586 |
591 #if defined(SAFE_BROWSING_DB_LOCAL) | 587 #if defined(SAFE_BROWSING_DB_LOCAL) |
592 if (!use_v4_only_) { | 588 if (!enabled_v4_only_) { |
593 SafeBrowsingProtocolManagerDelegate* protocol_manager_delegate = | 589 SafeBrowsingProtocolManagerDelegate* protocol_manager_delegate = |
594 GetProtocolManagerDelegate(); | 590 GetProtocolManagerDelegate(); |
595 if (protocol_manager_delegate) { | 591 if (protocol_manager_delegate) { |
596 protocol_manager_ = SafeBrowsingProtocolManager::Create( | 592 protocol_manager_ = SafeBrowsingProtocolManager::Create( |
597 protocol_manager_delegate, url_request_context_getter, config); | 593 protocol_manager_delegate, url_request_context_getter, config); |
598 protocol_manager_->Initialize(); | 594 protocol_manager_->Initialize(); |
599 } | 595 } |
600 } | 596 } |
601 #endif | 597 #endif |
602 | 598 |
603 DCHECK(!ping_manager_); | 599 DCHECK(!ping_manager_); |
604 ping_manager_ = SafeBrowsingPingManager::Create( | 600 ping_manager_ = SafeBrowsingPingManager::Create( |
605 url_request_context_getter, config); | 601 url_request_context_getter, config); |
606 } | 602 } |
607 | 603 |
608 void SafeBrowsingService::StopOnIOThread(bool shutdown) { | 604 void SafeBrowsingService::StopOnIOThread(bool shutdown) { |
609 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 605 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
610 | 606 |
611 #if defined(SAFE_BROWSING_DB_LOCAL) || defined(SAFE_BROWSING_DB_REMOTE) | 607 #if defined(SAFE_BROWSING_DB_LOCAL) || defined(SAFE_BROWSING_DB_REMOTE) |
612 if (!use_v4_only_) { | 608 if (!enabled_v4_only_) { |
613 database_manager_->StopOnIOThread(shutdown); | 609 database_manager_->StopOnIOThread(shutdown); |
614 } | 610 } |
615 #endif | 611 #endif |
616 ui_manager_->StopOnIOThread(shutdown); | 612 ui_manager_->StopOnIOThread(shutdown); |
617 | 613 |
618 services_delegate_->StopOnIOThread(shutdown); | 614 services_delegate_->StopOnIOThread(shutdown); |
619 | 615 |
620 if (enabled_) { | 616 if (enabled_) { |
621 enabled_ = false; | 617 enabled_ = false; |
622 | 618 |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
763 ping_manager()->ReportThreatDetails(report); | 759 ping_manager()->ReportThreatDetails(report); |
764 } | 760 } |
765 | 761 |
766 void SafeBrowsingService::ProcessResourceRequest( | 762 void SafeBrowsingService::ProcessResourceRequest( |
767 const ResourceRequestInfo& request) { | 763 const ResourceRequestInfo& request) { |
768 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 764 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
769 services_delegate_->ProcessResourceRequest(&request); | 765 services_delegate_->ProcessResourceRequest(&request); |
770 } | 766 } |
771 | 767 |
772 } // namespace safe_browsing | 768 } // namespace safe_browsing |
OLD | NEW |