OLD | NEW |
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" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 // TODO(brettw) scale this value to the amount of available memory. | 50 // TODO(brettw) scale this value to the amount of available memory. |
51 sqlite3_exec(db_, "PRAGMA cache_size=6000", NULL, NULL, NULL); | 51 sqlite3_exec(db_, "PRAGMA cache_size=6000", NULL, NULL, NULL); |
52 | 52 |
53 // Wrap the rest of init in a tranaction. This will prevent the database from | 53 // Wrap the rest of init in a tranaction. This will prevent the database from |
54 // getting corrupted if we crash in the middle of initialization or migration. | 54 // getting corrupted if we crash in the middle of initialization or migration. |
55 TransactionScoper transaction(this); | 55 TransactionScoper transaction(this); |
56 | 56 |
57 // Make sure the statement cache is properly initialized. | 57 // Make sure the statement cache is properly initialized. |
58 statement_cache_->set_db(db_); | 58 statement_cache_->set_db(db_); |
59 | 59 |
60 // Prime the cache. See the header file's documentation for this function. | 60 // Prime the cache. |
61 PrimeCache(); | 61 MetaTableHelper::PrimeCache(std::string(), db_); |
62 | 62 |
63 // Create the tables and indices. | 63 // Create the tables and indices. |
64 // NOTE: If you add something here, also add it to | 64 // NOTE: If you add something here, also add it to |
65 // RecreateAllButStarAndURLTables. | 65 // RecreateAllButStarAndURLTables. |
66 if (!meta_table_.Init(std::string(), kCurrentVersionNumber, | 66 if (!meta_table_.Init(std::string(), kCurrentVersionNumber, |
67 kCompatibleVersionNumber, db_)) | 67 kCompatibleVersionNumber, db_)) |
68 return INIT_FAILURE; | 68 return INIT_FAILURE; |
69 if (!CreateURLTable(false) || !InitVisitTable() || | 69 if (!CreateURLTable(false) || !InitVisitTable() || |
70 !InitKeywordSearchTermsTable() || !InitDownloadTable() || | 70 !InitKeywordSearchTermsTable() || !InitDownloadTable() || |
71 !InitSegmentTables()) | 71 !InitSegmentTables()) |
72 return INIT_FAILURE; | 72 return INIT_FAILURE; |
73 CreateMainURLIndex(); | 73 CreateMainURLIndex(); |
74 CreateSupplimentaryURLIndices(); | 74 CreateSupplimentaryURLIndices(); |
75 | 75 |
76 // Version check. | 76 // Version check. |
77 InitStatus version_status = EnsureCurrentVersion(bookmarks_path); | 77 InitStatus version_status = EnsureCurrentVersion(bookmarks_path); |
78 if (version_status != INIT_OK) | 78 if (version_status != INIT_OK) |
79 return version_status; | 79 return version_status; |
80 | 80 |
81 // Succeeded: keep the DB open by detaching the auto-closer. | 81 // Succeeded: keep the DB open by detaching the auto-closer. |
82 scoper.Detach(); | 82 scoper.Detach(); |
83 db_closer_.Attach(&db_, &statement_cache_); | 83 db_closer_.Attach(&db_, &statement_cache_); |
84 return INIT_OK; | 84 return INIT_OK; |
85 } | 85 } |
86 | 86 |
87 void HistoryDatabase::BeginExclusiveMode() { | 87 void HistoryDatabase::BeginExclusiveMode() { |
88 sqlite3_exec(db_, "PRAGMA locking_mode=EXCLUSIVE", NULL, NULL, NULL); | 88 sqlite3_exec(db_, "PRAGMA locking_mode=EXCLUSIVE", NULL, NULL, NULL); |
89 } | 89 } |
90 | 90 |
91 void HistoryDatabase::PrimeCache() { | |
92 // A statement must be open for the preload command to work. If the meta | |
93 // table can't be read, it probably means this is a new database and there | |
94 // is nothing to preload (so it's OK we do nothing). | |
95 SQLStatement dummy; | |
96 if (dummy.prepare(db_, "SELECT * from meta") != SQLITE_OK) | |
97 return; | |
98 if (dummy.step() != SQLITE_ROW) | |
99 return; | |
100 | |
101 sqlite3Preload(db_); | |
102 } | |
103 | |
104 // static | 91 // static |
105 int HistoryDatabase::GetCurrentVersion() { | 92 int HistoryDatabase::GetCurrentVersion() { |
106 return kCurrentVersionNumber; | 93 return kCurrentVersionNumber; |
107 } | 94 } |
108 | 95 |
109 void HistoryDatabase::BeginTransaction() { | 96 void HistoryDatabase::BeginTransaction() { |
110 DCHECK(db_); | 97 DCHECK(db_); |
111 if (transaction_nesting_ == 0) { | 98 if (transaction_nesting_ == 0) { |
112 int rv = sqlite3_exec(db_, "BEGIN TRANSACTION", NULL, NULL, NULL); | 99 int rv = sqlite3_exec(db_, "BEGIN TRANSACTION", NULL, NULL, NULL); |
113 DCHECK(rv == SQLITE_OK) << "Failed to begin transaction"; | 100 DCHECK(rv == SQLITE_OK) << "Failed to begin transaction"; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 | 213 |
227 // When the version is too old, we just try to continue anyway, there should | 214 // When the version is too old, we just try to continue anyway, there should |
228 // not be a released product that makes a database too old for us to handle. | 215 // not be a released product that makes a database too old for us to handle. |
229 LOG_IF(WARNING, cur_version < kCurrentVersionNumber) << | 216 LOG_IF(WARNING, cur_version < kCurrentVersionNumber) << |
230 "History database version " << cur_version << " is too old to handle."; | 217 "History database version " << cur_version << " is too old to handle."; |
231 | 218 |
232 return INIT_OK; | 219 return INIT_OK; |
233 } | 220 } |
234 | 221 |
235 } // namespace history | 222 } // namespace history |
OLD | NEW |