Index: chrome/browser/safe_browsing/client_side_detection_service.h |
diff --git a/chrome/browser/safe_browsing/client_side_detection_service.h b/chrome/browser/safe_browsing/client_side_detection_service.h |
index a9bc7f6966ddfb82ccc5d9ce970795b6ddc8ea58..252fc735f2fbe5bc322572374e6e3134cc55b81d 100644 |
--- a/chrome/browser/safe_browsing/client_side_detection_service.h |
+++ b/chrome/browser/safe_browsing/client_side_detection_service.h |
@@ -25,6 +25,7 @@ |
#include "base/callback.h" |
#include "base/file_path.h" |
#include "base/gtest_prod_util.h" |
+#include "base/linked_ptr.h" |
#include "base/platform_file.h" |
#include "base/ref_counted.h" |
#include "base/scoped_callback_factory.h" |
@@ -99,9 +100,22 @@ class ClientSideDetectionService : public URLFetcher::Delegate { |
ERROR_STATUS, |
}; |
+ // CacheState holds all information necessary to respond to a caller without |
+ // actually making a HTTP request. |
+ struct CacheState { |
+ bool is_phishing; |
+ base::Time timestamp; |
+ |
+ CacheState(bool phish, base::Time time); |
+ }; |
+ typedef std::map<GURL, linked_ptr<CacheState> > PhishingCache; |
+ |
static const char kClientReportPhishingUrl[]; |
static const char kClientModelUrl[]; |
- static const int kMaxReportsPerDay; |
+ static const int kMaxReportsPerInterval; |
+ static const base::TimeDelta kReportsInterval; |
+ static const base::TimeDelta kNegativeCacheInterval; |
+ static const base::TimeDelta kPositiveCacheInterval; |
// Use Create() method to create an instance of this object. |
ClientSideDetectionService(const FilePath& model_path, |
@@ -165,9 +179,14 @@ class ClientSideDetectionService : public URLFetcher::Delegate { |
const ResponseCookies& cookies, |
const std::string& data); |
- // Get the number of phishing reports that we have sent over the last 24 |
- // hours. |
- int GetNumReportsPerDay(); |
+ // Returns true and sets is_phishing if url is in the cache and valid. |
+ bool GetCachedResult(const GURL& url, bool* is_phishing); |
+ |
+ // Invalidate cache results which are no longer useful. |
+ void UpdateCache(); |
+ |
+ // Get the number of phishing reports that we have sent over kReportsInterval |
+ int GetNumReports(); |
FilePath model_path_; |
ModelStatus model_status_; |
@@ -181,6 +200,14 @@ class ClientSideDetectionService : public URLFetcher::Delegate { |
struct ClientReportInfo; |
std::map<const URLFetcher*, ClientReportInfo*> client_phishing_reports_; |
+ // Cache of completed requests. Used to satisfy requests for the same urls |
+ // as long as the next request falls within our caching window (which is |
+ // determined by kNegativeCacheInterval and kPositiveCacheInterval). The |
+ // size of this cache is limited by kMaxReportsPerDay * |
+ // ceil(InDays(max(kNegativeCacheInterval, kPositiveCacheInterval))). |
+ // TODO(gcasto): Serialize this so that it doesn't reset on browser restart. |
+ PhishingCache cache_; |
+ |
// Timestamp of when we sent a phishing request. Used to limit the number |
// of phishing requests that we send in a day. |
// TODO(gcasto): Serialize this so that it doesn't reset on browser restart. |