| 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> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/gtest_prod_util.h" |
| 14 #include "base/macros.h" | 15 #include "base/macros.h" |
| 15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 16 #include "chrome/browser/predictors/predictor_table_base.h" | 17 #include "chrome/browser/predictors/predictor_table_base.h" |
| 17 #include "chrome/browser/predictors/resource_prefetch_common.h" | 18 #include "chrome/browser/predictors/resource_prefetch_common.h" |
| 18 #include "chrome/browser/predictors/resource_prefetch_predictor.pb.h" | 19 #include "chrome/browser/predictors/resource_prefetch_predictor.pb.h" |
| 19 #include "content/public/common/resource_type.h" | 20 #include "content/public/common/resource_type.h" |
| 20 #include "net/base/request_priority.h" | 21 #include "net/base/request_priority.h" |
| 21 #include "url/gurl.h" | 22 #include "url/gurl.h" |
| 22 | 23 |
| 23 namespace sql { | 24 namespace sql { |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 | 125 |
| 125 // Deletes all data in all the tables. | 126 // Deletes all data in all the tables. |
| 126 virtual void DeleteAllData(); | 127 virtual void DeleteAllData(); |
| 127 | 128 |
| 128 // The maximum length of the string that can be stored in the DB. | 129 // The maximum length of the string that can be stored in the DB. |
| 129 static const size_t kMaxStringLength; | 130 static const size_t kMaxStringLength; |
| 130 | 131 |
| 131 private: | 132 private: |
| 132 friend class PredictorDatabaseInternal; | 133 friend class PredictorDatabaseInternal; |
| 133 friend class MockResourcePrefetchPredictorTables; | 134 friend class MockResourcePrefetchPredictorTables; |
| 135 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTablesTest, |
| 136 DatabaseVersionIsSet); |
| 137 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTablesTest, |
| 138 DatabaseIsResetWhenIncompatible); |
| 134 | 139 |
| 135 ResourcePrefetchPredictorTables(); | 140 ResourcePrefetchPredictorTables(); |
| 136 ~ResourcePrefetchPredictorTables() override; | 141 ~ResourcePrefetchPredictorTables() override; |
| 137 | 142 |
| 138 // Helper functions below help perform functions on the Url and host table | 143 // Helper functions below help perform functions on the Url and host table |
| 139 // using the same code. | 144 // using the same code. |
| 140 void GetAllDataHelper(PrefetchKeyType key_type, | 145 void GetAllDataHelper(PrefetchKeyType key_type, |
| 141 PrefetchDataMap* data_map, | 146 PrefetchDataMap* data_map, |
| 142 std::vector<std::string>* to_delete); | 147 std::vector<std::string>* to_delete); |
| 143 bool UpdateDataHelper(const PrefetchData& data); | 148 bool UpdateDataHelper(const PrefetchData& data); |
| 144 void DeleteDataHelper(PrefetchKeyType key_type, | 149 void DeleteDataHelper(PrefetchKeyType key_type, |
| 145 const std::vector<std::string>& keys); | 150 const std::vector<std::string>& keys); |
| 146 | 151 |
| 147 // Returns true if the strings in the |data| are less than |kMaxStringLength| | 152 // Returns true if the strings in the |data| are less than |kMaxStringLength| |
| 148 // in length. | 153 // in length. |
| 149 bool StringsAreSmallerThanDBLimit(const PrefetchData& data) const; | 154 bool StringsAreSmallerThanDBLimit(const PrefetchData& data) const; |
| 150 | 155 |
| 151 // PredictorTableBase methods. | 156 // PredictorTableBase methods. |
| 152 void CreateTableIfNonExistent() override; | 157 void CreateTableIfNonExistent() override; |
| 153 void LogDatabaseStats() override; | 158 void LogDatabaseStats() override; |
| 154 | 159 |
| 155 bool DropTablesIfOutdated(sql::Connection* db); | 160 // Database version. Always increment it when any change is made to the data |
| 161 // schema (including the .proto). |
| 162 static constexpr int kDatabaseVersion = 1; |
| 163 |
| 164 static bool DropTablesIfOutdated(sql::Connection* db); |
| 165 static int GetDatabaseVersion(sql::Connection* db); |
| 166 static bool SetDatabaseVersion(sql::Connection* db, int version); |
| 156 | 167 |
| 157 // Helpers to return Statements for cached Statements. The caller must take | 168 // Helpers to return Statements for cached Statements. The caller must take |
| 158 // ownership of the return Statements. | 169 // ownership of the return Statements. |
| 159 sql::Statement* GetUrlResourceDeleteStatement(); | 170 sql::Statement* GetUrlResourceDeleteStatement(); |
| 160 sql::Statement* GetUrlResourceUpdateStatement(); | 171 sql::Statement* GetUrlResourceUpdateStatement(); |
| 161 sql::Statement* GetUrlMetadataDeleteStatement(); | 172 sql::Statement* GetUrlMetadataDeleteStatement(); |
| 162 sql::Statement* GetUrlMetadataUpdateStatement(); | 173 sql::Statement* GetUrlMetadataUpdateStatement(); |
| 163 | 174 |
| 164 sql::Statement* GetHostResourceDeleteStatement(); | 175 sql::Statement* GetHostResourceDeleteStatement(); |
| 165 sql::Statement* GetHostResourceUpdateStatement(); | 176 sql::Statement* GetHostResourceUpdateStatement(); |
| 166 sql::Statement* GetHostMetadataDeleteStatement(); | 177 sql::Statement* GetHostMetadataDeleteStatement(); |
| 167 sql::Statement* GetHostMetadataUpdateStatement(); | 178 sql::Statement* GetHostMetadataUpdateStatement(); |
| 168 | 179 |
| 169 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetchPredictorTables); | 180 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetchPredictorTables); |
| 170 }; | 181 }; |
| 171 | 182 |
| 172 } // namespace predictors | 183 } // namespace predictors |
| 173 | 184 |
| 174 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_TABLES_H_ | 185 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_TABLES_H_ |
| OLD | NEW |