OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 closing_database_(false), | 168 closing_database_(false), |
169 download_urlcheck_timeout_ms_(kDownloadUrlCheckTimeoutMs), | 169 download_urlcheck_timeout_ms_(kDownloadUrlCheckTimeoutMs), |
170 download_hashcheck_timeout_ms_(kDownloadHashCheckTimeoutMs) { | 170 download_hashcheck_timeout_ms_(kDownloadHashCheckTimeoutMs) { |
171 #if !defined(OS_CHROMEOS) | 171 #if !defined(OS_CHROMEOS) |
172 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 172 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
173 switches::kDisableClientSidePhishingDetection)) { | 173 switches::kDisableClientSidePhishingDetection)) { |
174 csd_service_.reset( | 174 csd_service_.reset( |
175 safe_browsing::ClientSideDetectionService::Create( | 175 safe_browsing::ClientSideDetectionService::Create( |
176 g_browser_process->system_request_context())); | 176 g_browser_process->system_request_context())); |
177 } | 177 } |
178 if (CommandLine::ForCurrentProcess()->HasSwitch( | 178 download_service_.reset(new safe_browsing::DownloadProtectionService( |
179 switches::kEnableImprovedDownloadProtection)) { | 179 this, |
180 download_service_ = new safe_browsing::DownloadProtectionService( | 180 g_browser_process->system_request_context())); |
181 this, | |
182 g_browser_process->system_request_context()); | |
183 } | |
184 #endif | 181 #endif |
185 } | 182 } |
186 | 183 |
187 SafeBrowsingService::~SafeBrowsingService() { | 184 SafeBrowsingService::~SafeBrowsingService() { |
| 185 ShutDownDownloadService(); |
| 186 |
188 // Deletes the PrefChangeRegistrars, whose dtors also unregister |this| as an | 187 // Deletes the PrefChangeRegistrars, whose dtors also unregister |this| as an |
189 // observer of the preferences. | 188 // observer of the preferences. |
190 STLDeleteValues(&prefs_map_); | 189 STLDeleteValues(&prefs_map_); |
191 | 190 |
192 // We should have already been shut down. If we're still enabled, then the | 191 // We should have already been shut down. If we're still enabled, then the |
193 // database isn't going to be closed properly, which could lead to corruption. | 192 // database isn't going to be closed properly, which could lead to corruption. |
194 DCHECK(!enabled_); | 193 DCHECK(!enabled_); |
195 } | 194 } |
196 | 195 |
197 void SafeBrowsingService::Initialize() { | 196 void SafeBrowsingService::Initialize() { |
(...skipping 11 matching lines...) Expand all Loading... |
209 } | 208 } |
210 | 209 |
211 // Track profile creation and destruction. | 210 // Track profile creation and destruction. |
212 prefs_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CREATED, | 211 prefs_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CREATED, |
213 content::NotificationService::AllSources()); | 212 content::NotificationService::AllSources()); |
214 prefs_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, | 213 prefs_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
215 content::NotificationService::AllSources()); | 214 content::NotificationService::AllSources()); |
216 } | 215 } |
217 | 216 |
218 void SafeBrowsingService::ShutDown() { | 217 void SafeBrowsingService::ShutDown() { |
219 if (download_service_.get()) { | 218 ShutDownDownloadService(); |
220 // Disabling the download service first will ensure that it is | |
221 // disabled before the SafeBrowsingService object becomes invalid. The | |
222 // download service might stay around for a bit since it's | |
223 // ref-counted but it won't do any harm because it will be | |
224 // disabled. | |
225 download_service_->SetEnabled(false); | |
226 download_service_ = NULL; | |
227 } | |
228 Stop(); | 219 Stop(); |
229 // The IO thread is going away, so make sure the ClientSideDetectionService | 220 // The IO thread is going away, so make sure the ClientSideDetectionService |
230 // dtor executes now since it may call the dtor of URLFetcher which relies | 221 // dtor executes now since it may call the dtor of URLFetcher which relies |
231 // on it. | 222 // on it. |
232 csd_service_.reset(); | 223 csd_service_.reset(); |
233 } | 224 } |
234 | 225 |
235 bool SafeBrowsingService::CanCheckUrl(const GURL& url) const { | 226 bool SafeBrowsingService::CanCheckUrl(const GURL& url) const { |
236 return url.SchemeIs(chrome::kFtpScheme) || | 227 return url.SchemeIs(chrome::kFtpScheme) || |
237 url.SchemeIs(chrome::kHttpScheme) || | 228 url.SchemeIs(chrome::kHttpScheme) || |
(...skipping 1123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1361 } | 1352 } |
1362 } | 1353 } |
1363 | 1354 |
1364 if (enable) | 1355 if (enable) |
1365 Start(); | 1356 Start(); |
1366 else | 1357 else |
1367 Stop(); | 1358 Stop(); |
1368 | 1359 |
1369 if (csd_service_.get()) | 1360 if (csd_service_.get()) |
1370 csd_service_->SetEnabledAndRefreshState(enable); | 1361 csd_service_->SetEnabledAndRefreshState(enable); |
1371 if (download_service_.get()) | 1362 if (download_service_.get()) { |
1372 download_service_->SetEnabled(enable); | 1363 download_service_->SetEnabled( |
| 1364 enable && CommandLine::ForCurrentProcess()->HasSwitch( |
| 1365 switches::kEnableImprovedDownloadProtection)); |
| 1366 } |
1373 } | 1367 } |
| 1368 |
| 1369 void SafeBrowsingService::ShutDownDownloadService() { |
| 1370 if (download_service_.get()) { |
| 1371 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, |
| 1372 download_service_.release()); |
| 1373 } |
| 1374 } |
OLD | NEW |