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

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

Issue 2321343002: Redirect handling in resource prefetch predictor (Closed)
Patch Set: Update some comments Created 4 years, 3 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 953c23f1c553437fb7354050c2bc7bb7b3a2c521..02776949c34e6c21073b9ab08b0d01344d120b70 100644
--- a/chrome/browser/predictors/resource_prefetch_predictor_tables.h
+++ b/chrome/browser/predictors/resource_prefetch_predictor_tables.h
@@ -28,6 +28,7 @@ class Statement;
namespace predictors {
using chrome_browser_predictors::ResourceData;
+using chrome_browser_predictors::RedirectStat;
// Interface for database tables used by the ResourcePrefetchPredictor.
// All methods except the constructor and destructor need to be called on the DB
@@ -35,9 +36,13 @@ using chrome_browser_predictors::ResourceData;
//
// Currently manages:
// - UrlResourceTable - resources per Urls.
-// - UrlMetadataTable - misc data for Urls (like last visit time).
+// - UrlResourceMetadataTable - misc data for Urls (like last visit time).
+// - UrlRedirectTable - redirects per Urls.
+// - UrlRedirectMetadataTable - misc data for redirected Urls.
// - HostResourceTable - resources per host.
-// - HostMetadataTable - misc data for hosts.
+// - HostResourceMetadataTable - misc data for hosts.
+// - HostRedirectTable - redirects per host.
+// - HostRedirectMetadataTable - misc data for redirecte hosts.
class ResourcePrefetchPredictorTables : public PredictorTableBase {
public:
// Used in the UrlResourceTable and HostResourceTable to store resources
@@ -72,10 +77,9 @@ class ResourcePrefetchPredictorTables : public PredictorTableBase {
// Not stored.
float score;
};
- typedef std::vector<ResourceRow> ResourceRows;
// Sorts the resource rows by score, decreasing.
- static void SortResourceRows(ResourceRows* rows);
+ static void SortResourceRows(std::vector<ResourceRow>* rows);
// Aggregated data for a Url or Host. Although the data differs slightly, we
// store them in the same structure, because most of the fields are common and
@@ -93,29 +97,86 @@ class ResourcePrefetchPredictorTables : public PredictorTableBase {
std::string primary_key; // is_host() ? main frame url : host.
base::Time last_visit;
- ResourceRows resources;
+ std::vector<ResourceRow> resources;
};
// Map from primary key to PrefetchData for the key.
typedef std::map<std::string, PrefetchData> PrefetchDataMap;
+ // Used in the UrlRedirectTable and HostRedirectTable to store redirects
+ // required for the page or host.
+ struct RedirectRow {
+ RedirectRow();
+ RedirectRow(const RedirectRow& other);
+ RedirectRow(const std::string& final_redirect,
+ size_t number_of_hits,
+ size_t number_of_misses,
+ size_t consecutive_misses);
+ void UpdateScore();
+ bool operator==(const RedirectRow& rhs) const;
+ static void FromProto(const RedirectStat& proto, RedirectRow* row);
+ void ToProto(RedirectStat* redirect_data) const;
+
+ std::string final_redirect;
+ size_t number_of_hits;
+ size_t number_of_misses;
+ size_t consecutive_misses;
+
+ // Not stored.
+ float score;
+ };
+
+ // Sorts the redirect rows by score, decreasing.
+ static void SortRedirectRows(std::vector<RedirectRow>* rows);
+
+ // Aggregated data about redirections for a Url or Host.
+ struct RedirectData {
+ RedirectData(PrefetchKeyType key_type, const std::string& primary_key);
+ RedirectData(const RedirectData& other);
+ ~RedirectData();
+ bool operator==(const RedirectData& rhs) const;
+
+ bool is_host() const { return key_type == PREFETCH_KEY_TYPE_HOST; }
+
+ PrefetchKeyType key_type;
+ std::string primary_key;
+ base::Time last_visit;
+ std::vector<RedirectRow> redirects;
+ };
+ // Map from primary key to RedirectData for the key.
+ typedef std::map<std::string, RedirectData> RedirectDataMap;
+
// Returns data for all Urls and Hosts.
virtual void GetAllData(PrefetchDataMap* url_data_map,
- PrefetchDataMap* host_data_map);
+ PrefetchDataMap* host_data_map,
+ RedirectDataMap* url_redirect_data_map,
+ RedirectDataMap* host_redirect_data_map);
// Updates data for a Url and a host. If either of the |url_data| or
- // |host_data| has an empty primary key, it will be ignored.
- // Note that the Urls and primary key in |url_data| and |host_data| should be
- // less than |kMaxStringLength| in length.
+ // |host_data| or |url_redirect_data| or |host_redirect_data| 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.
virtual void UpdateData(const PrefetchData& url_data,
- const PrefetchData& host_data);
+ const PrefetchData& host_data,
+ const RedirectData& url_redirect_data,
+ const RedirectData& host_redirect_data);
// Delete data for the input |urls| and |hosts|.
- virtual void DeleteData(const std::vector<std::string>& urls,
- const std::vector<std::string>& hosts);
+ virtual void DeleteResourceData(const std::vector<std::string>& urls,
+ const std::vector<std::string>& hosts);
- // Wrapper over DeleteData for convenience.
- virtual void DeleteSingleDataPoint(const std::string& key,
- PrefetchKeyType key_type);
+ // Wrapper over DeleteResourceData for convenience.
+ virtual void DeleteSingleResourceDataPoint(const std::string& key,
+ PrefetchKeyType key_type);
+
+ // Delete data for the input |urls| and |hosts|.
+ virtual void DeleteRedirectData(const std::vector<std::string>& urls,
+ const std::vector<std::string>& hosts);
+
+ // Wrapper over DeleteRedirectData for convenience.
+ virtual void DeleteSingleRedirectDataPoint(const std::string& key,
+ PrefetchKeyType key_type);
// Deletes all data in all the tables.
virtual void DeleteAllData();
@@ -139,13 +200,20 @@ class ResourcePrefetchPredictorTables : public PredictorTableBase {
void GetAllDataHelper(PrefetchKeyType key_type,
PrefetchDataMap* data_map,
std::vector<std::string>* to_delete);
+ void GetAllDataHelper(PrefetchKeyType key_type,
+ RedirectDataMap* redirect_map,
+ std::vector<std::string>* to_delete);
bool UpdateDataHelper(const PrefetchData& data);
- void DeleteDataHelper(PrefetchKeyType key_type,
- const std::vector<std::string>& keys);
+ bool UpdateDataHelper(const RedirectData& data);
+ void DeleteResourceDataHelper(PrefetchKeyType key_type,
+ const std::vector<std::string>& keys);
+ void DeleteRedirectDataHelper(PrefetchKeyType key_type,
+ const std::vector<std::string>& keys);
// Returns true if the strings in the |data| are less than |kMaxStringLength|
// in length.
static bool StringsAreSmallerThanDBLimit(const PrefetchData& data);
+ static bool StringsAreSmallerThanDBLimit(const RedirectData& data);
// PredictorTableBase methods.
void CreateTableIfNonExistent() override;
@@ -153,7 +221,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 = 2;
+ static constexpr int kDatabaseVersion = 3;
static bool DropTablesIfOutdated(sql::Connection* db);
static int GetDatabaseVersion(sql::Connection* db);
@@ -163,13 +231,21 @@ class ResourcePrefetchPredictorTables : public PredictorTableBase {
// ownership of the return Statements.
sql::Statement* GetUrlResourceDeleteStatement();
sql::Statement* GetUrlResourceUpdateStatement();
- sql::Statement* GetUrlMetadataDeleteStatement();
- sql::Statement* GetUrlMetadataUpdateStatement();
+ sql::Statement* GetUrlResourceMetadataDeleteStatement();
+ sql::Statement* GetUrlResourceMetadataUpdateStatement();
+ sql::Statement* GetUrlRedirectDeleteStatement();
+ sql::Statement* GetUrlRedirectUpdateStatement();
+ sql::Statement* GetUrlRedirectMetadataDeleteStatement();
+ sql::Statement* GetUrlRedirectMetadataUpdateStatement();
sql::Statement* GetHostResourceDeleteStatement();
sql::Statement* GetHostResourceUpdateStatement();
- sql::Statement* GetHostMetadataDeleteStatement();
- sql::Statement* GetHostMetadataUpdateStatement();
+ sql::Statement* GetHostResourceMetadataDeleteStatement();
+ sql::Statement* GetHostResourceMetadataUpdateStatement();
+ sql::Statement* GetHostRedirectDeleteStatement();
+ sql::Statement* GetHostRedirectUpdateStatement();
+ sql::Statement* GetHostRedirectMetadataDeleteStatement();
+ sql::Statement* GetHostRedirectMetadataUpdateStatement();
DISALLOW_COPY_AND_ASSIGN(ResourcePrefetchPredictorTables);
};

Powered by Google App Engine
This is Rietveld 408576698