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