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

Side by Side Diff: chrome/browser/predictors/resource_prefetch_predictor_tables.h

Issue 2321343002: Redirect handling in resource prefetch predictor (Closed)
Patch Set: test 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_TABLES_H_ 5 #ifndef CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_TABLES_H_
6 #define CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_TABLES_H_ 6 #define CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_TABLES_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <map> 10 #include <map>
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 // Is the data a host as opposed to a Url? 91 // Is the data a host as opposed to a Url?
92 PrefetchKeyType key_type; // Not const to be able to assign. 92 PrefetchKeyType key_type; // Not const to be able to assign.
93 std::string primary_key; // is_host() ? main frame url : host. 93 std::string primary_key; // is_host() ? main frame url : host.
94 94
95 base::Time last_visit; 95 base::Time last_visit;
96 ResourceRows resources; 96 ResourceRows resources;
97 }; 97 };
98 // Map from primary key to PrefetchData for the key. 98 // Map from primary key to PrefetchData for the key.
99 typedef std::map<std::string, PrefetchData> PrefetchDataMap; 99 typedef std::map<std::string, PrefetchData> PrefetchDataMap;
100 100
101 struct RedirectStatRow {
102 RedirectStatRow();
103 RedirectStatRow(const RedirectStatRow& other);
104
105 std::string final_redirect;
106 size_t number_of_hits;
107 size_t number_of_misses;
108 size_t consecutive_misses;
109 };
110 typedef std::vector<RedirectStatRow> RedirectStatRows;
mattcary 2016/09/09 13:19:21 Would prefer not to typedef the vector. You don't
111
112 struct RedirectData {
113 RedirectData(PrefetchKeyType key_type, const std::string& primary_key);
114 RedirectData(const RedirectData& other);
115 ~RedirectData();
116
117 bool is_host() const { return key_type == PREFETCH_KEY_TYPE_HOST; }
118
119 PrefetchKeyType key_type;
120 std::string primary_key;
121 base::Time last_visit;
122 RedirectStatRows redirect_stats;
123 };
124 typedef std::map<std::string, RedirectData> RedirectDataMap;
125
101 // Returns data for all Urls and Hosts. 126 // Returns data for all Urls and Hosts.
102 virtual void GetAllData(PrefetchDataMap* url_data_map, 127 virtual void GetAllData(PrefetchDataMap* url_data_map,
103 PrefetchDataMap* host_data_map); 128 PrefetchDataMap* host_data_map,
129 RedirectDataMap* url_redirect_data_map,
130 RedirectDataMap* host_redirect_data_map);
104 131
105 // Updates data for a Url and a host. If either of the |url_data| or 132 // Updates data for a Url and a host. If either of the |url_data| or
106 // |host_data| has an empty primary key, it will be ignored. 133 // |host_data| has an empty primary key, it will be ignored.
107 // Note that the Urls and primary key in |url_data| and |host_data| should be 134 // Note that the Urls and primary key in |url_data| and |host_data| should be
108 // less than |kMaxStringLength| in length. 135 // less than |kMaxStringLength| in length.
109 virtual void UpdateData(const PrefetchData& url_data, 136 virtual void UpdatePrefetchData(const PrefetchData& url_data,
110 const PrefetchData& host_data); 137 const PrefetchData& host_data);
111 138
112 // Delete data for the input |urls| and |hosts|. 139 // Delete data for the input |urls| and |hosts|.
113 virtual void DeleteData(const std::vector<std::string>& urls, 140 virtual void DeleteData(const std::vector<std::string>& urls,
114 const std::vector<std::string>& hosts); 141 const std::vector<std::string>& hosts);
115 142
116 // Wrapper over DeleteData for convenience. 143 // Wrapper over DeleteData for convenience.
117 virtual void DeleteSingleDataPoint(const std::string& key, 144 virtual void DeleteSingleDataPoint(const std::string& key,
118 PrefetchKeyType key_type); 145 PrefetchKeyType key_type);
119 146
120 // Deletes all data in all the tables. 147 // Deletes all data in all the tables.
(...skipping 11 matching lines...) Expand all
132 DatabaseIsResetWhenIncompatible); 159 DatabaseIsResetWhenIncompatible);
133 160
134 ResourcePrefetchPredictorTables(); 161 ResourcePrefetchPredictorTables();
135 ~ResourcePrefetchPredictorTables() override; 162 ~ResourcePrefetchPredictorTables() override;
136 163
137 // Helper functions below help perform functions on the Url and host table 164 // Helper functions below help perform functions on the Url and host table
138 // using the same code. 165 // using the same code.
139 void GetAllDataHelper(PrefetchKeyType key_type, 166 void GetAllDataHelper(PrefetchKeyType key_type,
140 PrefetchDataMap* data_map, 167 PrefetchDataMap* data_map,
141 std::vector<std::string>* to_delete); 168 std::vector<std::string>* to_delete);
142 bool UpdateDataHelper(const PrefetchData& data); 169 bool UpdatePrefetchDataHelper(const PrefetchData& data);
143 void DeleteDataHelper(PrefetchKeyType key_type, 170 void DeleteDataHelper(PrefetchKeyType key_type,
144 const std::vector<std::string>& keys); 171 const std::vector<std::string>& keys);
145 172
146 // Returns true if the strings in the |data| are less than |kMaxStringLength| 173 // Returns true if the strings in the |data| are less than |kMaxStringLength|
147 // in length. 174 // in length.
148 static bool StringsAreSmallerThanDBLimit(const PrefetchData& data); 175 static bool StringsAreSmallerThanDBLimit(const PrefetchData& data);
176 static bool StringsAreSmallerThanDBLimit(const RedirectData& data);
149 177
150 // PredictorTableBase methods. 178 // PredictorTableBase methods.
151 void CreateTableIfNonExistent() override; 179 void CreateTableIfNonExistent() override;
152 void LogDatabaseStats() override; 180 void LogDatabaseStats() override;
153 181
154 // Database version. Always increment it when any change is made to the data 182 // Database version. Always increment it when any change is made to the data
155 // schema (including the .proto). 183 // schema (including the .proto).
156 static constexpr int kDatabaseVersion = 2; 184 static constexpr int kDatabaseVersion = 2;
157 185
158 static bool DropTablesIfOutdated(sql::Connection* db); 186 static bool DropTablesIfOutdated(sql::Connection* db);
(...skipping 11 matching lines...) Expand all
170 sql::Statement* GetHostResourceUpdateStatement(); 198 sql::Statement* GetHostResourceUpdateStatement();
171 sql::Statement* GetHostMetadataDeleteStatement(); 199 sql::Statement* GetHostMetadataDeleteStatement();
172 sql::Statement* GetHostMetadataUpdateStatement(); 200 sql::Statement* GetHostMetadataUpdateStatement();
173 201
174 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetchPredictorTables); 202 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetchPredictorTables);
175 }; 203 };
176 204
177 } // namespace predictors 205 } // namespace predictors
178 206
179 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_TABLES_H_ 207 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_TABLES_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698