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 12 matching lines...) Expand all Loading... |
23 #include "chrome/browser/safe_browsing/protocol_manager.h" | 23 #include "chrome/browser/safe_browsing/protocol_manager.h" |
24 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" | 24 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" |
25 #include "chrome/browser/safe_browsing/safe_browsing_database.h" | 25 #include "chrome/browser/safe_browsing/safe_browsing_database.h" |
26 #include "chrome/browser/tab_contents/tab_util.h" | 26 #include "chrome/browser/tab_contents/tab_util.h" |
27 #include "chrome/common/chrome_constants.h" | 27 #include "chrome/common/chrome_constants.h" |
28 #include "chrome/common/chrome_notification_types.h" | 28 #include "chrome/common/chrome_notification_types.h" |
29 #include "chrome/common/chrome_paths.h" | 29 #include "chrome/common/chrome_paths.h" |
30 #include "chrome/common/chrome_switches.h" | 30 #include "chrome/common/chrome_switches.h" |
31 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
32 #include "chrome/common/url_constants.h" | 32 #include "chrome/common/url_constants.h" |
| 33 #include "content/browser/browser_thread.h" |
33 #include "content/browser/tab_contents/tab_contents.h" | 34 #include "content/browser/tab_contents/tab_contents.h" |
34 #include "content/public/browser/notification_service.h" | 35 #include "content/public/browser/notification_service.h" |
35 #include "content/public/browser/notification_types.h" | 36 #include "content/public/browser/notification_types.h" |
36 #include "net/base/registry_controlled_domain.h" | 37 #include "net/base/registry_controlled_domain.h" |
37 #include "net/url_request/url_request_context_getter.h" | 38 #include "net/url_request/url_request_context_getter.h" |
38 | 39 |
39 #if defined(OS_WIN) | 40 #if defined(OS_WIN) |
40 #include "chrome/installer/util/browser_distribution.h" | 41 #include "chrome/installer/util/browser_distribution.h" |
41 #endif | 42 #endif |
42 | 43 |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 closing_database_(false), | 168 closing_database_(false), |
168 download_urlcheck_timeout_ms_(kDownloadUrlCheckTimeoutMs), | 169 download_urlcheck_timeout_ms_(kDownloadUrlCheckTimeoutMs), |
169 download_hashcheck_timeout_ms_(kDownloadHashCheckTimeoutMs) { | 170 download_hashcheck_timeout_ms_(kDownloadHashCheckTimeoutMs) { |
170 #if !defined(OS_CHROMEOS) | 171 #if !defined(OS_CHROMEOS) |
171 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 172 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
172 switches::kDisableClientSidePhishingDetection)) { | 173 switches::kDisableClientSidePhishingDetection)) { |
173 csd_service_.reset( | 174 csd_service_.reset( |
174 safe_browsing::ClientSideDetectionService::Create( | 175 safe_browsing::ClientSideDetectionService::Create( |
175 g_browser_process->system_request_context())); | 176 g_browser_process->system_request_context())); |
176 } | 177 } |
177 download_service_.reset(new safe_browsing::DownloadProtectionService( | 178 if (CommandLine::ForCurrentProcess()->HasSwitch( |
178 this, | 179 switches::kEnableImprovedDownloadProtection)) { |
179 g_browser_process->system_request_context())); | 180 download_service_ = new safe_browsing::DownloadProtectionService( |
| 181 this, |
| 182 g_browser_process->system_request_context()); |
| 183 } |
180 #endif | 184 #endif |
181 } | 185 } |
182 | 186 |
183 SafeBrowsingService::~SafeBrowsingService() { | 187 SafeBrowsingService::~SafeBrowsingService() { |
184 // Deletes the PrefChangeRegistrars, whose dtors also unregister |this| as an | 188 // Deletes the PrefChangeRegistrars, whose dtors also unregister |this| as an |
185 // observer of the preferences. | 189 // observer of the preferences. |
186 STLDeleteValues(&prefs_map_); | 190 STLDeleteValues(&prefs_map_); |
187 | 191 |
188 // We should have already been shut down. If we're still enabled, then the | 192 // We should have already been shut down. If we're still enabled, then the |
189 // database isn't going to be closed properly, which could lead to corruption. | 193 // database isn't going to be closed properly, which could lead to corruption. |
(...skipping 15 matching lines...) Expand all Loading... |
205 } | 209 } |
206 | 210 |
207 // Track profile creation and destruction. | 211 // Track profile creation and destruction. |
208 prefs_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CREATED, | 212 prefs_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CREATED, |
209 content::NotificationService::AllSources()); | 213 content::NotificationService::AllSources()); |
210 prefs_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, | 214 prefs_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
211 content::NotificationService::AllSources()); | 215 content::NotificationService::AllSources()); |
212 } | 216 } |
213 | 217 |
214 void SafeBrowsingService::ShutDown() { | 218 void SafeBrowsingService::ShutDown() { |
| 219 if (download_service_.get()) { |
| 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 } |
215 Stop(); | 228 Stop(); |
216 // The IO thread is going away, so make sure the ClientSideDetectionService | 229 // The IO thread is going away, so make sure the ClientSideDetectionService |
217 // dtor executes now since it may call the dtor of URLFetcher which relies | 230 // dtor executes now since it may call the dtor of URLFetcher which relies |
218 // on it. | 231 // on it. |
219 csd_service_.reset(); | 232 csd_service_.reset(); |
220 download_service_.reset(); | |
221 } | 233 } |
222 | 234 |
223 bool SafeBrowsingService::CanCheckUrl(const GURL& url) const { | 235 bool SafeBrowsingService::CanCheckUrl(const GURL& url) const { |
224 return url.SchemeIs(chrome::kFtpScheme) || | 236 return url.SchemeIs(chrome::kFtpScheme) || |
225 url.SchemeIs(chrome::kHttpScheme) || | 237 url.SchemeIs(chrome::kHttpScheme) || |
226 url.SchemeIs(chrome::kHttpsScheme); | 238 url.SchemeIs(chrome::kHttpsScheme); |
227 } | 239 } |
228 | 240 |
229 // Only report SafeBrowsing related stats when UMA is enabled. User must also | 241 // Only report SafeBrowsing related stats when UMA is enabled. User must also |
230 // ensure that safe browsing is enabled from the calling profile. | 242 // ensure that safe browsing is enabled from the calling profile. |
(...skipping 1118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1349 } | 1361 } |
1350 } | 1362 } |
1351 | 1363 |
1352 if (enable) | 1364 if (enable) |
1353 Start(); | 1365 Start(); |
1354 else | 1366 else |
1355 Stop(); | 1367 Stop(); |
1356 | 1368 |
1357 if (csd_service_.get()) | 1369 if (csd_service_.get()) |
1358 csd_service_->SetEnabledAndRefreshState(enable); | 1370 csd_service_->SetEnabledAndRefreshState(enable); |
1359 if (download_service_.get()) { | 1371 if (download_service_.get()) |
1360 download_service_->SetEnabled( | 1372 download_service_->SetEnabled(enable); |
1361 enable && CommandLine::ForCurrentProcess()->HasSwitch( | |
1362 switches::kEnableImprovedDownloadProtection)); | |
1363 } | |
1364 } | 1373 } |
OLD | NEW |