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..70118b1f81354767a89c47029d66fa9a1c4ac597 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,23 @@ 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) |
+ : is_phishing(phish), |
+ timestamp(time) {} |
Brian Ryner
2011/02/08 20:16:48
The style guidelines discourage inlining construct
gcasto (DO NOT USE)
2011/02/09 00:10:52
Moved.
|
+ }; |
+ typedef std::map<GURL, linked_ptr<CacheState> > PhishingCache; |
+ |
static const char kClientReportPhishingUrl[]; |
static const char kClientModelUrl[]; |
static const int kMaxReportsPerDay; |
+ 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,6 +180,12 @@ class ClientSideDetectionService : public URLFetcher::Delegate { |
const ResponseCookies& cookies, |
const std::string& data); |
+ // Returns true and sets is_phishing if url is in the cache and valid. |
+ bool GetCachedResult(GURL url, bool* is_phishing); |
Brian Ryner
2011/02/08 20:16:48
Have this take a const GURL&, so that it doesn't n
gcasto (DO NOT USE)
2011/02/09 00:10:52
Done.
|
+ |
+ // Invalidate cache results which are no longer useful. |
+ void UpdateCache(); |
+ |
// Get the number of phishing reports that we have sent over the last 24 |
// hours. |
int GetNumReportsPerDay(); |
@@ -181,6 +202,12 @@ 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). |
+ // 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. |