| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 | 5 |
| 6 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 6 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 7 | 7 |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/histogram.h" | 9 #include "base/histogram.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 DCHECK(MessageLoop::current() == io_loop_); | 177 DCHECK(MessageLoop::current() == io_loop_); |
| 178 if (!enabled_ || !database_) | 178 if (!enabled_ || !database_) |
| 179 return true; | 179 return true; |
| 180 | 180 |
| 181 if (new_safe_browsing_) | 181 if (new_safe_browsing_) |
| 182 return CheckUrlNew(url, client); | 182 return CheckUrlNew(url, client); |
| 183 | 183 |
| 184 if (!resetting_) { | 184 if (!resetting_) { |
| 185 Time start_time = Time::Now(); | 185 Time start_time = Time::Now(); |
| 186 bool need_check = database_->NeedToCheckUrl(url); | 186 bool need_check = database_->NeedToCheckUrl(url); |
| 187 UMA_HISTOGRAM_TIMES(L"SB.BloomFilter", Time::Now() - start_time); | 187 UMA_HISTOGRAM_TIMES("SB.BloomFilter", Time::Now() - start_time); |
| 188 if (!need_check) | 188 if (!need_check) |
| 189 return true; // The url is definitely safe. | 189 return true; // The url is definitely safe. |
| 190 } | 190 } |
| 191 | 191 |
| 192 // The url may or may not be safe, need to go to the database to be sure. | 192 // The url may or may not be safe, need to go to the database to be sure. |
| 193 SafeBrowsingCheck* check = new SafeBrowsingCheck(); | 193 SafeBrowsingCheck* check = new SafeBrowsingCheck(); |
| 194 check->url = url; | 194 check->url = url; |
| 195 check->client = client; | 195 check->client = client; |
| 196 check->result = URL_SAFE; | 196 check->result = URL_SAFE; |
| 197 check->need_get_hash = false; | 197 check->need_get_hash = false; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 216 } | 216 } |
| 217 | 217 |
| 218 std::string list; | 218 std::string list; |
| 219 std::vector<SBPrefix> prefix_hits; | 219 std::vector<SBPrefix> prefix_hits; |
| 220 std::vector<SBFullHashResult> full_hits; | 220 std::vector<SBFullHashResult> full_hits; |
| 221 base::Time check_start = base::Time::Now(); | 221 base::Time check_start = base::Time::Now(); |
| 222 bool prefix_match = database_->ContainsUrl(url, &list, &prefix_hits, | 222 bool prefix_match = database_->ContainsUrl(url, &list, &prefix_hits, |
| 223 &full_hits, | 223 &full_hits, |
| 224 protocol_manager_->last_update()); | 224 protocol_manager_->last_update()); |
| 225 | 225 |
| 226 UMA_HISTOGRAM_TIMES(L"SB2.FilterCheck", base::Time::Now() - check_start); | 226 UMA_HISTOGRAM_TIMES("SB2.FilterCheck", base::Time::Now() - check_start); |
| 227 | 227 |
| 228 if (!prefix_match) | 228 if (!prefix_match) |
| 229 return true; // URL is okay. | 229 return true; // URL is okay. |
| 230 | 230 |
| 231 // Needs to be asynchronous, since we could be in the constructor of a | 231 // Needs to be asynchronous, since we could be in the constructor of a |
| 232 // ResourceDispatcherHost event handler which can't pause there. | 232 // ResourceDispatcherHost event handler which can't pause there. |
| 233 SafeBrowsingCheck* check = new SafeBrowsingCheck(); | 233 SafeBrowsingCheck* check = new SafeBrowsingCheck(); |
| 234 check->url = url; | 234 check->url = url; |
| 235 check->client = client; | 235 check->client = client; |
| 236 check->result = URL_SAFE; | 236 check->result = URL_SAFE; |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 } | 376 } |
| 377 | 377 |
| 378 void SafeBrowsingService::OnCheckDone(SafeBrowsingCheck* check) { | 378 void SafeBrowsingService::OnCheckDone(SafeBrowsingCheck* check) { |
| 379 DCHECK(MessageLoop::current() == io_loop_); | 379 DCHECK(MessageLoop::current() == io_loop_); |
| 380 | 380 |
| 381 // If we've been shutdown during the database lookup, this check will already | 381 // If we've been shutdown during the database lookup, this check will already |
| 382 // have been deleted (in OnIOShutdown). | 382 // have been deleted (in OnIOShutdown). |
| 383 if (!enabled_ || checks_.find(check) == checks_.end()) | 383 if (!enabled_ || checks_.find(check) == checks_.end()) |
| 384 return; | 384 return; |
| 385 | 385 |
| 386 UMA_HISTOGRAM_TIMES(L"SB.Database", Time::Now() - check->start); | 386 UMA_HISTOGRAM_TIMES("SB.Database", Time::Now() - check->start); |
| 387 if (check->client && check->need_get_hash) { | 387 if (check->client && check->need_get_hash) { |
| 388 // We have a partial match so we need to query Google for the full hash. | 388 // We have a partial match so we need to query Google for the full hash. |
| 389 // Clean up will happen in HandleGetHashResults. | 389 // Clean up will happen in HandleGetHashResults. |
| 390 | 390 |
| 391 // See if we have a GetHash request already in progress for this particular | 391 // See if we have a GetHash request already in progress for this particular |
| 392 // prefix. If so, we just append ourselves to the list of interested parties | 392 // prefix. If so, we just append ourselves to the list of interested parties |
| 393 // when the results arrive. We only do this for checks involving one prefix, | 393 // when the results arrive. We only do this for checks involving one prefix, |
| 394 // since that is the common case (multiple prefixes will issue the request | 394 // since that is the common case (multiple prefixes will issue the request |
| 395 // as normal). | 395 // as normal). |
| 396 if (check->prefix_hits.size() == 1) { | 396 if (check->prefix_hits.size() == 1) { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 void SafeBrowsingService::HandleGetHashResults( | 457 void SafeBrowsingService::HandleGetHashResults( |
| 458 SafeBrowsingCheck* check, | 458 SafeBrowsingCheck* check, |
| 459 const std::vector<SBFullHashResult>& full_hashes, | 459 const std::vector<SBFullHashResult>& full_hashes, |
| 460 bool can_cache) { | 460 bool can_cache) { |
| 461 if (checks_.find(check) == checks_.end()) | 461 if (checks_.find(check) == checks_.end()) |
| 462 return; | 462 return; |
| 463 | 463 |
| 464 DCHECK(enabled_); | 464 DCHECK(enabled_); |
| 465 | 465 |
| 466 if (new_safe_browsing_) | 466 if (new_safe_browsing_) |
| 467 UMA_HISTOGRAM_LONG_TIMES(L"SB2.Network", Time::Now() - check->start); | 467 UMA_HISTOGRAM_LONG_TIMES("SB2.Network", Time::Now() - check->start); |
| 468 else | 468 else |
| 469 UMA_HISTOGRAM_LONG_TIMES(L"SB.Network", Time::Now() - check->start); | 469 UMA_HISTOGRAM_LONG_TIMES("SB.Network", Time::Now() - check->start); |
| 470 | 470 |
| 471 std::vector<SBPrefix> prefixes = check->prefix_hits; | 471 std::vector<SBPrefix> prefixes = check->prefix_hits; |
| 472 OnHandleGetHashResults(check, full_hashes); // 'check' is deleted here. | 472 OnHandleGetHashResults(check, full_hashes); // 'check' is deleted here. |
| 473 | 473 |
| 474 if (can_cache) { | 474 if (can_cache) { |
| 475 if (!new_safe_browsing_) { | 475 if (!new_safe_browsing_) { |
| 476 db_thread_->message_loop()->PostTask(FROM_HERE, NewRunnableMethod( | 476 db_thread_->message_loop()->PostTask(FROM_HERE, NewRunnableMethod( |
| 477 this, &SafeBrowsingService::CacheHashResults, prefixes, full_hashes)); | 477 this, &SafeBrowsingService::CacheHashResults, prefixes, full_hashes)); |
| 478 } else if (database_) { | 478 } else if (database_) { |
| 479 // Cache the GetHash results in memory: | 479 // Cache the GetHash results in memory: |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 704 if (safe_browsing_util::IsMalwareList(list_name)) { | 704 if (safe_browsing_util::IsMalwareList(list_name)) { |
| 705 return URL_MALWARE; | 705 return URL_MALWARE; |
| 706 } | 706 } |
| 707 | 707 |
| 708 SB_DLOG(INFO) << "Unknown safe browsing list " << list_name; | 708 SB_DLOG(INFO) << "Unknown safe browsing list " << list_name; |
| 709 return URL_SAFE; | 709 return URL_SAFE; |
| 710 } | 710 } |
| 711 | 711 |
| 712 void SafeBrowsingService::LogPauseDelay(TimeDelta time) { | 712 void SafeBrowsingService::LogPauseDelay(TimeDelta time) { |
| 713 if (new_safe_browsing_) | 713 if (new_safe_browsing_) |
| 714 UMA_HISTOGRAM_LONG_TIMES(L"SB2.Delay", time); | 714 UMA_HISTOGRAM_LONG_TIMES("SB2.Delay", time); |
| 715 else | 715 else |
| 716 UMA_HISTOGRAM_LONG_TIMES(L"SB.Delay", time); | 716 UMA_HISTOGRAM_LONG_TIMES("SB.Delay", time); |
| 717 } | 717 } |
| 718 | 718 |
| 719 void SafeBrowsingService::CacheHashResults( | 719 void SafeBrowsingService::CacheHashResults( |
| 720 const std::vector<SBPrefix>& prefixes, | 720 const std::vector<SBPrefix>& prefixes, |
| 721 const std::vector<SBFullHashResult>& full_hashes) { | 721 const std::vector<SBFullHashResult>& full_hashes) { |
| 722 DCHECK(MessageLoop::current() == db_thread_->message_loop()); | 722 DCHECK(MessageLoop::current() == db_thread_->message_loop()); |
| 723 GetDatabase()->CacheHashResults(prefixes, full_hashes); | 723 GetDatabase()->CacheHashResults(prefixes, full_hashes); |
| 724 } | 724 } |
| 725 | 725 |
| 726 void SafeBrowsingService::OnSuspend(base::SystemMonitor*) { | 726 void SafeBrowsingService::OnSuspend(base::SystemMonitor*) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 741 DCHECK(MessageLoop::current() == db_thread_->message_loop()); | 741 DCHECK(MessageLoop::current() == db_thread_->message_loop()); |
| 742 // We don't call GetDatabase() here, since we want to avoid unnecessary calls | 742 // We don't call GetDatabase() here, since we want to avoid unnecessary calls |
| 743 // to Open, Reset, etc, or reload the bloom filter while we're coming out of | 743 // to Open, Reset, etc, or reload the bloom filter while we're coming out of |
| 744 // a suspended state. | 744 // a suspended state. |
| 745 if (database_) | 745 if (database_) |
| 746 database_->HandleResume(); | 746 database_->HandleResume(); |
| 747 } | 747 } |
| 748 | 748 |
| 749 void SafeBrowsingService::RunQueuedClients() { | 749 void SafeBrowsingService::RunQueuedClients() { |
| 750 DCHECK(MessageLoop::current() == io_loop_); | 750 DCHECK(MessageLoop::current() == io_loop_); |
| 751 HISTOGRAM_COUNTS(L"SB.QueueDepth", queued_checks_.size()); | 751 HISTOGRAM_COUNTS("SB.QueueDepth", queued_checks_.size()); |
| 752 while (!queued_checks_.empty()) { | 752 while (!queued_checks_.empty()) { |
| 753 QueuedCheck check = queued_checks_.front(); | 753 QueuedCheck check = queued_checks_.front(); |
| 754 HISTOGRAM_TIMES(L"SB.QueueDelay", Time::Now() - check.start); | 754 HISTOGRAM_TIMES("SB.QueueDelay", Time::Now() - check.start); |
| 755 CheckUrl(check.url, check.client); | 755 CheckUrl(check.url, check.client); |
| 756 queued_checks_.pop_front(); | 756 queued_checks_.pop_front(); |
| 757 } | 757 } |
| 758 } | 758 } |
| 759 | 759 |
| 760 void SafeBrowsingService::ReportMalware(const GURL& malware_url, | 760 void SafeBrowsingService::ReportMalware(const GURL& malware_url, |
| 761 const GURL& page_url, | 761 const GURL& page_url, |
| 762 const GURL& referrer_url) { | 762 const GURL& referrer_url) { |
| 763 DCHECK(MessageLoop::current() == io_loop_); | 763 DCHECK(MessageLoop::current() == io_loop_); |
| 764 | 764 |
| 765 // We need to access the database cache on the io_loop_ which is only allowed | 765 // We need to access the database cache on the io_loop_ which is only allowed |
| 766 // in the new SafeBrowsing database system. | 766 // in the new SafeBrowsing database system. |
| 767 if (!new_safe_browsing_ || !enabled_ || !database_) | 767 if (!new_safe_browsing_ || !enabled_ || !database_) |
| 768 return; | 768 return; |
| 769 | 769 |
| 770 // Check if 'page_url' is already blacklisted (exists in our cache). Only | 770 // Check if 'page_url' is already blacklisted (exists in our cache). Only |
| 771 // report if it's not there. | 771 // report if it's not there. |
| 772 std::string list; | 772 std::string list; |
| 773 std::vector<SBPrefix> prefix_hits; | 773 std::vector<SBPrefix> prefix_hits; |
| 774 std::vector<SBFullHashResult> full_hits; | 774 std::vector<SBFullHashResult> full_hits; |
| 775 database_->ContainsUrl(page_url, &list, &prefix_hits, &full_hits, | 775 database_->ContainsUrl(page_url, &list, &prefix_hits, &full_hits, |
| 776 protocol_manager_->last_update()); | 776 protocol_manager_->last_update()); |
| 777 | 777 |
| 778 if (full_hits.empty()) | 778 if (full_hits.empty()) |
| 779 protocol_manager_->ReportMalware(malware_url, page_url, referrer_url); | 779 protocol_manager_->ReportMalware(malware_url, page_url, referrer_url); |
| 780 } | 780 } |
| OLD | NEW |