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

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

Issue 2268283005: predictors: Refactor the resource_prefetch_predictor database handling. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 4 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 62b9a5f48d00374d55b375c742841baa5d4ed588..3db828d6fc7d6743ce66b7089fc879d74a87f40b 100644
--- a/chrome/browser/predictors/resource_prefetch_predictor_tables.h
+++ b/chrome/browser/predictors/resource_prefetch_predictor_tables.h
@@ -39,49 +39,6 @@ using chrome_browser_predictors::ResourceData;
// - HostMetadataTable - misc data for hosts.
class ResourcePrefetchPredictorTables : public PredictorTableBase {
public:
- // Used in the UrlResourceTable and HostResourceTable to store resources
- // required for the page or host.
- struct ResourceRow {
- ResourceRow();
- ResourceRow(const ResourceRow& other);
- ResourceRow(const std::string& main_frame_url,
- const std::string& resource_url,
- content::ResourceType resource_type,
- int number_of_hits,
- int number_of_misses,
- int consecutive_misses,
- double average_position,
- net::RequestPriority priority,
- bool has_validators,
- bool always_revalidate);
- void UpdateScore();
- bool operator==(const ResourceRow& rhs) const;
- static void FromProto(const ResourceData& proto, ResourceRow* row);
- void ToProto(ResourceData* resource_data) const;
-
- // Stores the host for host based data, main frame Url for the Url based
- // data. This field is cleared for efficiency reasons and the code outside
- // this class should not assume it is set.
- std::string primary_key;
-
- GURL resource_url;
- content::ResourceType resource_type;
- size_t number_of_hits;
- size_t number_of_misses;
- size_t consecutive_misses;
- double average_position;
- net::RequestPriority priority;
- bool has_validators;
- bool always_revalidate;
-
- // Not stored.
- float score;
- };
- typedef std::vector<ResourceRow> ResourceRows;
-
- // Sorts the resource rows by score, decreasing.
- static void SortResourceRows(ResourceRows* 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
// it allows us to use the same functions.
@@ -89,7 +46,6 @@ class ResourcePrefetchPredictorTables : public PredictorTableBase {
PrefetchData(PrefetchKeyType key_type, const std::string& primary_key);
PrefetchData(const PrefetchData& other);
~PrefetchData();
- bool operator==(const PrefetchData& rhs) const;
bool is_host() const { return key_type == PREFETCH_KEY_TYPE_HOST; }
@@ -98,8 +54,15 @@ class ResourcePrefetchPredictorTables : public PredictorTableBase {
std::string primary_key; // is_host() ? main frame url : host.
base::Time last_visit;
- ResourceRows resources;
+ std::vector<ResourceData> resources;
};
+
+ // Sorts the resources by score, decreasing.
+ static void SortResources(std::vector<ResourceData>* resource);
+
+ // Updates the score of a resource.
+ static void UpdateResourceScore(ResourceData* resource);
+
// Map from primary key to PrefetchData for the key.
typedef std::map<std::string, PrefetchData> PrefetchDataMap;
@@ -116,7 +79,7 @@ class ResourcePrefetchPredictorTables : public PredictorTableBase {
// Delete data for the input |urls| and |hosts|.
virtual void DeleteData(const std::vector<std::string>& urls,
- const std::vector<std::string>& hosts);
+ const std::vector<std::string>& hosts);
// Wrapper over DeleteData for convenience.
virtual void DeleteSingleDataPoint(const std::string& key,
@@ -126,7 +89,7 @@ class ResourcePrefetchPredictorTables : public PredictorTableBase {
virtual void DeleteAllData();
// The maximum length of the string that can be stored in the DB.
- static const size_t kMaxStringLength;
+ static const size_t kMaxStringLength = 1024;
private:
friend class PredictorDatabaseInternal;
@@ -146,7 +109,7 @@ class ResourcePrefetchPredictorTables : public PredictorTableBase {
// Returns true if the strings in the |data| are less than |kMaxStringLength|
// in length.
- bool StringsAreSmallerThanDBLimit(const PrefetchData& data) const;
+ static bool StringsAreSmallerThanDBLimit(const PrefetchData& data);
// PredictorTableBase methods.
void CreateTableIfNonExistent() override;

Powered by Google App Engine
This is Rietveld 408576698