diff options
Diffstat (limited to 'chrome/browser/safe_browsing/safe_browsing_database.cc')
| -rw-r--r-- | chrome/browser/safe_browsing/safe_browsing_database.cc | 24 |
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) { |
