Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 26 matching lines...) Expand all Loading... | |
| 37 // - UrlMetadataTable - misc data for Urls (like last visit time). | 37 // - UrlMetadataTable - misc data for Urls (like last visit time). |
| 38 // - HostResourceTable - resources per host. | 38 // - HostResourceTable - resources per host. |
| 39 // - HostMetadataTable - misc data for hosts. | 39 // - HostMetadataTable - misc data for hosts. |
| 40 class ResourcePrefetchPredictorTables : public PredictorTableBase { | 40 class ResourcePrefetchPredictorTables : public PredictorTableBase { |
| 41 public: | 41 public: |
| 42 // Used in the UrlResourceTable and HostResourceTable to store resources | 42 // Used in the UrlResourceTable and HostResourceTable to store resources |
| 43 // required for the page or host. | 43 // required for the page or host. |
| 44 struct ResourceRow { | 44 struct ResourceRow { |
| 45 ResourceRow(); | 45 ResourceRow(); |
| 46 ResourceRow(const ResourceRow& other); | 46 ResourceRow(const ResourceRow& other); |
| 47 ResourceRow(const std::string& main_frame_url, | 47 ResourceRow(const std::string& resource_url, |
| 48 const std::string& resource_url, | |
| 49 content::ResourceType resource_type, | 48 content::ResourceType resource_type, |
| 50 int number_of_hits, | 49 int number_of_hits, |
| 51 int number_of_misses, | 50 int number_of_misses, |
| 52 int consecutive_misses, | 51 int consecutive_misses, |
| 53 double average_position, | 52 double average_position, |
| 54 net::RequestPriority priority, | 53 net::RequestPriority priority, |
| 55 bool has_validators, | 54 bool has_validators, |
| 56 bool always_revalidate); | 55 bool always_revalidate); |
| 57 void UpdateScore(); | 56 void UpdateScore(); |
| 58 bool operator==(const ResourceRow& rhs) const; | 57 bool operator==(const ResourceRow& rhs) const; |
| 59 static void FromProto(const ResourceData& proto, ResourceRow* row); | 58 static void FromProto(const ResourceData& proto, ResourceRow* row); |
| 60 void ToProto(ResourceData* resource_data) const; | 59 void ToProto(ResourceData* resource_data) const; |
| 61 | 60 |
| 62 // Stores the host for host based data, main frame Url for the Url based | |
| 63 // data. This field is cleared for efficiency reasons and the code outside | |
| 64 // this class should not assume it is set. | |
| 65 std::string primary_key; | |
| 66 | |
| 67 GURL resource_url; | 61 GURL resource_url; |
| 68 content::ResourceType resource_type; | 62 content::ResourceType resource_type; |
| 69 size_t number_of_hits; | 63 size_t number_of_hits; |
|
pasko
2016/08/26 13:40:30
Do we want to still plumb these one by one in From
Benoit L
2016/08/29 13:11:39
If the proto doesn't reflect everything and needs
| |
| 70 size_t number_of_misses; | 64 size_t number_of_misses; |
| 71 size_t consecutive_misses; | 65 size_t consecutive_misses; |
| 72 double average_position; | 66 double average_position; |
| 73 net::RequestPriority priority; | 67 net::RequestPriority priority; |
| 74 bool has_validators; | 68 bool has_validators; |
| 75 bool always_revalidate; | 69 bool always_revalidate; |
| 76 | 70 |
| 77 // Not stored. | 71 // Not stored. |
| 78 float score; | 72 float score; |
| 79 }; | 73 }; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 const std::vector<std::string>& hosts); | 113 const std::vector<std::string>& hosts); |
| 120 | 114 |
| 121 // Wrapper over DeleteData for convenience. | 115 // Wrapper over DeleteData for convenience. |
| 122 virtual void DeleteSingleDataPoint(const std::string& key, | 116 virtual void DeleteSingleDataPoint(const std::string& key, |
| 123 PrefetchKeyType key_type); | 117 PrefetchKeyType key_type); |
| 124 | 118 |
| 125 // Deletes all data in all the tables. | 119 // Deletes all data in all the tables. |
| 126 virtual void DeleteAllData(); | 120 virtual void DeleteAllData(); |
| 127 | 121 |
| 128 // The maximum length of the string that can be stored in the DB. | 122 // The maximum length of the string that can be stored in the DB. |
| 129 static const size_t kMaxStringLength; | 123 static const size_t kMaxStringLength = 1024; |
|
pasko
2016/08/26 13:40:30
I would recommend constexpr. The idea of including
Benoit L
2016/08/29 13:11:39
Done.
| |
| 130 | 124 |
| 131 private: | 125 private: |
| 132 friend class PredictorDatabaseInternal; | 126 friend class PredictorDatabaseInternal; |
| 133 friend class MockResourcePrefetchPredictorTables; | 127 friend class MockResourcePrefetchPredictorTables; |
| 134 | 128 |
| 135 ResourcePrefetchPredictorTables(); | 129 ResourcePrefetchPredictorTables(); |
| 136 ~ResourcePrefetchPredictorTables() override; | 130 ~ResourcePrefetchPredictorTables() override; |
| 137 | 131 |
| 138 // Helper functions below help perform functions on the Url and host table | 132 // Helper functions below help perform functions on the Url and host table |
| 139 // using the same code. | 133 // using the same code. |
| 140 void GetAllDataHelper(PrefetchKeyType key_type, | 134 void GetAllDataHelper(PrefetchKeyType key_type, |
| 141 PrefetchDataMap* data_map, | 135 PrefetchDataMap* data_map, |
| 142 std::vector<std::string>* to_delete); | 136 std::vector<std::string>* to_delete); |
| 143 bool UpdateDataHelper(const PrefetchData& data); | 137 bool UpdateDataHelper(const PrefetchData& data); |
| 144 void DeleteDataHelper(PrefetchKeyType key_type, | 138 void DeleteDataHelper(PrefetchKeyType key_type, |
| 145 const std::vector<std::string>& keys); | 139 const std::vector<std::string>& keys); |
| 146 | 140 |
| 147 // Returns true if the strings in the |data| are less than |kMaxStringLength| | 141 // Returns true if the strings in the |data| are less than |kMaxStringLength| |
| 148 // in length. | 142 // in length. |
| 149 bool StringsAreSmallerThanDBLimit(const PrefetchData& data) const; | 143 static bool StringsAreSmallerThanDBLimit(const PrefetchData& data); |
| 150 | 144 |
| 151 // PredictorTableBase methods. | 145 // PredictorTableBase methods. |
| 152 void CreateTableIfNonExistent() override; | 146 void CreateTableIfNonExistent() override; |
| 153 void LogDatabaseStats() override; | 147 void LogDatabaseStats() override; |
| 154 | 148 |
| 155 static bool DropTablesIfOutdated(sql::Connection* db); | 149 static bool DropTablesIfOutdated(sql::Connection* db); |
| 156 | 150 |
| 157 // Helpers to return Statements for cached Statements. The caller must take | 151 // Helpers to return Statements for cached Statements. The caller must take |
| 158 // ownership of the return Statements. | 152 // ownership of the return Statements. |
| 159 sql::Statement* GetUrlResourceDeleteStatement(); | 153 sql::Statement* GetUrlResourceDeleteStatement(); |
| 160 sql::Statement* GetUrlResourceUpdateStatement(); | 154 sql::Statement* GetUrlResourceUpdateStatement(); |
| 161 sql::Statement* GetUrlMetadataDeleteStatement(); | 155 sql::Statement* GetUrlMetadataDeleteStatement(); |
| 162 sql::Statement* GetUrlMetadataUpdateStatement(); | 156 sql::Statement* GetUrlMetadataUpdateStatement(); |
| 163 | 157 |
| 164 sql::Statement* GetHostResourceDeleteStatement(); | 158 sql::Statement* GetHostResourceDeleteStatement(); |
| 165 sql::Statement* GetHostResourceUpdateStatement(); | 159 sql::Statement* GetHostResourceUpdateStatement(); |
| 166 sql::Statement* GetHostMetadataDeleteStatement(); | 160 sql::Statement* GetHostMetadataDeleteStatement(); |
| 167 sql::Statement* GetHostMetadataUpdateStatement(); | 161 sql::Statement* GetHostMetadataUpdateStatement(); |
| 168 | 162 |
| 169 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetchPredictorTables); | 163 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetchPredictorTables); |
| 170 }; | 164 }; |
| 171 | 165 |
| 172 } // namespace predictors | 166 } // namespace predictors |
| 173 | 167 |
| 174 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_TABLES_H_ | 168 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_TABLES_H_ |
| OLD | NEW |