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

Side by Side Diff: components/history/core/browser/history_database.cc

Issue 2721713002: [sync] Add typed url sync metadata to the history db (Closed)
Patch Set: brettw review Created 3 years, 9 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
OLDNEW
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 "components/history/core/browser/history_database.h" 5 #include "components/history/core/browser/history_database.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <set> 10 #include <set>
(...skipping 18 matching lines...) Expand all
29 #include "base/mac/mac_util.h" 29 #include "base/mac/mac_util.h"
30 #endif 30 #endif
31 31
32 namespace history { 32 namespace history {
33 33
34 namespace { 34 namespace {
35 35
36 // Current version number. We write databases at the "current" version number, 36 // Current version number. We write databases at the "current" version number,
37 // but any previous version that can read the "compatible" one can make do with 37 // but any previous version that can read the "compatible" one can make do with
38 // our database without *too* many bad effects. 38 // our database without *too* many bad effects.
39 const int kCurrentVersionNumber = 34; 39 const int kCurrentVersionNumber = 35;
40 const int kCompatibleVersionNumber = 16; 40 const int kCompatibleVersionNumber = 16;
41 const char kEarlyExpirationThresholdKey[] = "early_expiration_threshold"; 41 const char kEarlyExpirationThresholdKey[] = "early_expiration_threshold";
42 const int kMaxHostsInMemory = 10000; 42 const int kMaxHostsInMemory = 10000;
43 43
44 } // namespace 44 } // namespace
45 45
46 HistoryDatabase::HistoryDatabase( 46 HistoryDatabase::HistoryDatabase(
47 DownloadInterruptReason download_interrupt_reason_none, 47 DownloadInterruptReason download_interrupt_reason_none,
48 DownloadInterruptReason download_interrupt_reason_crash) 48 DownloadInterruptReason download_interrupt_reason_crash)
49 : DownloadDatabase(download_interrupt_reason_none, 49 : DownloadDatabase(download_interrupt_reason_none,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 // Prime the cache. 89 // Prime the cache.
90 db_.Preload(); 90 db_.Preload();
91 91
92 // Create the tables and indices. 92 // Create the tables and indices.
93 // NOTE: If you add something here, also add it to 93 // NOTE: If you add something here, also add it to
94 // RecreateAllButStarAndURLTables. 94 // RecreateAllButStarAndURLTables.
95 if (!meta_table_.Init(&db_, GetCurrentVersion(), kCompatibleVersionNumber)) 95 if (!meta_table_.Init(&db_, GetCurrentVersion(), kCompatibleVersionNumber))
96 return sql::INIT_FAILURE; 96 return sql::INIT_FAILURE;
97 if (!CreateURLTable(false) || !InitVisitTable() || 97 if (!CreateURLTable(false) || !InitVisitTable() ||
98 !InitKeywordSearchTermsTable() || !InitDownloadTable() || 98 !InitKeywordSearchTermsTable() || !InitDownloadTable() ||
99 !InitSegmentTables()) 99 !InitSegmentTables() || !InitSyncTable())
100 return sql::INIT_FAILURE; 100 return sql::INIT_FAILURE;
101 CreateMainURLIndex(); 101 CreateMainURLIndex();
102 CreateKeywordSearchTermsIndices(); 102 CreateKeywordSearchTermsIndices();
103 103
104 // TODO(benjhayden) Remove at some point. 104 // TODO(benjhayden) Remove at some point.
105 meta_table_.DeleteKey("next_download_id"); 105 meta_table_.DeleteKey("next_download_id");
106 106
107 // Version check. 107 // Version check.
108 sql::InitStatus version_status = EnsureCurrentVersion(); 108 sql::InitStatus version_status = EnsureCurrentVersion();
109 if (version_status != sql::INIT_OK) 109 if (version_status != sql::INIT_OK)
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 544
545 if (cur_version == 33) { 545 if (cur_version == 33) {
546 if (!MigrateDownloadLastAccessTime()) { 546 if (!MigrateDownloadLastAccessTime()) {
547 LOG(WARNING) << "Unable to migrate to version 34"; 547 LOG(WARNING) << "Unable to migrate to version 34";
548 return sql::INIT_FAILURE; 548 return sql::INIT_FAILURE;
549 } 549 }
550 cur_version++; 550 cur_version++;
551 meta_table_.SetVersionNumber(cur_version); 551 meta_table_.SetVersionNumber(cur_version);
552 } 552 }
553 553
554 if (cur_version == 34) {
555 // AUTOINCREMENT is added to urls table PRIMARY KEY(id), need to recreate a
556 // new table and copy all contents over. favicon_id is removed from urls
557 // table since we never use it. Also typed_url_sync_metadata and
558 // autofill_model_type_state tables are introduced, no migration needed for
559 // those two tables.
560 if (!RecreateURLTableWithAllContents()) {
561 LOG(WARNING) << "Unable to update history database to version 35.";
562 return sql::INIT_FAILURE;
563 }
564 cur_version++;
565 meta_table_.SetVersionNumber(cur_version);
566 }
567
554 // When the version is too old, we just try to continue anyway, there should 568 // When the version is too old, we just try to continue anyway, there should
555 // not be a released product that makes a database too old for us to handle. 569 // not be a released product that makes a database too old for us to handle.
556 LOG_IF(WARNING, cur_version < GetCurrentVersion()) << 570 LOG_IF(WARNING, cur_version < GetCurrentVersion()) <<
557 "History database version " << cur_version << " is too old to handle."; 571 "History database version " << cur_version << " is too old to handle.";
558 572
559 return sql::INIT_OK; 573 return sql::INIT_OK;
560 } 574 }
561 575
562 #if !defined(OS_WIN) 576 #if !defined(OS_WIN)
563 void HistoryDatabase::MigrateTimeEpoch() { 577 void HistoryDatabase::MigrateTimeEpoch() {
564 // Update all the times in the URLs and visits table in the main database. 578 // Update all the times in the URLs and visits table in the main database.
565 ignore_result(db_.Execute( 579 ignore_result(db_.Execute(
566 "UPDATE urls " 580 "UPDATE urls "
567 "SET last_visit_time = last_visit_time + 11644473600000000 " 581 "SET last_visit_time = last_visit_time + 11644473600000000 "
568 "WHERE id IN (SELECT id FROM urls WHERE last_visit_time > 0);")); 582 "WHERE id IN (SELECT id FROM urls WHERE last_visit_time > 0);"));
569 ignore_result(db_.Execute( 583 ignore_result(db_.Execute(
570 "UPDATE visits " 584 "UPDATE visits "
571 "SET visit_time = visit_time + 11644473600000000 " 585 "SET visit_time = visit_time + 11644473600000000 "
572 "WHERE id IN (SELECT id FROM visits WHERE visit_time > 0);")); 586 "WHERE id IN (SELECT id FROM visits WHERE visit_time > 0);"));
573 ignore_result(db_.Execute( 587 ignore_result(db_.Execute(
574 "UPDATE segment_usage " 588 "UPDATE segment_usage "
575 "SET time_slot = time_slot + 11644473600000000 " 589 "SET time_slot = time_slot + 11644473600000000 "
576 "WHERE id IN (SELECT id FROM segment_usage WHERE time_slot > 0);")); 590 "WHERE id IN (SELECT id FROM segment_usage WHERE time_slot > 0);"));
577 } 591 }
578 #endif 592 #endif
579 593
580 } // namespace history 594 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698