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 |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
14 #include "base/rand_util.h" | 14 #include "base/rand_util.h" |
15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
16 #include "base/time.h" | 16 #include "base/time.h" |
17 #include "sql/transaction.h" | 17 #include "sql/transaction.h" |
18 | 18 |
19 #if defined(OS_MACOSX) | 19 #if defined(OS_MACOSX) |
20 #include "base/mac/mac_util.h" | 20 #include "base/mac/mac_util.h" |
21 #endif | 21 #endif |
22 | 22 |
23 namespace history { | 23 namespace history { |
24 | 24 |
25 namespace { | 25 namespace { |
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 // or database without *too* many bad effects. | 29 // or database without *too* many bad effects. |
30 static const int kCurrentVersionNumber = 23; | 30 static const int kCurrentVersionNumber = 24; |
31 static const int kCompatibleVersionNumber = 16; | 31 static const int kCompatibleVersionNumber = 16; |
32 static const char kEarlyExpirationThresholdKey[] = "early_expiration_threshold"; | 32 static const char kEarlyExpirationThresholdKey[] = "early_expiration_threshold"; |
33 | 33 |
34 // Key in the meta table used to determine if we need to migrate thumbnails out | 34 // Key in the meta table used to determine if we need to migrate thumbnails out |
35 // of history. | 35 // of history. |
36 static const char kNeedsThumbnailMigrationKey[] = "needs_thumbnail_migration"; | 36 static const char kNeedsThumbnailMigrationKey[] = "needs_thumbnail_migration"; |
37 | 37 |
38 void ComputeDatabaseMetrics(const FilePath& history_name, | 38 void ComputeDatabaseMetrics(const FilePath& history_name, |
39 sql::Connection& db) { | 39 sql::Connection& db) { |
40 if (base::RandInt(1, 100) != 50) | 40 if (base::RandInt(1, 100) != 50) |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 if (cur_version == 22) { | 392 if (cur_version == 22) { |
393 if (!MigrateDownloadsState()) { | 393 if (!MigrateDownloadsState()) { |
394 LOG(WARNING) << "Unable to fix invalid downloads state values"; | 394 LOG(WARNING) << "Unable to fix invalid downloads state values"; |
395 // Invalid state values may cause crashes. | 395 // Invalid state values may cause crashes. |
396 return sql::INIT_FAILURE; | 396 return sql::INIT_FAILURE; |
397 } | 397 } |
398 cur_version++; | 398 cur_version++; |
399 meta_table_.SetVersionNumber(cur_version); | 399 meta_table_.SetVersionNumber(cur_version); |
400 } | 400 } |
401 | 401 |
| 402 if (cur_version == 23) { |
| 403 if (!MigrateDownloadsReasonPathsAndDangerType()) { |
| 404 LOG(WARNING) << "Unable to upgrade download interrupt reason and paths"; |
| 405 // Invalid state values may cause crashes. |
| 406 return sql::INIT_FAILURE; |
| 407 } |
| 408 cur_version++; |
| 409 meta_table_.SetVersionNumber(cur_version); |
| 410 } |
| 411 |
402 // When the version is too old, we just try to continue anyway, there should | 412 // When the version is too old, we just try to continue anyway, there should |
403 // not be a released product that makes a database too old for us to handle. | 413 // not be a released product that makes a database too old for us to handle. |
404 LOG_IF(WARNING, cur_version < GetCurrentVersion()) << | 414 LOG_IF(WARNING, cur_version < GetCurrentVersion()) << |
405 "History database version " << cur_version << " is too old to handle."; | 415 "History database version " << cur_version << " is too old to handle."; |
406 | 416 |
407 return sql::INIT_OK; | 417 return sql::INIT_OK; |
408 } | 418 } |
409 | 419 |
410 #if !defined(OS_WIN) | 420 #if !defined(OS_WIN) |
411 void HistoryDatabase::MigrateTimeEpoch() { | 421 void HistoryDatabase::MigrateTimeEpoch() { |
(...skipping 14 matching lines...) Expand all Loading... |
426 "WHERE id IN (SELECT id FROM segment_usage WHERE time_slot > 0);")); | 436 "WHERE id IN (SELECT id FROM segment_usage WHERE time_slot > 0);")); |
427 | 437 |
428 // Erase all the full text index files. These will take a while to update and | 438 // Erase all the full text index files. These will take a while to update and |
429 // are less important, so we just blow them away. Same with the archived | 439 // are less important, so we just blow them away. Same with the archived |
430 // database. | 440 // database. |
431 needs_version_17_migration_ = true; | 441 needs_version_17_migration_ = true; |
432 } | 442 } |
433 #endif | 443 #endif |
434 | 444 |
435 } // namespace history | 445 } // namespace history |
OLD | NEW |