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

Unified Diff: chrome/browser/predictors/resource_prefetch_predictor_tables.h

Issue 2796783004: predictors: Add origin learning. (Closed)
Patch Set: , Created 3 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
Index: chrome/browser/predictors/resource_prefetch_predictor_tables.h
diff --git a/chrome/browser/predictors/resource_prefetch_predictor_tables.h b/chrome/browser/predictors/resource_prefetch_predictor_tables.h
index ff9c5ea220f9be08f63e4a8f7477c862d644b032..522def9429d83e1dd418ab22865b89c3f9827902 100644
--- a/chrome/browser/predictors/resource_prefetch_predictor_tables.h
+++ b/chrome/browser/predictors/resource_prefetch_predictor_tables.h
@@ -41,20 +41,19 @@ class ResourcePrefetchPredictorTables : public PredictorTableBase {
typedef std::map<std::string, PrefetchData> PrefetchDataMap;
typedef std::map<std::string, RedirectData> RedirectDataMap;
typedef std::map<std::string, precache::PrecacheManifest> ManifestDataMap;
+ typedef std::map<std::string, OriginData> OriginDataMap;
// Returns data for all Urls and Hosts.
virtual void GetAllData(PrefetchDataMap* url_data_map,
PrefetchDataMap* host_data_map,
RedirectDataMap* url_redirect_data_map,
RedirectDataMap* host_redirect_data_map,
- ManifestDataMap* manifest_map);
+ ManifestDataMap* manifest_map,
+ OriginDataMap* origin_data_map);
- // Updates data for a Url and a host. If either of the |url_data| or
- // |host_data| or |url_redirect_data| or |host_redirect_data| has an empty
+ // Updates data for a Url and a host. If any of the arguments has an empty
// primary key, it will be ignored.
- // Note that the Urls and primary key in |url_data|, |host_data|,
- // |url_redirect_data| and |host_redirect_data| should be less than
- // |kMaxStringLength| in length.
+ // Note that all the keys should be less |kMaxStringLength| in length.
virtual void UpdateData(const PrefetchData& url_data,
const PrefetchData& host_data,
const RedirectData& url_redirect_data,
@@ -65,6 +64,9 @@ class ResourcePrefetchPredictorTables : public PredictorTableBase {
const std::string& host,
const precache::PrecacheManifest& manifest_data);
+ // Updates a given origin data point.
+ virtual void UpdateOriginData(const OriginData& origin_data);
+
// Delete data for the input |urls| and |hosts|.
virtual void DeleteResourceData(const std::vector<std::string>& urls,
const std::vector<std::string>& hosts);
@@ -84,6 +86,9 @@ class ResourcePrefetchPredictorTables : public PredictorTableBase {
// Delete data for the input |hosts|.
virtual void DeleteManifestData(const std::vector<std::string>& hosts);
+ // Deletes the origin data for a list of |hosts|.
+ virtual void DeleteOriginData(const std::vector<std::string>& hosts);
+
// Deletes all data in all the tables.
virtual void DeleteAllData();
@@ -101,6 +106,16 @@ class ResourcePrefetchPredictorTables : public PredictorTableBase {
// misses from |data|.
static void TrimRedirects(RedirectData* data, size_t max_consecutive_misses);
+ // Removes the origins with more than |max_consecutive_misses| consecutive
+ // misses from |data|.
+ static void TrimOrigins(OriginData* data, size_t max_consecutive_misses);
+
+ // Sorts the origins by score, decreasing.
+ static void SortOrigins(OriginData* data);
+
+ // Computes score of |data|.
+ static float ComputeOriginScore(const OriginStat& origin);
+
// The maximum length of the string that can be stored in the DB.
static constexpr size_t kMaxStringLength = 1024;
@@ -112,7 +127,7 @@ class ResourcePrefetchPredictorTables : public PredictorTableBase {
private:
// Represents the type of information that is stored in prefetch database.
- enum class PrefetchDataType { RESOURCE, REDIRECT, MANIFEST };
+ enum class PrefetchDataType { RESOURCE, REDIRECT, MANIFEST, ORIGIN };
enum class TableOperationType { INSERT, REMOVE };
@@ -124,7 +139,7 @@ class ResourcePrefetchPredictorTables : public PredictorTableBase {
// Database version. Always increment it when any change is made to the data
// schema (including the .proto).
- static constexpr int kDatabaseVersion = 6;
+ static constexpr int kDatabaseVersion = 7;
// Helper functions below help perform functions on the Url and host table
// using the same code.
@@ -133,6 +148,7 @@ class ResourcePrefetchPredictorTables : public PredictorTableBase {
void GetAllRedirectDataHelper(PrefetchKeyType key_type,
RedirectDataMap* redirect_map);
void GetAllManifestDataHelper(ManifestDataMap* manifest_map);
+ void GetAllOriginDataHelper(OriginDataMap* manifest_map);
bool UpdateDataHelper(PrefetchKeyType key_type,
PrefetchDataType data_type,

Powered by Google App Engine
This is Rietveld 408576698