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

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 UMA stat for not being able to serialize request. 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
« no previous file with comments | « no previous file | chrome/browser/safe_browsing/client_side_detection_service.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.
« no previous file with comments | « no previous file | chrome/browser/safe_browsing/client_side_detection_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698