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" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
13 #include "base/threading/thread_restrictions.h" | 13 #include "base/threading/thread_restrictions.h" |
14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
15 #include "chrome/browser/metrics/metrics_service.h" | 15 #include "chrome/browser/metrics/metrics_service.h" |
16 #include "chrome/browser/prefs/pref_change_registrar.h" | 16 #include "chrome/browser/prefs/pref_change_registrar.h" |
17 #include "chrome/browser/prefs/pref_service.h" | 17 #include "chrome/browser/prefs/pref_service.h" |
18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/profiles/profile_manager.h" | 19 #include "chrome/browser/profiles/profile_manager.h" |
| 20 #include "chrome/browser/safe_browsing/client_side_detection_service.h" |
20 #include "chrome/browser/safe_browsing/malware_details.h" | 21 #include "chrome/browser/safe_browsing/malware_details.h" |
21 #include "chrome/browser/safe_browsing/protocol_manager.h" | 22 #include "chrome/browser/safe_browsing/protocol_manager.h" |
22 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" | 23 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" |
23 #include "chrome/browser/safe_browsing/safe_browsing_database.h" | 24 #include "chrome/browser/safe_browsing/safe_browsing_database.h" |
24 #include "chrome/browser/tab_contents/tab_util.h" | 25 #include "chrome/browser/tab_contents/tab_util.h" |
25 #include "chrome/common/chrome_constants.h" | 26 #include "chrome/common/chrome_constants.h" |
26 #include "chrome/common/chrome_notification_types.h" | 27 #include "chrome/common/chrome_notification_types.h" |
27 #include "chrome/common/chrome_paths.h" | 28 #include "chrome/common/chrome_paths.h" |
28 #include "chrome/common/chrome_switches.h" | 29 #include "chrome/common/chrome_switches.h" |
29 #include "chrome/common/pref_names.h" | 30 #include "chrome/common/pref_names.h" |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 : database_(NULL), | 159 : database_(NULL), |
159 protocol_manager_(NULL), | 160 protocol_manager_(NULL), |
160 enabled_(false), | 161 enabled_(false), |
161 enable_download_protection_(false), | 162 enable_download_protection_(false), |
162 enable_csd_whitelist_(false), | 163 enable_csd_whitelist_(false), |
163 update_in_progress_(false), | 164 update_in_progress_(false), |
164 database_update_in_progress_(false), | 165 database_update_in_progress_(false), |
165 closing_database_(false), | 166 closing_database_(false), |
166 download_urlcheck_timeout_ms_(kDownloadUrlCheckTimeoutMs), | 167 download_urlcheck_timeout_ms_(kDownloadUrlCheckTimeoutMs), |
167 download_hashcheck_timeout_ms_(kDownloadHashCheckTimeoutMs) { | 168 download_hashcheck_timeout_ms_(kDownloadHashCheckTimeoutMs) { |
| 169 csd_service_ = g_browser_process->safe_browsing_detection_service(); |
| 170 } |
| 171 |
| 172 SafeBrowsingService::~SafeBrowsingService() { |
| 173 // Deletes the PrefChangeRegistrars, whose dtors also unregister |this| as an |
| 174 // observer of the preferences. |
| 175 STLDeleteValues(&prefs_map_); |
| 176 |
| 177 // We should have already been shut down. If we're still enabled, then the |
| 178 // database isn't going to be closed properly, which could lead to corruption. |
| 179 DCHECK(!enabled_); |
168 } | 180 } |
169 | 181 |
170 void SafeBrowsingService::Initialize() { | 182 void SafeBrowsingService::Initialize() { |
171 // Track the safe browsing preference of existing profiles. | 183 // Track the safe browsing preference of existing profiles. |
172 // The SafeBrowsingService will be started if any existing profile has the | 184 // The SafeBrowsingService will be started if any existing profile has the |
173 // preference enabled. It will also listen for updates to the preferences. | 185 // preference enabled. It will also listen for updates to the preferences. |
174 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 186 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
175 if (profile_manager) { | 187 if (profile_manager) { |
176 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles(); | 188 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles(); |
177 for (size_t i = 0; i < profiles.size(); ++i) { | 189 for (size_t i = 0; i < profiles.size(); ++i) { |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 486 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
475 DCHECK(enabled_); | 487 DCHECK(enabled_); |
476 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, NewRunnableMethod( | 488 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, NewRunnableMethod( |
477 this, &SafeBrowsingService::OnResetDatabase)); | 489 this, &SafeBrowsingService::OnResetDatabase)); |
478 } | 490 } |
479 | 491 |
480 void SafeBrowsingService::LogPauseDelay(base::TimeDelta time) { | 492 void SafeBrowsingService::LogPauseDelay(base::TimeDelta time) { |
481 UMA_HISTOGRAM_LONG_TIMES("SB2.Delay", time); | 493 UMA_HISTOGRAM_LONG_TIMES("SB2.Delay", time); |
482 } | 494 } |
483 | 495 |
484 SafeBrowsingService::~SafeBrowsingService() { | |
485 // Deletes the PrefChangeRegistrars, whose dtors also unregister |this| as an | |
486 // observer of the preferences. | |
487 STLDeleteValues(&prefs_map_); | |
488 | |
489 // We should have already been shut down. If we're still enabled, then the | |
490 // database isn't going to be closed properly, which could lead to corruption. | |
491 DCHECK(!enabled_); | |
492 } | |
493 | |
494 void SafeBrowsingService::OnIOInitialize( | 496 void SafeBrowsingService::OnIOInitialize( |
495 const std::string& client_key, | 497 const std::string& client_key, |
496 const std::string& wrapped_key, | 498 const std::string& wrapped_key, |
497 net::URLRequestContextGetter* request_context_getter) { | 499 net::URLRequestContextGetter* request_context_getter) { |
498 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 500 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
499 if (enabled_) | 501 if (enabled_) |
500 return; | 502 return; |
501 DCHECK(!safe_browsing_thread_.get()); | 503 DCHECK(!safe_browsing_thread_.get()); |
502 safe_browsing_thread_.reset(new base::Thread("Chrome_SafeBrowsingThread")); | 504 safe_browsing_thread_.reset(new base::Thread("Chrome_SafeBrowsingThread")); |
503 if (!safe_browsing_thread_->Start()) | 505 if (!safe_browsing_thread_->Start()) |
(...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1315 if (iter->first->GetBoolean(prefs::kSafeBrowsingEnabled)) { | 1317 if (iter->first->GetBoolean(prefs::kSafeBrowsingEnabled)) { |
1316 enable = true; | 1318 enable = true; |
1317 break; | 1319 break; |
1318 } | 1320 } |
1319 } | 1321 } |
1320 | 1322 |
1321 if (enable) | 1323 if (enable) |
1322 Start(); | 1324 Start(); |
1323 else | 1325 else |
1324 ShutDown(); | 1326 ShutDown(); |
| 1327 |
| 1328 if (csd_service_) |
| 1329 csd_service_->SetEnabled(enable); |
1325 } | 1330 } |
OLD | NEW |