Index: chrome/browser/safe_browsing/safe_browsing_service.cc |
diff --git a/chrome/browser/safe_browsing/safe_browsing_service.cc b/chrome/browser/safe_browsing/safe_browsing_service.cc |
index cac584c5a29534107b6cd36011a7a0750ba3c38f..c8f1851d26bb6332e1d102ab06438361475e0122 100644 |
--- a/chrome/browser/safe_browsing/safe_browsing_service.cc |
+++ b/chrome/browser/safe_browsing/safe_browsing_service.cc |
@@ -17,6 +17,7 @@ |
#include "chrome/browser/prefs/pref_service.h" |
#include "chrome/browser/profiles/profile.h" |
#include "chrome/browser/profiles/profile_manager.h" |
+#include "chrome/browser/safe_browsing/client_side_detection_service.h" |
#include "chrome/browser/safe_browsing/malware_details.h" |
#include "chrome/browser/safe_browsing/protocol_manager.h" |
#include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" |
@@ -165,6 +166,25 @@ SafeBrowsingService::SafeBrowsingService() |
closing_database_(false), |
download_urlcheck_timeout_ms_(kDownloadUrlCheckTimeoutMs), |
download_hashcheck_timeout_ms_(kDownloadHashCheckTimeoutMs) { |
+#if !defined(OS_CHROMEOS) |
+ if (!CommandLine::ForCurrentProcess()->HasSwitch( |
+ switches::kDisableClientSidePhishingDetection) && |
+ CanReportStats()) { |
+ csd_service_.reset( |
+ safe_browsing::ClientSideDetectionService::Create( |
+ g_browser_process->system_request_context())); |
+ } |
+#endif |
+} |
+ |
+SafeBrowsingService::~SafeBrowsingService() { |
+ // Deletes the PrefChangeRegistrars, whose dtors also unregister |this| as an |
+ // observer of the preferences. |
+ STLDeleteValues(&prefs_map_); |
+ |
+ // We should have already been shut down. If we're still enabled, then the |
+ // database isn't going to be closed properly, which could lead to corruption. |
+ DCHECK(!enabled_); |
} |
void SafeBrowsingService::Initialize() { |
@@ -189,9 +209,11 @@ void SafeBrowsingService::Initialize() { |
} |
void SafeBrowsingService::ShutDown() { |
- BrowserThread::PostTask( |
- BrowserThread::IO, FROM_HERE, |
- NewRunnableMethod(this, &SafeBrowsingService::OnIOShutdown)); |
+ Stop(); |
+ // The IO thread is going away, so make sure the ClientSideDetectionService |
+ // dtor executes now since it may call the dtor of URLFetcher which relies |
+ // on it. |
+ csd_service_.reset(); |
} |
bool SafeBrowsingService::CanCheckUrl(const GURL& url) const { |
@@ -481,16 +503,6 @@ void SafeBrowsingService::LogPauseDelay(base::TimeDelta time) { |
UMA_HISTOGRAM_LONG_TIMES("SB2.Delay", time); |
} |
-SafeBrowsingService::~SafeBrowsingService() { |
- // Deletes the PrefChangeRegistrars, whose dtors also unregister |this| as an |
- // observer of the preferences. |
- STLDeleteValues(&prefs_map_); |
- |
- // We should have already been shut down. If we're still enabled, then the |
- // database isn't going to be closed properly, which could lead to corruption. |
- DCHECK(!enabled_); |
-} |
- |
void SafeBrowsingService::OnIOInitialize( |
const std::string& client_key, |
const std::string& wrapped_key, |
@@ -897,6 +909,12 @@ void SafeBrowsingService::Start() { |
request_context_getter)); |
} |
+void SafeBrowsingService::Stop() { |
+ BrowserThread::PostTask( |
+ BrowserThread::IO, FROM_HERE, |
+ NewRunnableMethod(this, &SafeBrowsingService::OnIOShutdown)); |
+} |
+ |
void SafeBrowsingService::OnCloseDatabase() { |
DCHECK_EQ(MessageLoop::current(), safe_browsing_thread_->message_loop()); |
DCHECK(closing_database_); |
@@ -1321,5 +1339,8 @@ void SafeBrowsingService::RefreshState() { |
if (enable) |
Start(); |
else |
- ShutDown(); |
+ Stop(); |
+ |
+ if (csd_service_.get()) |
+ csd_service_->SetEnabled(enable); |
} |