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

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

Issue 2796783004: predictors: Add origin learning. (Closed)
Patch Set: Advancing our amazing database version number. 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..bf151da4bdfc78886c0891dbe9417f995240f927 100644
--- a/chrome/browser/predictors/resource_prefetch_predictor_tables.h
+++ b/chrome/browser/predictors/resource_prefetch_predictor_tables.h
@@ -9,6 +9,7 @@
#include <map>
#include <memory>
#include <string>
+#include <unordered_map>
#include <vector>
#include "base/gtest_prod_util.h"
@@ -26,6 +27,7 @@ namespace predictors {
// From resource_prefetch_predictor.proto.
using RedirectStat = RedirectData_RedirectStat;
+using OriginStat = OriginData_OriginStat;
// Interface for database tables used by the ResourcePrefetchPredictor.
// All methods except the constructor and destructor need to be called on the DB
@@ -38,23 +40,23 @@ using RedirectStat = RedirectData_RedirectStat;
// - HostRedirectTable - redirects per host.
class ResourcePrefetchPredictorTables : public PredictorTableBase {
public:
- typedef std::map<std::string, PrefetchData> PrefetchDataMap;
- typedef std::map<std::string, RedirectData> RedirectDataMap;
- typedef std::map<std::string, precache::PrecacheManifest> ManifestDataMap;
+ typedef std::unordered_map<std::string, PrefetchData> PrefetchDataMap;
alexilin 2017/04/10 14:58:28 Wow, this is a big change! Maybe for another CL? A
Benoit L 2017/04/11 09:04:05 I really dislike map<>, but unordered_map<> is not
+ typedef std::unordered_map<std::string, RedirectData> RedirectDataMap;
+ typedef std::unordered_map<std::string, precache::PrecacheManifest>
+ ManifestDataMap;
+ typedef std::unordered_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 +67,10 @@ class ResourcePrefetchPredictorTables : public PredictorTableBase {
const std::string& host,
const precache::PrecacheManifest& manifest_data);
+ // Updates the origin data for a given |host|.
+ virtual void UpdateOriginData(const std::string& host,
+ 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 +90,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 +110,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 +131,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 +143,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 +152,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