Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(253)

Side by Side Diff: chrome/browser/history/history_database.cc

Issue 173296: Convert internal time format to Windows 1601 epoch on Linux & Mac.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 9
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "chrome/common/sqlite_utils.h" 11 #include "chrome/common/sqlite_utils.h"
12 12
13 using base::Time; 13 using base::Time;
14 14
15 namespace history { 15 namespace history {
16 16
17 namespace { 17 namespace {
18 18
19 // Current version number. 19 // Current version number. We write databases at the "current" version number,
20 static const int kCurrentVersionNumber = 16; 20 // but any previous version that can read the "compatible" one can make do with
21 // or database without *too* many bad effects.
22 static const int kCurrentVersionNumber = 17;
21 static const int kCompatibleVersionNumber = 16; 23 static const int kCompatibleVersionNumber = 16;
22 static const char kEarlyExpirationThresholdKey[] = "early_expiration_threshold"; 24 static const char kEarlyExpirationThresholdKey[] = "early_expiration_threshold";
23 25
24 } // namespace 26 } // namespace
25 27
26 HistoryDatabase::HistoryDatabase() 28 HistoryDatabase::HistoryDatabase()
27 : transaction_nesting_(0), 29 : transaction_nesting_(0),
28 db_(NULL) { 30 db_(NULL),
31 needs_version_17_migration_(false) {
29 } 32 }
30 33
31 HistoryDatabase::~HistoryDatabase() { 34 HistoryDatabase::~HistoryDatabase() {
32 } 35 }
33 36
34 InitStatus HistoryDatabase::Init(const FilePath& history_name, 37 InitStatus HistoryDatabase::Init(const FilePath& history_name,
35 const FilePath& bookmarks_path) { 38 const FilePath& bookmarks_path) {
36 // OpenSqliteDb uses the narrow version of open, indicating to sqlite that we 39 // OpenSqliteDb uses the narrow version of open, indicating to sqlite that we
37 // want the database to be in UTF-8 if it doesn't already exist. 40 // want the database to be in UTF-8 if it doesn't already exist.
38 DCHECK(!db_) << "Already initialized!"; 41 DCHECK(!db_) << "Already initialized!";
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 !DropStarredIDFromURLs()) { 231 !DropStarredIDFromURLs()) {
229 LOG(WARNING) << "Unable to update history database to version 16."; 232 LOG(WARNING) << "Unable to update history database to version 16.";
230 return INIT_FAILURE; 233 return INIT_FAILURE;
231 } 234 }
232 ++cur_version; 235 ++cur_version;
233 meta_table_.SetVersionNumber(cur_version); 236 meta_table_.SetVersionNumber(cur_version);
234 meta_table_.SetCompatibleVersionNumber( 237 meta_table_.SetCompatibleVersionNumber(
235 std::min(cur_version, kCompatibleVersionNumber)); 238 std::min(cur_version, kCompatibleVersionNumber));
236 } 239 }
237 240
241 if (cur_version == 16) {
242 #if !defined(OS_WIN)
243 // In this version we bring the time format on Mac & Linux in sync with the
244 // Windows version so that profiles can be moved between computers.
245 MigrateTimeEpoch();
246 #endif
247 // On all platforms we bump the version number, so on Windows this
248 // migration is a NOP. We keep the compatible version at 16 since things
249 // will basically still work, just history will be in the future if an
250 // old version reads it.
251 ++cur_version;
252 meta_table_.SetVersionNumber(cur_version);
253 }
254
238 // When the version is too old, we just try to continue anyway, there should 255 // When the version is too old, we just try to continue anyway, there should
239 // not be a released product that makes a database too old for us to handle. 256 // not be a released product that makes a database too old for us to handle.
240 LOG_IF(WARNING, cur_version < kCurrentVersionNumber) << 257 LOG_IF(WARNING, cur_version < kCurrentVersionNumber) <<
241 "History database version " << cur_version << " is too old to handle."; 258 "History database version " << cur_version << " is too old to handle.";
242 259
243 return INIT_OK; 260 return INIT_OK;
244 } 261 }
245 262
263 #if !defined(OS_WIN)
264 void HistoryDatabase::MigrateTimeEpoch() {
265 // Update all the times in the URLs and visits table in the main database.
266 // For visits, clear the indexed flag since we'll delete the FTS databases in
267 // the next step.
268 sqlite3_exec(GetDB(),
269 "UPDATE urls "
270 "SET last_visit_time = last_visit_time + 11644473600000000 "
271 "WHERE id IN (SELECT id FROM urls WHERE last_visit_time > 0);",
272 NULL, NULL, NULL);
273 sqlite3_exec(GetDB(),
274 "UPDATE visits "
275 "SET visit_time = visit_time + 11644473600000000, is_indexed = 0 "
276 "WHERE id IN (SELECT id FROM visits WHERE visit_time > 0);",
277 NULL, NULL, NULL);
278 sqlite3_exec(GetDB(),
279 "UPDATE segment_usage "
280 "SET time_slot = time_slot + 11644473600000000 "
281 "WHERE id IN (SELECT id FROM segment_usage WHERE time_slot > 0);",
282 NULL, NULL, NULL);
283
284 // Erase all the full text index files. These will take a while to update and
285 // are less important, so we just blow them away. Same with the archived
286 // database.
287 needs_version_17_migration_ = true;
288 }
289 #endif
290
246 } // namespace history 291 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/history/history_database.h ('k') | chrome/browser/password_manager/password_store_mac_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698