diff options
Diffstat (limited to 'chrome/browser/history/archived_database.cc')
-rw-r--r-- | chrome/browser/history/archived_database.cc | 46 |
1 files changed, 37 insertions, 9 deletions
diff --git a/chrome/browser/history/archived_database.cc b/chrome/browser/history/archived_database.cc index 19f6436..40ba38b 100644 --- a/chrome/browser/history/archived_database.cc +++ b/chrome/browser/history/archived_database.cc @@ -34,7 +34,7 @@ namespace history { namespace { -static const int kDatabaseVersion = 1; +static const int kCurrentVersionNumber = 2; } // namespace @@ -73,15 +73,8 @@ bool ArchivedDatabase::Init(const std::wstring& file_name) { BeginTransaction(); // Version check. - if (!meta_table_.Init(std::string(), kDatabaseVersion, db_)) + if (!meta_table_.Init(std::string(), kCurrentVersionNumber, db_)) return false; - if (meta_table_.GetCompatibleVersionNumber() > kDatabaseVersion) { - // We ignore this error and just run without the database. Normally, if - // the user is running two versions, the main history DB will give a - // warning about a version from the future. - LOG(WARNING) << "Archived database is a future version."; - return false; - } // Create the tables. if (!CreateURLTable(false) || !InitVisitTable() || @@ -89,6 +82,9 @@ bool ArchivedDatabase::Init(const std::wstring& file_name) { return false; CreateMainURLIndex(); + if (EnsureCurrentVersion() != INIT_OK) + return false; + // Succeeded: keep the DB open by detaching the auto-closer. scoper.Detach(); db_closer_.Attach(&db_, &statement_cache_); @@ -123,4 +119,36 @@ SqliteStatementCache& ArchivedDatabase::GetStatementCache() { return *statement_cache_; } +// Migration ------------------------------------------------------------------- + +InitStatus ArchivedDatabase::EnsureCurrentVersion() { + // We can't read databases newer than we were designed for. + if (meta_table_.GetCompatibleVersionNumber() > kCurrentVersionNumber) + return INIT_TOO_NEW; + + // NOTICE: If you are changing structures for things shared with the archived + // history file like URLs, visits, or downloads, that will need migration as + // well. Instead of putting such migration code in this class, it should be + // in the corresponding file (url_database.cc, etc.) and called from here and + // from the archived_database.cc. + + // When the version is too old, we just try to continue anyway, there should + // not be a released product that makes a database too old for us to handle. + int cur_version = meta_table_.GetVersionNumber(); + + // Put migration code here + + if (cur_version == 1) { + if (!DropStarredIDFromURLs()) + return INIT_FAILURE; + cur_version = 2; + meta_table_.SetVersionNumber(cur_version); + meta_table_.SetCompatibleVersionNumber(cur_version); + } + + LOG_IF(WARNING, cur_version < kCurrentVersionNumber) << + "Archived database version " << cur_version << " is too old to handle."; + + return INIT_OK; +} } // namespace history |