| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include <algorithm> | 5 #include <algorithm> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "chrome/browser/history/archived_database.h" | 9 #include "chrome/browser/history/archived_database.h" |
| 10 #include "sql/transaction.h" | 10 #include "sql/transaction.h" |
| 11 | 11 |
| 12 namespace history { | 12 namespace history { |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 static const int kCurrentVersionNumber = 3; | 16 static const int kCurrentVersionNumber = 4; |
| 17 static const int kCompatibleVersionNumber = 2; | 17 static const int kCompatibleVersionNumber = 2; |
| 18 | 18 |
| 19 } // namespace | 19 } // namespace |
| 20 | 20 |
| 21 ArchivedDatabase::ArchivedDatabase() { | 21 ArchivedDatabase::ArchivedDatabase() { |
| 22 } | 22 } |
| 23 | 23 |
| 24 ArchivedDatabase::~ArchivedDatabase() { | 24 ArchivedDatabase::~ArchivedDatabase() { |
| 25 } | 25 } |
| 26 | 26 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 } | 77 } |
| 78 | 78 |
| 79 void ArchivedDatabase::CommitTransaction() { | 79 void ArchivedDatabase::CommitTransaction() { |
| 80 db_.CommitTransaction(); | 80 db_.CommitTransaction(); |
| 81 } | 81 } |
| 82 | 82 |
| 83 sql::Connection& ArchivedDatabase::GetDB() { | 83 sql::Connection& ArchivedDatabase::GetDB() { |
| 84 return db_; | 84 return db_; |
| 85 } | 85 } |
| 86 | 86 |
| 87 // static |
| 88 int ArchivedDatabase::GetCurrentVersion() { |
| 89 return kCurrentVersionNumber; |
| 90 } |
| 91 |
| 87 // Migration ------------------------------------------------------------------- | 92 // Migration ------------------------------------------------------------------- |
| 88 | 93 |
| 89 sql::InitStatus ArchivedDatabase::EnsureCurrentVersion() { | 94 sql::InitStatus ArchivedDatabase::EnsureCurrentVersion() { |
| 90 // We can't read databases newer than we were designed for. | 95 // We can't read databases newer than we were designed for. |
| 91 if (meta_table_.GetCompatibleVersionNumber() > kCurrentVersionNumber) { | 96 if (meta_table_.GetCompatibleVersionNumber() > kCurrentVersionNumber) { |
| 92 LOG(WARNING) << "Archived database is too new."; | 97 LOG(WARNING) << "Archived database is too new."; |
| 93 return sql::INIT_TOO_NEW; | 98 return sql::INIT_TOO_NEW; |
| 94 } | 99 } |
| 95 | 100 |
| 96 // NOTICE: If you are changing structures for things shared with the archived | 101 // NOTICE: If you are changing structures for things shared with the archived |
| (...skipping 13 matching lines...) Expand all Loading... |
| 110 meta_table_.SetCompatibleVersionNumber( | 115 meta_table_.SetCompatibleVersionNumber( |
| 111 std::min(cur_version, kCompatibleVersionNumber)); | 116 std::min(cur_version, kCompatibleVersionNumber)); |
| 112 } | 117 } |
| 113 | 118 |
| 114 if (cur_version == 2) { | 119 if (cur_version == 2) { |
| 115 // This is the version prior to adding visit_source table. | 120 // This is the version prior to adding visit_source table. |
| 116 ++cur_version; | 121 ++cur_version; |
| 117 meta_table_.SetVersionNumber(cur_version); | 122 meta_table_.SetVersionNumber(cur_version); |
| 118 } | 123 } |
| 119 | 124 |
| 125 if (cur_version == 3) { |
| 126 // This is the version prior to adding the visit_duration field in visits |
| 127 // database. We need to migrate the database. |
| 128 if (!MigrateVisitsWithoutDuration()) { |
| 129 LOG(WARNING) << "Unable to update archived database to version 4."; |
| 130 return sql::INIT_FAILURE; |
| 131 } |
| 132 ++cur_version; |
| 133 meta_table_.SetVersionNumber(cur_version); |
| 134 } |
| 135 |
| 120 // Put future migration cases here. | 136 // Put future migration cases here. |
| 121 | 137 |
| 122 // When the version is too old, we just try to continue anyway, there should | 138 // When the version is too old, we just try to continue anyway, there should |
| 123 // not be a released product that makes a database too old for us to handle. | 139 // not be a released product that makes a database too old for us to handle. |
| 124 LOG_IF(WARNING, cur_version < kCurrentVersionNumber) << | 140 LOG_IF(WARNING, cur_version < kCurrentVersionNumber) << |
| 125 "Archived database version " << cur_version << " is too old to handle."; | 141 "Archived database version " << cur_version << " is too old to handle."; |
| 126 | 142 |
| 127 return sql::INIT_OK; | 143 return sql::INIT_OK; |
| 128 } | 144 } |
| 129 } // namespace history | 145 } // namespace history |
| OLD | NEW |