Index: chrome/browser/safe_browsing/safe_browsing_service.cc |
=================================================================== |
--- chrome/browser/safe_browsing/safe_browsing_service.cc (revision 106761) |
+++ chrome/browser/safe_browsing/safe_browsing_service.cc (working copy) |
@@ -175,16 +175,15 @@ |
safe_browsing::ClientSideDetectionService::Create( |
g_browser_process->system_request_context())); |
} |
- if (CommandLine::ForCurrentProcess()->HasSwitch( |
- switches::kEnableImprovedDownloadProtection)) { |
- download_service_ = new safe_browsing::DownloadProtectionService( |
- this, |
- g_browser_process->system_request_context()); |
- } |
+ download_service_.reset(new safe_browsing::DownloadProtectionService( |
+ this, |
+ g_browser_process->system_request_context())); |
#endif |
} |
SafeBrowsingService::~SafeBrowsingService() { |
+ ShutDownDownloadService(); |
+ |
// Deletes the PrefChangeRegistrars, whose dtors also unregister |this| as an |
// observer of the preferences. |
STLDeleteValues(&prefs_map_); |
@@ -216,15 +215,7 @@ |
} |
void SafeBrowsingService::ShutDown() { |
- if (download_service_.get()) { |
- // Disabling the download service first will ensure that it is |
- // disabled before the SafeBrowsingService object becomes invalid. The |
- // download service might stay around for a bit since it's |
- // ref-counted but it won't do any harm because it will be |
- // disabled. |
- download_service_->SetEnabled(false); |
- download_service_ = NULL; |
- } |
+ ShutDownDownloadService(); |
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 |
@@ -1368,6 +1359,16 @@ |
if (csd_service_.get()) |
csd_service_->SetEnabledAndRefreshState(enable); |
- if (download_service_.get()) |
- download_service_->SetEnabled(enable); |
+ if (download_service_.get()) { |
+ download_service_->SetEnabled( |
+ enable && CommandLine::ForCurrentProcess()->HasSwitch( |
+ switches::kEnableImprovedDownloadProtection)); |
+ } |
} |
+ |
+void SafeBrowsingService::ShutDownDownloadService() { |
+ if (download_service_.get()) { |
+ BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, |
+ download_service_.release()); |
+ } |
+} |