Index: components/history/core/browser/history_database.cc |
diff --git a/components/history/core/browser/history_database.cc b/components/history/core/browser/history_database.cc |
index 9884339dec1927ce4f46b5019547067bee2d4574..a09e942999a6d0ba44d5c6e53cc3571b6a4e5ecd 100644 |
--- a/components/history/core/browser/history_database.cc |
+++ b/components/history/core/browser/history_database.cc |
@@ -22,6 +22,7 @@ |
#include "base/time/time.h" |
#include "build/build_config.h" |
#include "components/history/core/browser/url_utils.h" |
+#include "sql/meta_table.h" |
#include "sql/statement.h" |
#include "sql/transaction.h" |
@@ -36,7 +37,7 @@ namespace { |
// Current version number. We write databases at the "current" version number, |
// but any previous version that can read the "compatible" one can make do with |
// our database without *too* many bad effects. |
-const int kCurrentVersionNumber = 34; |
+const int kCurrentVersionNumber = 35; |
const int kCompatibleVersionNumber = 16; |
const char kEarlyExpirationThresholdKey[] = "early_expiration_threshold"; |
const int kMaxHostsInMemory = 10000; |
@@ -92,17 +93,18 @@ sql::InitStatus HistoryDatabase::Init(const base::FilePath& history_name) { |
// Create the tables and indices. |
// NOTE: If you add something here, also add it to |
// RecreateAllButStarAndURLTables. |
- if (!meta_table_.Init(&db_, GetCurrentVersion(), kCompatibleVersionNumber)) |
+ if (!GetMetaTable()->Init(&db_, GetCurrentVersion(), |
+ kCompatibleVersionNumber)) |
return sql::INIT_FAILURE; |
if (!CreateURLTable(false) || !InitVisitTable() || |
!InitKeywordSearchTermsTable() || !InitDownloadTable() || |
- !InitSegmentTables()) |
+ !InitSegmentTables() || !InitSyncTable()) |
return sql::INIT_FAILURE; |
CreateMainURLIndex(); |
CreateKeywordSearchTermsIndices(); |
// TODO(benjhayden) Remove at some point. |
- meta_table_.DeleteKey("next_download_id"); |
+ GetMetaTable()->DeleteKey("next_download_id"); |
// Version check. |
sql::InitStatus version_status = EnsureCurrentVersion(); |
@@ -344,7 +346,7 @@ base::Time HistoryDatabase::GetEarlyExpirationThreshold() { |
return cached_early_expiration_threshold_; |
int64_t threshold; |
- if (!meta_table_.GetValue(kEarlyExpirationThresholdKey, &threshold)) { |
+ if (!GetMetaTable()->GetValue(kEarlyExpirationThresholdKey, &threshold)) { |
// Set to a very early non-zero time, so it's before all history, but not |
// zero to avoid re-retrieval. |
threshold = 1L; |
@@ -355,8 +357,8 @@ base::Time HistoryDatabase::GetEarlyExpirationThreshold() { |
} |
void HistoryDatabase::UpdateEarlyExpirationThreshold(base::Time threshold) { |
- meta_table_.SetValue(kEarlyExpirationThresholdKey, |
- threshold.ToInternalValue()); |
+ GetMetaTable()->SetValue(kEarlyExpirationThresholdKey, |
+ threshold.ToInternalValue()); |
cached_early_expiration_threshold_ = threshold; |
} |
@@ -368,12 +370,12 @@ sql::Connection& HistoryDatabase::GetDB() { |
sql::InitStatus HistoryDatabase::EnsureCurrentVersion() { |
// We can't read databases newer than we were designed for. |
- if (meta_table_.GetCompatibleVersionNumber() > kCurrentVersionNumber) { |
+ if (GetMetaTable()->GetCompatibleVersionNumber() > kCurrentVersionNumber) { |
LOG(WARNING) << "History database is too new."; |
return sql::INIT_TOO_NEW; |
} |
- int cur_version = meta_table_.GetVersionNumber(); |
+ int cur_version = GetMetaTable()->GetVersionNumber(); |
// Put migration code here |
@@ -383,8 +385,8 @@ sql::InitStatus HistoryDatabase::EnsureCurrentVersion() { |
return sql::INIT_FAILURE; |
} |
++cur_version; |
- meta_table_.SetVersionNumber(cur_version); |
- meta_table_.SetCompatibleVersionNumber( |
+ GetMetaTable()->SetVersionNumber(cur_version); |
+ GetMetaTable()->SetCompatibleVersionNumber( |
std::min(cur_version, kCompatibleVersionNumber)); |
} |
@@ -399,26 +401,26 @@ sql::InitStatus HistoryDatabase::EnsureCurrentVersion() { |
// will basically still work, just history will be in the future if an |
// old version reads it. |
++cur_version; |
- meta_table_.SetVersionNumber(cur_version); |
+ GetMetaTable()->SetVersionNumber(cur_version); |
} |
if (cur_version == 17) { |
// Version 17 was for thumbnails to top sites migration. We ended up |
// disabling it though, so 17->18 does nothing. |
++cur_version; |
- meta_table_.SetVersionNumber(cur_version); |
+ GetMetaTable()->SetVersionNumber(cur_version); |
} |
if (cur_version == 18) { |
// This is the version prior to adding url_source column. We need to |
// migrate the database. |
cur_version = 19; |
- meta_table_.SetVersionNumber(cur_version); |
+ GetMetaTable()->SetVersionNumber(cur_version); |
} |
if (cur_version == 19) { |
cur_version++; |
- meta_table_.SetVersionNumber(cur_version); |
+ GetMetaTable()->SetVersionNumber(cur_version); |
// This was the thumbnail migration. Obsolete. |
} |
@@ -430,7 +432,7 @@ sql::InitStatus HistoryDatabase::EnsureCurrentVersion() { |
return sql::INIT_FAILURE; |
} |
++cur_version; |
- meta_table_.SetVersionNumber(cur_version); |
+ GetMetaTable()->SetVersionNumber(cur_version); |
} |
if (cur_version == 21) { |
@@ -441,7 +443,7 @@ sql::InitStatus HistoryDatabase::EnsureCurrentVersion() { |
} |
#endif |
++cur_version; |
- meta_table_.SetVersionNumber(cur_version); |
+ GetMetaTable()->SetVersionNumber(cur_version); |
} |
if (cur_version == 22) { |
@@ -451,7 +453,7 @@ sql::InitStatus HistoryDatabase::EnsureCurrentVersion() { |
return sql::INIT_FAILURE; |
} |
cur_version++; |
- meta_table_.SetVersionNumber(cur_version); |
+ GetMetaTable()->SetVersionNumber(cur_version); |
} |
if (cur_version == 23) { |
@@ -461,7 +463,7 @@ sql::InitStatus HistoryDatabase::EnsureCurrentVersion() { |
return sql::INIT_FAILURE; |
} |
cur_version++; |
- meta_table_.SetVersionNumber(cur_version); |
+ GetMetaTable()->SetVersionNumber(cur_version); |
} |
if (cur_version == 24) { |
@@ -470,7 +472,7 @@ sql::InitStatus HistoryDatabase::EnsureCurrentVersion() { |
return sql::INIT_FAILURE; |
} |
cur_version++; |
- meta_table_.SetVersionNumber(cur_version); |
+ GetMetaTable()->SetVersionNumber(cur_version); |
} |
if (cur_version == 25) { |
@@ -479,7 +481,7 @@ sql::InitStatus HistoryDatabase::EnsureCurrentVersion() { |
return sql::INIT_FAILURE; |
} |
cur_version++; |
- meta_table_.SetVersionNumber(cur_version); |
+ GetMetaTable()->SetVersionNumber(cur_version); |
} |
if (cur_version == 26) { |
@@ -488,7 +490,7 @@ sql::InitStatus HistoryDatabase::EnsureCurrentVersion() { |
return sql::INIT_FAILURE; |
} |
cur_version++; |
- meta_table_.SetVersionNumber(cur_version); |
+ GetMetaTable()->SetVersionNumber(cur_version); |
} |
if (cur_version == 27) { |
@@ -497,7 +499,7 @@ sql::InitStatus HistoryDatabase::EnsureCurrentVersion() { |
return sql::INIT_FAILURE; |
} |
cur_version++; |
- meta_table_.SetVersionNumber(cur_version); |
+ GetMetaTable()->SetVersionNumber(cur_version); |
} |
if (cur_version == 28) { |
@@ -506,7 +508,7 @@ sql::InitStatus HistoryDatabase::EnsureCurrentVersion() { |
return sql::INIT_FAILURE; |
} |
cur_version++; |
- meta_table_.SetVersionNumber(cur_version); |
+ GetMetaTable()->SetVersionNumber(cur_version); |
} |
if (cur_version == 29) { |
@@ -515,7 +517,7 @@ sql::InitStatus HistoryDatabase::EnsureCurrentVersion() { |
return sql::INIT_FAILURE; |
} |
cur_version++; |
- meta_table_.SetVersionNumber(cur_version); |
+ GetMetaTable()->SetVersionNumber(cur_version); |
} |
if (cur_version == 30) { |
@@ -524,7 +526,7 @@ sql::InitStatus HistoryDatabase::EnsureCurrentVersion() { |
return sql::INIT_FAILURE; |
} |
cur_version++; |
- meta_table_.SetVersionNumber(cur_version); |
+ GetMetaTable()->SetVersionNumber(cur_version); |
} |
if (cur_version == 31) { |
@@ -533,13 +535,13 @@ sql::InitStatus HistoryDatabase::EnsureCurrentVersion() { |
return sql::INIT_FAILURE; |
} |
cur_version++; |
- meta_table_.SetVersionNumber(cur_version); |
+ GetMetaTable()->SetVersionNumber(cur_version); |
} |
if (cur_version == 32) { |
// New download slices table is introduced, no migration needed. |
cur_version++; |
- meta_table_.SetVersionNumber(cur_version); |
+ GetMetaTable()->SetVersionNumber(cur_version); |
} |
if (cur_version == 33) { |
@@ -548,7 +550,21 @@ sql::InitStatus HistoryDatabase::EnsureCurrentVersion() { |
return sql::INIT_FAILURE; |
} |
cur_version++; |
- meta_table_.SetVersionNumber(cur_version); |
+ GetMetaTable()->SetVersionNumber(cur_version); |
+ } |
+ |
+ if (cur_version == 34) { |
+ // AUTOINCREMENT is added to urls table PRIMARY KEY(id), need to recreate a |
+ // new table and copy all contents over. favicon_id is removed from urls |
+ // table since we never use it. Also typed_url_sync_metadata and |
+ // autofill_model_type_state tables are introduced, no migration needed for |
+ // those two tables. |
+ if (!RecreateURLTableWithAllContents()) { |
+ LOG(WARNING) << "Unable to update history database to version 35."; |
+ return sql::INIT_FAILURE; |
+ } |
+ cur_version++; |
+ GetMetaTable()->SetVersionNumber(cur_version); |
} |
// When the version is too old, we just try to continue anyway, there should |