| 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 <vector> | 7 #include <vector> | 
| 8 | 8 | 
| 9 #include "base/bind.h" | 9 #include "base/bind.h" | 
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" | 
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 213 | 213 | 
| 214   database_manager_ = CreateDatabaseManager(); | 214   database_manager_ = CreateDatabaseManager(); | 
| 215 | 215 | 
| 216   BrowserThread::PostTask( | 216   BrowserThread::PostTask( | 
| 217       BrowserThread::IO, FROM_HERE, | 217       BrowserThread::IO, FROM_HERE, | 
| 218       base::Bind( | 218       base::Bind( | 
| 219           &SafeBrowsingService::InitURLRequestContextOnIOThread, this, | 219           &SafeBrowsingService::InitURLRequestContextOnIOThread, this, | 
| 220           make_scoped_refptr(g_browser_process->system_request_context()))); | 220           make_scoped_refptr(g_browser_process->system_request_context()))); | 
| 221 | 221 | 
| 222 #if defined(FULL_SAFE_BROWSING) | 222 #if defined(FULL_SAFE_BROWSING) | 
| 223 #if !defined(OS_ANDROID) | 223 #if !defined(SAFE_BROWSING_CSD) | 
| 224   if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 224   if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 
| 225           switches::kDisableClientSidePhishingDetection)) { | 225           switches::kDisableClientSidePhishingDetection)) { | 
| 226     csd_service_.reset(safe_browsing::ClientSideDetectionService::Create( | 226     csd_service_.reset(safe_browsing::ClientSideDetectionService::Create( | 
| 227         url_request_context_getter_.get())); | 227         url_request_context_getter_.get())); | 
| 228   } | 228   } | 
|  | 229 #endif  // !defined(SAFE_BROWSING_CSD) | 
|  | 230 | 
|  | 231 // TODO(nparker): Adding SAFE_BROWSING_SERVICE_DOWNLOAD to control this might | 
|  | 232 // allow removing FULL_SAFE_BROWSING above. | 
|  | 233 #if !defined(OS_ANDROID) | 
| 229   download_service_.reset(new safe_browsing::DownloadProtectionService( | 234   download_service_.reset(new safe_browsing::DownloadProtectionService( | 
| 230       this, url_request_context_getter_.get())); | 235       this, url_request_context_getter_.get())); | 
| 231 #endif | 236 #endif | 
| 232 | 237 | 
| 233   if (IsIncidentReportingServiceEnabled()) { | 238   if (IsIncidentReportingServiceEnabled()) { | 
| 234     incident_service_.reset(new safe_browsing::IncidentReportingService( | 239     incident_service_.reset(new safe_browsing::IncidentReportingService( | 
| 235         this, url_request_context_getter_)); | 240         this, url_request_context_getter_)); | 
| 236     resource_request_detector_.reset(new safe_browsing::ResourceRequestDetector( | 241     resource_request_detector_.reset(new safe_browsing::ResourceRequestDetector( | 
| 237         incident_service_->GetIncidentReceiver())); | 242         incident_service_->GetIncidentReceiver())); | 
| 238   } | 243   } | 
| 239 | 244 | 
| 240   off_domain_inclusion_detector_.reset( | 245   off_domain_inclusion_detector_.reset( | 
| 241       new safe_browsing::OffDomainInclusionDetector(database_manager_)); | 246       new safe_browsing::OffDomainInclusionDetector(database_manager_)); | 
| 242 #endif | 247 #endif  // !defined(OS_ANDROID) | 
| 243 | 248 | 
| 244   // Track the safe browsing preference of existing profiles. | 249   // Track the safe browsing preference of existing profiles. | 
| 245   // The SafeBrowsingService will be started if any existing profile has the | 250   // The SafeBrowsingService will be started if any existing profile has the | 
| 246   // preference enabled. It will also listen for updates to the preferences. | 251   // preference enabled. It will also listen for updates to the preferences. | 
| 247   ProfileManager* profile_manager = g_browser_process->profile_manager(); | 252   ProfileManager* profile_manager = g_browser_process->profile_manager(); | 
| 248   if (profile_manager) { | 253   if (profile_manager) { | 
| 249     std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles(); | 254     std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles(); | 
| 250     for (size_t i = 0; i < profiles.size(); ++i) { | 255     for (size_t i = 0; i < profiles.size(); ++i) { | 
| 251       if (profiles[i]->IsOffTheRecord()) | 256       if (profiles[i]->IsOffTheRecord()) | 
| 252         continue; | 257         continue; | 
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 367   if (resource_request_detector_) | 372   if (resource_request_detector_) | 
| 368     resource_request_detector_->OnResourceRequest(request); | 373     resource_request_detector_->OnResourceRequest(request); | 
| 369 #endif | 374 #endif | 
| 370 } | 375 } | 
| 371 | 376 | 
| 372 SafeBrowsingUIManager* SafeBrowsingService::CreateUIManager() { | 377 SafeBrowsingUIManager* SafeBrowsingService::CreateUIManager() { | 
| 373   return new SafeBrowsingUIManager(this); | 378   return new SafeBrowsingUIManager(this); | 
| 374 } | 379 } | 
| 375 | 380 | 
| 376 SafeBrowsingDatabaseManager* SafeBrowsingService::CreateDatabaseManager() { | 381 SafeBrowsingDatabaseManager* SafeBrowsingService::CreateDatabaseManager() { | 
| 377 #if defined(FULL_SAFE_BROWSING) | 382 #if defined(SAFE_BROWSING_DB_LOCAL) | 
| 378   return new SafeBrowsingDatabaseManager(this); | 383   return new SafeBrowsingDatabaseManager(this); | 
| 379 #else | 384 #else | 
| 380   return NULL; | 385   return NULL; | 
| 381 #endif | 386 #endif | 
| 382 } | 387 } | 
| 383 | 388 | 
| 384 void SafeBrowsingService::RegisterAllDelayedAnalysis() { | 389 void SafeBrowsingService::RegisterAllDelayedAnalysis() { | 
| 385 #if defined(FULL_SAFE_BROWSING) | 390 #if defined(FULL_SAFE_BROWSING) | 
| 386   safe_browsing::RegisterBinaryIntegrityAnalysis(); | 391   safe_browsing::RegisterBinaryIntegrityAnalysis(); | 
| 387   safe_browsing::RegisterBlacklistLoadAnalysis(); | 392   safe_browsing::RegisterBlacklistLoadAnalysis(); | 
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 476   tracked_objects::ScopedTracker tracking_profile1( | 481   tracked_objects::ScopedTracker tracking_profile1( | 
| 477       FROM_HERE_WITH_EXPLICIT_FUNCTION( | 482       FROM_HERE_WITH_EXPLICIT_FUNCTION( | 
| 478           "455469 SafeBrowsingService::StartOnIOThread 1")); | 483           "455469 SafeBrowsingService::StartOnIOThread 1")); | 
| 479   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 484   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 
| 480   if (enabled_) | 485   if (enabled_) | 
| 481     return; | 486     return; | 
| 482   enabled_ = true; | 487   enabled_ = true; | 
| 483 | 488 | 
| 484   SafeBrowsingProtocolConfig config = GetProtocolConfig(); | 489   SafeBrowsingProtocolConfig config = GetProtocolConfig(); | 
| 485 | 490 | 
| 486 #if defined(FULL_SAFE_BROWSING) | 491 #if defined(SAFE_BROWSING_DB_LOCAL) | 
| 487   // TODO(pkasting): Remove ScopedTracker below once crbug.com/455469 is fixed. | 492   // TODO(pkasting): Remove ScopedTracker below once crbug.com/455469 is fixed. | 
| 488   tracked_objects::ScopedTracker tracking_profile2( | 493   tracked_objects::ScopedTracker tracking_profile2( | 
| 489       FROM_HERE_WITH_EXPLICIT_FUNCTION( | 494       FROM_HERE_WITH_EXPLICIT_FUNCTION( | 
| 490           "455469 SafeBrowsingService::StartOnIOThread 2")); | 495           "455469 SafeBrowsingService::StartOnIOThread 2")); | 
|  | 496 | 
| 491   DCHECK(database_manager_.get()); | 497   DCHECK(database_manager_.get()); | 
| 492   database_manager_->StartOnIOThread(); | 498   database_manager_->StartOnIOThread(); | 
| 493 | 499 | 
| 494   // TODO(pkasting): Remove ScopedTracker below once crbug.com/455469 is fixed. | 500   // TODO(pkasting): Remove ScopedTracker below once crbug.com/455469 is fixed. | 
| 495   tracked_objects::ScopedTracker tracking_profile3( | 501   tracked_objects::ScopedTracker tracking_profile3( | 
| 496       FROM_HERE_WITH_EXPLICIT_FUNCTION( | 502       FROM_HERE_WITH_EXPLICIT_FUNCTION( | 
| 497           "455469 SafeBrowsingService::StartOnIOThread 3")); | 503           "455469 SafeBrowsingService::StartOnIOThread 3")); | 
| 498   DCHECK(!protocol_manager_); | 504   DCHECK(!protocol_manager_); | 
| 499   protocol_manager_ = SafeBrowsingProtocolManager::Create( | 505   protocol_manager_ = SafeBrowsingProtocolManager::Create( | 
| 500       database_manager_.get(), url_request_context_getter, config); | 506       database_manager_.get(), url_request_context_getter, config); | 
| 501   protocol_manager_->Initialize(); | 507   protocol_manager_->Initialize(); | 
| 502 #endif | 508 #endif | 
| 503 | 509 | 
| 504   // TODO(pkasting): Remove ScopedTracker below once crbug.com/455469 is fixed. | 510   // TODO(pkasting): Remove ScopedTracker below once crbug.com/455469 is fixed. | 
| 505   tracked_objects::ScopedTracker tracking_profile4( | 511   tracked_objects::ScopedTracker tracking_profile4( | 
| 506       FROM_HERE_WITH_EXPLICIT_FUNCTION( | 512       FROM_HERE_WITH_EXPLICIT_FUNCTION( | 
| 507           "455469 SafeBrowsingService::StartOnIOThread 4")); | 513           "455469 SafeBrowsingService::StartOnIOThread 4")); | 
| 508   DCHECK(!ping_manager_); | 514   DCHECK(!ping_manager_); | 
| 509   ping_manager_ = SafeBrowsingPingManager::Create( | 515   ping_manager_ = SafeBrowsingPingManager::Create( | 
| 510       url_request_context_getter, config); | 516       url_request_context_getter, config); | 
| 511 } | 517 } | 
| 512 | 518 | 
| 513 void SafeBrowsingService::StopOnIOThread(bool shutdown) { | 519 void SafeBrowsingService::StopOnIOThread(bool shutdown) { | 
| 514   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 520   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 
| 515 | 521 | 
| 516 #if defined(FULL_SAFE_BROWSING) | 522 #if defined(SAFE_BROWSING_DB_LOCAL) | 
| 517   database_manager_->StopOnIOThread(shutdown); | 523   database_manager_->StopOnIOThread(shutdown); | 
| 518 #endif | 524 #endif | 
| 519   ui_manager_->StopOnIOThread(shutdown); | 525   ui_manager_->StopOnIOThread(shutdown); | 
| 520 | 526 | 
| 521   if (enabled_) { | 527   if (enabled_) { | 
| 522     enabled_ = false; | 528     enabled_ = false; | 
| 523 | 529 | 
| 524 #if defined(FULL_SAFE_BROWSING) | 530 #if defined(SAFE_BROWSING_DB_LOCAL) | 
| 525     // This cancels all in-flight GetHash requests. Note that database_manager_ | 531     // This cancels all in-flight GetHash requests. Note that database_manager_ | 
| 526     // relies on the protocol_manager_ so if the latter is destroyed, the | 532     // relies on the protocol_manager_ so if the latter is destroyed, the | 
| 527     // former must be stopped. | 533     // former must be stopped. | 
| 528     delete protocol_manager_; | 534     delete protocol_manager_; | 
| 529     protocol_manager_ = NULL; | 535     protocol_manager_ = NULL; | 
| 530 #endif | 536 #endif | 
| 531     delete ping_manager_; | 537     delete ping_manager_; | 
| 532     ping_manager_ = NULL; | 538     ping_manager_ = NULL; | 
| 533   } | 539   } | 
| 534 } | 540 } | 
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 613   else | 619   else | 
| 614     Stop(false); | 620     Stop(false); | 
| 615 | 621 | 
| 616 #if defined(FULL_SAFE_BROWSING) | 622 #if defined(FULL_SAFE_BROWSING) | 
| 617   if (csd_service_) | 623   if (csd_service_) | 
| 618     csd_service_->SetEnabledAndRefreshState(enable); | 624     csd_service_->SetEnabledAndRefreshState(enable); | 
| 619   if (download_service_) | 625   if (download_service_) | 
| 620     download_service_->SetEnabled(enable); | 626     download_service_->SetEnabled(enable); | 
| 621 #endif | 627 #endif | 
| 622 } | 628 } | 
| OLD | NEW | 
|---|