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

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

Issue 2287473002: predictors: Remove unused field from the resource_prefetch_predictor database. (Closed)
Patch Set: Rebase. 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 27 matching lines...) Expand all
38 // - UrlMetadataTable - misc data for Urls (like last visit time). 38 // - UrlMetadataTable - misc data for Urls (like last visit time).
39 // - HostResourceTable - resources per host. 39 // - HostResourceTable - resources per host.
40 // - HostMetadataTable - misc data for hosts. 40 // - HostMetadataTable - misc data for hosts.
41 class ResourcePrefetchPredictorTables : public PredictorTableBase { 41 class ResourcePrefetchPredictorTables : public PredictorTableBase {
42 public: 42 public:
43 // Used in the UrlResourceTable and HostResourceTable to store resources 43 // Used in the UrlResourceTable and HostResourceTable to store resources
44 // required for the page or host. 44 // required for the page or host.
45 struct ResourceRow { 45 struct ResourceRow {
46 ResourceRow(); 46 ResourceRow();
47 ResourceRow(const ResourceRow& other); 47 ResourceRow(const ResourceRow& other);
48 ResourceRow(const std::string& main_frame_url, 48 ResourceRow(const std::string& resource_url,
49 const std::string& resource_url,
50 content::ResourceType resource_type, 49 content::ResourceType resource_type,
51 int number_of_hits, 50 int number_of_hits,
52 int number_of_misses, 51 int number_of_misses,
53 int consecutive_misses, 52 int consecutive_misses,
54 double average_position, 53 double average_position,
55 net::RequestPriority priority, 54 net::RequestPriority priority,
56 bool has_validators, 55 bool has_validators,
57 bool always_revalidate); 56 bool always_revalidate);
58 void UpdateScore(); 57 void UpdateScore();
59 bool operator==(const ResourceRow& rhs) const; 58 bool operator==(const ResourceRow& rhs) const;
60 static void FromProto(const ResourceData& proto, ResourceRow* row); 59 static void FromProto(const ResourceData& proto, ResourceRow* row);
61 void ToProto(ResourceData* resource_data) const; 60 void ToProto(ResourceData* resource_data) const;
62 61
63 // Stores the host for host based data, main frame Url for the Url based
64 // data. This field is cleared for efficiency reasons and the code outside
65 // this class should not assume it is set.
66 std::string primary_key;
67
68 GURL resource_url; 62 GURL resource_url;
69 content::ResourceType resource_type; 63 content::ResourceType resource_type;
70 size_t number_of_hits; 64 size_t number_of_hits;
71 size_t number_of_misses; 65 size_t number_of_misses;
72 size_t consecutive_misses; 66 size_t consecutive_misses;
73 double average_position; 67 double average_position;
74 net::RequestPriority priority; 68 net::RequestPriority priority;
75 bool has_validators; 69 bool has_validators;
76 bool always_revalidate; 70 bool always_revalidate;
77 71
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 const std::vector<std::string>& hosts); 114 const std::vector<std::string>& hosts);
121 115
122 // Wrapper over DeleteData for convenience. 116 // Wrapper over DeleteData for convenience.
123 virtual void DeleteSingleDataPoint(const std::string& key, 117 virtual void DeleteSingleDataPoint(const std::string& key,
124 PrefetchKeyType key_type); 118 PrefetchKeyType key_type);
125 119
126 // Deletes all data in all the tables. 120 // Deletes all data in all the tables.
127 virtual void DeleteAllData(); 121 virtual void DeleteAllData();
128 122
129 // The maximum length of the string that can be stored in the DB. 123 // The maximum length of the string that can be stored in the DB.
130 static const size_t kMaxStringLength; 124 static constexpr size_t kMaxStringLength = 1024;
131 125
132 private: 126 private:
133 friend class PredictorDatabaseInternal; 127 friend class PredictorDatabaseInternal;
134 friend class MockResourcePrefetchPredictorTables; 128 friend class MockResourcePrefetchPredictorTables;
135 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTablesTest, 129 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTablesTest,
136 DatabaseVersionIsSet); 130 DatabaseVersionIsSet);
137 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTablesTest, 131 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTablesTest,
138 DatabaseIsResetWhenIncompatible); 132 DatabaseIsResetWhenIncompatible);
139 133
140 ResourcePrefetchPredictorTables(); 134 ResourcePrefetchPredictorTables();
141 ~ResourcePrefetchPredictorTables() override; 135 ~ResourcePrefetchPredictorTables() override;
142 136
143 // Helper functions below help perform functions on the Url and host table 137 // Helper functions below help perform functions on the Url and host table
144 // using the same code. 138 // using the same code.
145 void GetAllDataHelper(PrefetchKeyType key_type, 139 void GetAllDataHelper(PrefetchKeyType key_type,
146 PrefetchDataMap* data_map, 140 PrefetchDataMap* data_map,
147 std::vector<std::string>* to_delete); 141 std::vector<std::string>* to_delete);
148 bool UpdateDataHelper(const PrefetchData& data); 142 bool UpdateDataHelper(const PrefetchData& data);
149 void DeleteDataHelper(PrefetchKeyType key_type, 143 void DeleteDataHelper(PrefetchKeyType key_type,
150 const std::vector<std::string>& keys); 144 const std::vector<std::string>& keys);
151 145
152 // Returns true if the strings in the |data| are less than |kMaxStringLength| 146 // Returns true if the strings in the |data| are less than |kMaxStringLength|
153 // in length. 147 // in length.
154 bool StringsAreSmallerThanDBLimit(const PrefetchData& data) const; 148 static bool StringsAreSmallerThanDBLimit(const PrefetchData& data);
155 149
156 // PredictorTableBase methods. 150 // PredictorTableBase methods.
157 void CreateTableIfNonExistent() override; 151 void CreateTableIfNonExistent() override;
158 void LogDatabaseStats() override; 152 void LogDatabaseStats() override;
159 153
160 // Database version. Always increment it when any change is made to the data 154 // Database version. Always increment it when any change is made to the data
161 // schema (including the .proto). 155 // schema (including the .proto).
162 static constexpr int kDatabaseVersion = 1; 156 static constexpr int kDatabaseVersion = 2;
163 157
164 static bool DropTablesIfOutdated(sql::Connection* db); 158 static bool DropTablesIfOutdated(sql::Connection* db);
165 static int GetDatabaseVersion(sql::Connection* db); 159 static int GetDatabaseVersion(sql::Connection* db);
166 static bool SetDatabaseVersion(sql::Connection* db, int version); 160 static bool SetDatabaseVersion(sql::Connection* db, int version);
167 161
168 // Helpers to return Statements for cached Statements. The caller must take 162 // Helpers to return Statements for cached Statements. The caller must take
169 // ownership of the return Statements. 163 // ownership of the return Statements.
170 sql::Statement* GetUrlResourceDeleteStatement(); 164 sql::Statement* GetUrlResourceDeleteStatement();
171 sql::Statement* GetUrlResourceUpdateStatement(); 165 sql::Statement* GetUrlResourceUpdateStatement();
172 sql::Statement* GetUrlMetadataDeleteStatement(); 166 sql::Statement* GetUrlMetadataDeleteStatement();
173 sql::Statement* GetUrlMetadataUpdateStatement(); 167 sql::Statement* GetUrlMetadataUpdateStatement();
174 168
175 sql::Statement* GetHostResourceDeleteStatement(); 169 sql::Statement* GetHostResourceDeleteStatement();
176 sql::Statement* GetHostResourceUpdateStatement(); 170 sql::Statement* GetHostResourceUpdateStatement();
177 sql::Statement* GetHostMetadataDeleteStatement(); 171 sql::Statement* GetHostMetadataDeleteStatement();
178 sql::Statement* GetHostMetadataUpdateStatement(); 172 sql::Statement* GetHostMetadataUpdateStatement();
179 173
180 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetchPredictorTables); 174 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetchPredictorTables);
181 }; 175 };
182 176
183 } // namespace predictors 177 } // namespace predictors
184 178
185 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_TABLES_H_ 179 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_TABLES_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698