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

Unified Diff: chrome/browser/safe_browsing/client_side_detection_service.h

Issue 6374017: Add caching to phishing client side detection. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Add testing for cache refresh. Also make interval that we keep track of requests configurable. Created 9 years, 10 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
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..292b74263a3b68bc6939697f2f7d03f9d25eeea1 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 kMaxReports;
Brian Ryner 2011/02/09 23:46:42 Maybe call this "kMaxReportPerInterval" to make it
gcasto (DO NOT USE) 2011/02/10 19:28:34 Done.
+ 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,15 @@ 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))).
+ // Currently this value is 3.
Brian Ryner 2011/02/09 23:46:42 It might be better to avoid mentioning the specifi
gcasto (DO NOT USE) 2011/02/10 19:28:34 Done.
+ // 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.

Powered by Google App Engine
This is Rietveld 408576698