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