summaryrefslogtreecommitdiffstats
path: root/chrome/browser/history
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-26 02:53:36 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-26 02:53:36 +0000
commita4a3292e978cca3ad8c0baa5205054b5b3802e64 (patch)
tree9490d74f9760c4b841f1188e13b1a91db374c327 /chrome/browser/history
parent67d0d62d638f7b15e031dd2c22756df0109e021d (diff)
downloadchromium_src-a4a3292e978cca3ad8c0baa5205054b5b3802e64.zip
chromium_src-a4a3292e978cca3ad8c0baa5205054b5b3802e64.tar.gz
chromium_src-a4a3292e978cca3ad8c0baa5205054b5b3802e64.tar.bz2
Convert internal time format to Windows 1601 epoch on Linux & Mac.
Although we represent time internally starting from 1601, there are still things like time explosion that will not work before the year 1900. This limitation is the same as it was previously. BUG=14734 Review URL: http://codereview.chromium.org/173296 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@24417 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/history')
-rw-r--r--chrome/browser/history/history_backend.cc13
-rw-r--r--chrome/browser/history/history_database.cc51
-rw-r--r--chrome/browser/history/history_database.h21
3 files changed, 82 insertions, 3 deletions
diff --git a/chrome/browser/history/history_backend.cc b/chrome/browser/history/history_backend.cc
index 1ccd7cf..0d01496 100644
--- a/chrome/browser/history/history_backend.cc
+++ b/chrome/browser/history/history_backend.cc
@@ -529,6 +529,13 @@ void HistoryBackend::InitImpl() {
LOG(WARNING) << "Text database initialization failed, running without it.";
text_database_.reset();
}
+ if (db_->needs_version_17_migration()) {
+ // See needs_version_17_migration() decl for more. In this case, we want
+ // to erase all the text database files. This must be done after the text
+ // database manager has been initialized, since it knows about all the
+ // files it manages.
+ text_database_->DeleteAll();
+ }
// Thumbnail database.
thumbnail_db_.reset(new ThumbnailDatabase());
@@ -544,6 +551,12 @@ void HistoryBackend::InitImpl() {
}
// Archived database.
+ if (db_->needs_version_17_migration()) {
+ // See needs_version_17_migration() decl for more. In this case, we want
+ // to delete the archived database and need to do so before we try to
+ // open the file. We can ignore any error (maybe the file doesn't exist).
+ file_util::Delete(archived_name, false);
+ }
archived_db_.reset(new ArchivedDatabase());
if (!archived_db_->Init(archived_name)) {
LOG(WARNING) << "Could not initialize the archived database.";
diff --git a/chrome/browser/history/history_database.cc b/chrome/browser/history/history_database.cc
index 5a929b1..198c6a4 100644
--- a/chrome/browser/history/history_database.cc
+++ b/chrome/browser/history/history_database.cc
@@ -16,8 +16,10 @@ namespace history {
namespace {
-// Current version number.
-static const int kCurrentVersionNumber = 16;
+// 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
+// or database without *too* many bad effects.
+static const int kCurrentVersionNumber = 17;
static const int kCompatibleVersionNumber = 16;
static const char kEarlyExpirationThresholdKey[] = "early_expiration_threshold";
@@ -25,7 +27,8 @@ static const char kEarlyExpirationThresholdKey[] = "early_expiration_threshold";
HistoryDatabase::HistoryDatabase()
: transaction_nesting_(0),
- db_(NULL) {
+ db_(NULL),
+ needs_version_17_migration_(false) {
}
HistoryDatabase::~HistoryDatabase() {
@@ -235,6 +238,20 @@ InitStatus HistoryDatabase::EnsureCurrentVersion(
std::min(cur_version, kCompatibleVersionNumber));
}
+ if (cur_version == 16) {
+#if !defined(OS_WIN)
+ // In this version we bring the time format on Mac & Linux in sync with the
+ // Windows version so that profiles can be moved between computers.
+ MigrateTimeEpoch();
+#endif
+ // On all platforms we bump the version number, so on Windows this
+ // migration is a NOP. We keep the compatible version at 16 since things
+ // will basically still work, just history will be in the future if an
+ // old version reads it.
+ ++cur_version;
+ meta_table_.SetVersionNumber(cur_version);
+ }
+
// 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.
LOG_IF(WARNING, cur_version < kCurrentVersionNumber) <<
@@ -243,4 +260,32 @@ InitStatus HistoryDatabase::EnsureCurrentVersion(
return INIT_OK;
}
+#if !defined(OS_WIN)
+void HistoryDatabase::MigrateTimeEpoch() {
+ // Update all the times in the URLs and visits table in the main database.
+ // For visits, clear the indexed flag since we'll delete the FTS databases in
+ // the next step.
+ sqlite3_exec(GetDB(),
+ "UPDATE urls "
+ "SET last_visit_time = last_visit_time + 11644473600000000 "
+ "WHERE id IN (SELECT id FROM urls WHERE last_visit_time > 0);",
+ NULL, NULL, NULL);
+ sqlite3_exec(GetDB(),
+ "UPDATE visits "
+ "SET visit_time = visit_time + 11644473600000000, is_indexed = 0 "
+ "WHERE id IN (SELECT id FROM visits WHERE visit_time > 0);",
+ NULL, NULL, NULL);
+ sqlite3_exec(GetDB(),
+ "UPDATE segment_usage "
+ "SET time_slot = time_slot + 11644473600000000 "
+ "WHERE id IN (SELECT id FROM segment_usage WHERE time_slot > 0);",
+ NULL, NULL, NULL);
+
+ // Erase all the full text index files. These will take a while to update and
+ // are less important, so we just blow them away. Same with the archived
+ // database.
+ needs_version_17_migration_ = true;
+}
+#endif
+
} // namespace history
diff --git a/chrome/browser/history/history_database.h b/chrome/browser/history/history_database.h
index 35d8595..9351c26 100644
--- a/chrome/browser/history/history_database.h
+++ b/chrome/browser/history/history_database.h
@@ -5,6 +5,7 @@
#ifndef CHROME_BROWSER_HISTORY_HISTORY_DATABASE_H_
#define CHROME_BROWSER_HISTORY_HISTORY_DATABASE_H_
+#include "build/build_config.h"
#include "chrome/browser/history/download_database.h"
#include "chrome/browser/history/history_types.h"
#include "chrome/browser/history/starred_url_database.h"
@@ -110,6 +111,17 @@ class HistoryDatabase : public DownloadDatabase,
// unused space in the file. It can be VERY SLOW.
void Vacuum();
+ // Returns true if the history backend should erase the full text search
+ // and archived history files as part of version 16 -> 17 migration. The
+ // time format changed in this revision, and these files would be much slower
+ // to migrate. Since the data is less important, they should be deleted.
+ //
+ // This flag will be valid after Init() is called. It will always be false
+ // when running on Windows.
+ bool needs_version_17_migration() const {
+ return needs_version_17_migration_;
+ }
+
// Visit table functions ----------------------------------------------------
// Update the segment id of a visit. Return true on success.
@@ -144,6 +156,12 @@ class HistoryDatabase : public DownloadDatabase,
// may commit the transaction and start a new one if migration requires it.
InitStatus EnsureCurrentVersion(const FilePath& tmp_bookmarks_path);
+#if !defined(OS_WIN)
+ // Converts the time epoch in the database from being 1970-based to being
+ // 1601-based which corresponds to the change in Time.internal_value_.
+ void MigrateTimeEpoch();
+#endif
+
// ---------------------------------------------------------------------------
// How many nested transactions are pending? When this gets to 0, we commit.
@@ -162,6 +180,9 @@ class HistoryDatabase : public DownloadDatabase,
MetaTableHelper meta_table_;
base::Time cached_early_expiration_threshold_;
+ // See the getter above.
+ bool needs_version_17_migration_;
+
DISALLOW_COPY_AND_ASSIGN(HistoryDatabase);
};