Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(376)

Unified Diff: chrome/browser/safe_browsing/protocol_manager.cc

Issue 220493003: Safebrowsing: change gethash caching to match api 2.3 rules, fix some corner cases. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase (including 227613008) Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/safe_browsing/protocol_manager.h ('k') | chrome/browser/safe_browsing/protocol_parser.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/safe_browsing/protocol_manager.cc
diff --git a/chrome/browser/safe_browsing/protocol_manager.cc b/chrome/browser/safe_browsing/protocol_manager.cc
index 5417835cc83d0206f8e381726cff6c8fee0af45d..57ed5d7293bdfd5ad96d5ce45222a7df9a652b5c 100644
--- a/chrome/browser/safe_browsing/protocol_manager.cc
+++ b/chrome/browser/safe_browsing/protocol_manager.cc
@@ -54,6 +54,10 @@ void RecordUpdateResult(UpdateResult result) {
} // namespace
+// The maximum staleness for a cached entry.
+// TODO(mattm): remove this when switching to Safebrowsing API 2.3.
+static const int kMaxStalenessMinutes = 45;
+
// Minimum time, in seconds, from start up before we must issue an update query.
static const int kSbTimerStartIntervalSecMin = 60;
@@ -173,7 +177,7 @@ void SafeBrowsingProtocolManager::GetFullHash(
if (gethash_error_count_ && Time::Now() <= next_gethash_time_) {
RecordGetHashResult(is_download, GET_HASH_BACKOFF_ERROR);
std::vector<SBFullHashResult> full_hashes;
- callback.Run(full_hashes, false);
+ callback.Run(full_hashes, base::TimeDelta());
return;
}
GURL gethash_url = GetHashUrl();
@@ -219,7 +223,7 @@ void SafeBrowsingProtocolManager::OnURLFetchComplete(
fetcher.reset(it->first);
const FullHashDetails& details = it->second;
std::vector<SBFullHashResult> full_hashes;
- bool can_cache = false;
+ base::TimeDelta cache_lifetime;
if (source->GetStatus().is_success() &&
(source->GetResponseCode() == 200 ||
source->GetResponseCode() == 204)) {
@@ -229,7 +233,9 @@ void SafeBrowsingProtocolManager::OnURLFetchComplete(
RecordGetHashResult(details.is_download, GET_HASH_STATUS_200);
else
RecordGetHashResult(details.is_download, GET_HASH_STATUS_204);
- can_cache = true;
+ // In SB 2.3, cache lifetime will be part of the protocol message. For
+ // now, use the old value of 45 minutes.
+ cache_lifetime = base::TimeDelta::FromMinutes(kMaxStalenessMinutes);
gethash_error_count_ = 0;
gethash_back_off_mult_ = 1;
SafeBrowsingProtocolParser parser;
@@ -242,7 +248,7 @@ void SafeBrowsingProtocolManager::OnURLFetchComplete(
if (!parsed_ok) {
full_hashes.clear();
RecordGetHashResult(details.is_download, GET_HASH_PARSE_ERROR);
- // TODO(cbentzel): Should can_cache be set to false here? (See
+ // TODO(cbentzel): Should cache_lifetime be set to 0 here? (See
// http://crbug.com/360232.)
}
} else {
@@ -261,7 +267,7 @@ void SafeBrowsingProtocolManager::OnURLFetchComplete(
// Invoke the callback with full_hashes, even if there was a parse error or
// an error response code (in which case full_hashes will be empty). The
// caller can't be blocked indefinitely.
- details.callback.Run(full_hashes, can_cache);
+ details.callback.Run(full_hashes, cache_lifetime);
hash_requests_.erase(it);
} else {
« no previous file with comments | « chrome/browser/safe_browsing/protocol_manager.h ('k') | chrome/browser/safe_browsing/protocol_parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698