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

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

Issue 2285673002: predictors: Version the resource_prefetch_predictor database. (Closed)
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..3bb13c5fa1a788be9abf7553589da1fceaf2fc48 100644
--- a/chrome/browser/predictors/resource_prefetch_predictor_tables.h
+++ b/chrome/browser/predictors/resource_prefetch_predictor_tables.h
@@ -11,6 +11,7 @@
#include <string>
#include <vector>
+#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "base/time/time.h"
#include "chrome/browser/predictors/predictor_table_base.h"
@@ -131,6 +132,10 @@ class ResourcePrefetchPredictorTables : public PredictorTableBase {
private:
friend class PredictorDatabaseInternal;
friend class MockResourcePrefetchPredictorTables;
+ FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTablesTest,
+ DatabaseVersionIsSet);
+ FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTablesTest,
+ DatabaseIsResetWhenIncompatible);
ResourcePrefetchPredictorTables();
~ResourcePrefetchPredictorTables() override;
@@ -152,7 +157,13 @@ class ResourcePrefetchPredictorTables : public PredictorTableBase {
void CreateTableIfNonExistent() override;
void LogDatabaseStats() override;
- bool DropTablesIfOutdated(sql::Connection* db);
+ // Database version. Always increment it when any change is made to the data
+ // schema (including the .proto).
+ static constexpr int kDatabaseVersion = 1;
+
+ static bool DropTablesIfOutdated(sql::Connection* db);
+ static int GetDatabaseVersion(sql::Connection* db);
+ static bool SetDatabaseVersion(sql::Connection* db, int version);
// Helpers to return Statements for cached Statements. The caller must take
// ownership of the return Statements.

Powered by Google App Engine
This is Rietveld 408576698