| OLD | NEW |
| 1 // Copyright (c) 2012 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 "chrome/browser/history/history_database.h" | 5 #include "chrome/browser/history/history_database.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 | 26 |
| 27 // Current version number. We write databases at the "current" version number, | 27 // Current version number. We write databases at the "current" version number, |
| 28 // but any previous version that can read the "compatible" one can make do with | 28 // but any previous version that can read the "compatible" one can make do with |
| 29 // our database without *too* many bad effects. | 29 // our database without *too* many bad effects. |
| 30 const int kCurrentVersionNumber = 28; | 30 const int kCurrentVersionNumber = 28; |
| 31 const int kCompatibleVersionNumber = 16; | 31 const int kCompatibleVersionNumber = 16; |
| 32 const char kEarlyExpirationThresholdKey[] = "early_expiration_threshold"; | 32 const char kEarlyExpirationThresholdKey[] = "early_expiration_threshold"; |
| 33 | 33 |
| 34 } // namespace | 34 } // namespace |
| 35 | 35 |
| 36 HistoryDatabase::HistoryDatabase() | 36 HistoryDatabase::HistoryDatabase() { |
| 37 : needs_version_17_migration_(false) { | |
| 38 } | 37 } |
| 39 | 38 |
| 40 HistoryDatabase::~HistoryDatabase() { | 39 HistoryDatabase::~HistoryDatabase() { |
| 41 } | 40 } |
| 42 | 41 |
| 43 sql::InitStatus HistoryDatabase::Init(const base::FilePath& history_name) { | 42 sql::InitStatus HistoryDatabase::Init(const base::FilePath& history_name) { |
| 44 db_.set_histogram_tag("History"); | 43 db_.set_histogram_tag("History"); |
| 45 | 44 |
| 46 // Set the exceptional sqlite error handler. | 45 // Set the exceptional sqlite error handler. |
| 47 db_.set_error_callback(error_callback_); | 46 db_.set_error_callback(error_callback_); |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 if (!DropKeywordSearchTermsTable()) | 212 if (!DropKeywordSearchTermsTable()) |
| 214 return false; | 213 return false; |
| 215 if (!InitKeywordSearchTermsTable()) | 214 if (!InitKeywordSearchTermsTable()) |
| 216 return false; | 215 return false; |
| 217 | 216 |
| 218 if (!DropSegmentTables()) | 217 if (!DropSegmentTables()) |
| 219 return false; | 218 return false; |
| 220 if (!InitSegmentTables()) | 219 if (!InitSegmentTables()) |
| 221 return false; | 220 return false; |
| 222 | 221 |
| 223 // We also add the supplementary URL indices at this point. This index is | |
| 224 // over parts of the URL table that weren't automatically created when the | |
| 225 // temporary URL table was | |
| 226 CreateKeywordSearchTermsIndices(); | 222 CreateKeywordSearchTermsIndices(); |
| 227 return true; | 223 return true; |
| 228 } | 224 } |
| 229 | 225 |
| 230 void HistoryDatabase::Vacuum() { | 226 void HistoryDatabase::Vacuum() { |
| 231 DCHECK_EQ(0, db_.transaction_nesting()) << | 227 DCHECK_EQ(0, db_.transaction_nesting()) << |
| 232 "Can not have a transaction when vacuuming."; | 228 "Can not have a transaction when vacuuming."; |
| 233 ignore_result(db_.Execute("VACUUM")); | 229 ignore_result(db_.Execute("VACUUM")); |
| 234 } | 230 } |
| 235 | 231 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 | 288 |
| 293 // Migration ------------------------------------------------------------------- | 289 // Migration ------------------------------------------------------------------- |
| 294 | 290 |
| 295 sql::InitStatus HistoryDatabase::EnsureCurrentVersion() { | 291 sql::InitStatus HistoryDatabase::EnsureCurrentVersion() { |
| 296 // We can't read databases newer than we were designed for. | 292 // We can't read databases newer than we were designed for. |
| 297 if (meta_table_.GetCompatibleVersionNumber() > kCurrentVersionNumber) { | 293 if (meta_table_.GetCompatibleVersionNumber() > kCurrentVersionNumber) { |
| 298 LOG(WARNING) << "History database is too new."; | 294 LOG(WARNING) << "History database is too new."; |
| 299 return sql::INIT_TOO_NEW; | 295 return sql::INIT_TOO_NEW; |
| 300 } | 296 } |
| 301 | 297 |
| 302 // NOTICE: If you are changing structures for things shared with the archived | |
| 303 // history file like URLs, visits, or downloads, that will need migration as | |
| 304 // well. Instead of putting such migration code in this class, it should be | |
| 305 // in the corresponding file (url_database.cc, etc.) and called from here and | |
| 306 // from the archived_database.cc. | |
| 307 | |
| 308 int cur_version = meta_table_.GetVersionNumber(); | 298 int cur_version = meta_table_.GetVersionNumber(); |
| 309 | 299 |
| 310 // Put migration code here | 300 // Put migration code here |
| 311 | 301 |
| 312 if (cur_version == 15) { | 302 if (cur_version == 15) { |
| 313 if (!db_.Execute("DROP TABLE starred") || !DropStarredIDFromURLs()) { | 303 if (!db_.Execute("DROP TABLE starred") || !DropStarredIDFromURLs()) { |
| 314 LOG(WARNING) << "Unable to update history database to version 16."; | 304 LOG(WARNING) << "Unable to update history database to version 16."; |
| 315 return sql::INIT_FAILURE; | 305 return sql::INIT_FAILURE; |
| 316 } | 306 } |
| 317 ++cur_version; | 307 ++cur_version; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 "SET last_visit_time = last_visit_time + 11644473600000000 " | 438 "SET last_visit_time = last_visit_time + 11644473600000000 " |
| 449 "WHERE id IN (SELECT id FROM urls WHERE last_visit_time > 0);")); | 439 "WHERE id IN (SELECT id FROM urls WHERE last_visit_time > 0);")); |
| 450 ignore_result(db_.Execute( | 440 ignore_result(db_.Execute( |
| 451 "UPDATE visits " | 441 "UPDATE visits " |
| 452 "SET visit_time = visit_time + 11644473600000000 " | 442 "SET visit_time = visit_time + 11644473600000000 " |
| 453 "WHERE id IN (SELECT id FROM visits WHERE visit_time > 0);")); | 443 "WHERE id IN (SELECT id FROM visits WHERE visit_time > 0);")); |
| 454 ignore_result(db_.Execute( | 444 ignore_result(db_.Execute( |
| 455 "UPDATE segment_usage " | 445 "UPDATE segment_usage " |
| 456 "SET time_slot = time_slot + 11644473600000000 " | 446 "SET time_slot = time_slot + 11644473600000000 " |
| 457 "WHERE id IN (SELECT id FROM segment_usage WHERE time_slot > 0);")); | 447 "WHERE id IN (SELECT id FROM segment_usage WHERE time_slot > 0);")); |
| 458 | |
| 459 // Erase all the full text index files. These will take a while to update and | |
| 460 // are less important, so we just blow them away. Same with the archived | |
| 461 // database. | |
| 462 needs_version_17_migration_ = true; | |
| 463 } | 448 } |
| 464 #endif | 449 #endif |
| 465 | 450 |
| 466 } // namespace history | 451 } // namespace history |
| OLD | NEW |