summaryrefslogtreecommitdiffstats
path: root/chrome/browser/safe_browsing/safe_browsing_database.cc
diff options
context:
space:
mode:
authorpaulg@google.com <paulg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-05 01:44:33 +0000
committerpaulg@google.com <paulg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-05 01:44:33 +0000
commit200abc3b412aa5129bca6c90cfe298b05ad547b2 (patch)
treee6ee185054384e5d70328de700bcedabef43920c /chrome/browser/safe_browsing/safe_browsing_database.cc
parent99f367cc966bff34742038d12580b8bad30b1ee0 (diff)
downloadchromium_src-200abc3b412aa5129bca6c90cfe298b05ad547b2.zip
chromium_src-200abc3b412aa5129bca6c90cfe298b05ad547b2.tar.gz
chromium_src-200abc3b412aa5129bca6c90cfe298b05ad547b2.tar.bz2
Cache empty responses from the SafeBrowsing servers for GetHash
requests so that we don't keep asking for full hashes that don't exist. We flush this cache with each update, which is a little aggressive, but on the safe side. BUG=1358225 Review URL: http://codereview.chromium.org/454 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1748 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/safe_browsing/safe_browsing_database.cc')
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_database.cc24
1 files changed, 24 insertions, 0 deletions
diff --git a/chrome/browser/safe_browsing/safe_browsing_database.cc b/chrome/browser/safe_browsing/safe_browsing_database.cc
index 0dea6e3..8a57559 100644
--- a/chrome/browser/safe_browsing/safe_browsing_database.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_database.cc
@@ -219,6 +219,7 @@ bool SafeBrowsingDatabase::CreateTables() {
// The SafeBrowsing service assumes this operation is synchronous.
bool SafeBrowsingDatabase::ResetDatabase() {
hash_cache_.clear();
+ prefix_miss_cache_.clear();
bool rv = Close();
DCHECK(rv);
@@ -295,6 +296,17 @@ bool SafeBrowsingDatabase::ContainsUrl(
}
if (!matching_list->empty() || !prefix_hits->empty()) {
+ // If all the prefixes are cached as 'misses', don't issue a GetHash.
+ bool all_misses = true;
+ for (std::vector<SBPrefix>::const_iterator it = prefix_hits->begin();
+ it != prefix_hits->end(); ++it) {
+ if (prefix_miss_cache_.find(*it) == prefix_miss_cache_.end()) {
+ all_misses = false;
+ break;
+ }
+ }
+ if (all_misses)
+ return false;
GetCachedFullHashes(prefix_hits, full_hits, last_update);
return true;
}
@@ -441,6 +453,7 @@ void SafeBrowsingDatabase::StartThrottledWork() {
}
void SafeBrowsingDatabase::RunThrottledWork() {
+ prefix_miss_cache_.clear();
while (true) {
bool done = ProcessChunks();
@@ -1183,7 +1196,18 @@ void SafeBrowsingDatabase::GetCachedFullHashes(
}
void SafeBrowsingDatabase::CacheHashResults(
+ const std::vector<SBPrefix>& prefixes,
const std::vector<SBFullHashResult>& full_hits) {
+ if (full_hits.empty()) {
+ // These prefixes returned no results, so we store them in order to prevent
+ // asking for them again. We flush this cache at the next update.
+ for (std::vector<SBPrefix>::const_iterator it = prefixes.begin();
+ it != prefixes.end(); ++it) {
+ prefix_miss_cache_.insert(*it);
+ }
+ return;
+ }
+
const Time now = Time::Now();
for (std::vector<SBFullHashResult>::const_iterator it = full_hits.begin();
it != full_hits.end(); ++it) {