OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 | 10 |
10 #include "base/file_util.h" | 11 #include "base/file_util.h" |
11 #include "base/histogram.h" | 12 #include "base/histogram.h" |
12 #include "base/rand_util.h" | 13 #include "base/rand_util.h" |
13 #include "base/string_util.h" | 14 #include "base/string_util.h" |
14 #include "chrome/common/sqlite_utils.h" | 15 #include "chrome/common/sqlite_utils.h" |
15 | 16 |
16 using base::Time; | 17 using base::Time; |
17 | 18 |
18 namespace history { | 19 namespace history { |
(...skipping 28 matching lines...) Expand all Loading... |
47 visit_count.step() != SQLITE_ROW) | 48 visit_count.step() != SQLITE_ROW) |
48 return; | 49 return; |
49 UMA_HISTOGRAM_COUNTS("History.VisitTableCount", visit_count.column_int(0)); | 50 UMA_HISTOGRAM_COUNTS("History.VisitTableCount", visit_count.column_int(0)); |
50 } | 51 } |
51 | 52 |
52 } // namespace | 53 } // namespace |
53 | 54 |
54 HistoryDatabase::HistoryDatabase() | 55 HistoryDatabase::HistoryDatabase() |
55 : transaction_nesting_(0), | 56 : transaction_nesting_(0), |
56 db_(NULL), | 57 db_(NULL), |
| 58 statement_cache_(NULL), |
57 needs_version_17_migration_(false) { | 59 needs_version_17_migration_(false) { |
58 } | 60 } |
59 | 61 |
60 HistoryDatabase::~HistoryDatabase() { | 62 HistoryDatabase::~HistoryDatabase() { |
61 } | 63 } |
62 | 64 |
63 InitStatus HistoryDatabase::Init(const FilePath& history_name, | 65 InitStatus HistoryDatabase::Init(const FilePath& history_name, |
64 const FilePath& bookmarks_path) { | 66 const FilePath& bookmarks_path) { |
65 // OpenSqliteDb uses the narrow version of open, indicating to sqlite that we | 67 // OpenSqliteDb uses the narrow version of open, indicating to sqlite that we |
66 // want the database to be in UTF-8 if it doesn't already exist. | 68 // want the database to be in UTF-8 if it doesn't already exist. |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 DCHECK(db_); | 132 DCHECK(db_); |
131 if (transaction_nesting_ == 0) { | 133 if (transaction_nesting_ == 0) { |
132 int rv = sqlite3_exec(db_, "BEGIN TRANSACTION", NULL, NULL, NULL); | 134 int rv = sqlite3_exec(db_, "BEGIN TRANSACTION", NULL, NULL, NULL); |
133 DCHECK(rv == SQLITE_OK) << "Failed to begin transaction"; | 135 DCHECK(rv == SQLITE_OK) << "Failed to begin transaction"; |
134 } | 136 } |
135 transaction_nesting_++; | 137 transaction_nesting_++; |
136 } | 138 } |
137 | 139 |
138 void HistoryDatabase::CommitTransaction() { | 140 void HistoryDatabase::CommitTransaction() { |
139 DCHECK(db_); | 141 DCHECK(db_); |
140 DCHECK(transaction_nesting_ > 0) << "Committing too many transactions"; | 142 DCHECK_GT(transaction_nesting_, 0) << "Committing too many transactions"; |
141 transaction_nesting_--; | 143 transaction_nesting_--; |
142 if (transaction_nesting_ == 0) { | 144 if (transaction_nesting_ == 0) { |
143 int rv = sqlite3_exec(db_, "COMMIT", NULL, NULL, NULL); | 145 int rv = sqlite3_exec(db_, "COMMIT", NULL, NULL, NULL); |
144 DCHECK(rv == SQLITE_OK) << "Failed to commit transaction"; | 146 DCHECK(rv == SQLITE_OK) << "Failed to commit transaction"; |
145 } | 147 } |
146 } | 148 } |
147 | 149 |
148 bool HistoryDatabase::RecreateAllTablesButURL() { | 150 bool HistoryDatabase::RecreateAllTablesButURL() { |
149 if (!DropVisitTable()) | 151 if (!DropVisitTable()) |
150 return false; | 152 return false; |
(...skipping 11 matching lines...) Expand all Loading... |
162 return false; | 164 return false; |
163 | 165 |
164 // We also add the supplementary URL indices at this point. This index is | 166 // We also add the supplementary URL indices at this point. This index is |
165 // over parts of the URL table that weren't automatically created when the | 167 // over parts of the URL table that weren't automatically created when the |
166 // temporary URL table was | 168 // temporary URL table was |
167 CreateSupplimentaryURLIndices(); | 169 CreateSupplimentaryURLIndices(); |
168 return true; | 170 return true; |
169 } | 171 } |
170 | 172 |
171 void HistoryDatabase::Vacuum() { | 173 void HistoryDatabase::Vacuum() { |
172 DCHECK(transaction_nesting_ == 0) << | 174 DCHECK_EQ(0, transaction_nesting_) << |
173 "Can not have a transaction when vacuuming."; | 175 "Can not have a transaction when vacuuming."; |
174 sqlite3_exec(db_, "VACUUM", NULL, NULL, NULL); | 176 sqlite3_exec(db_, "VACUUM", NULL, NULL, NULL); |
175 } | 177 } |
176 | 178 |
177 bool HistoryDatabase::SetSegmentID(VisitID visit_id, SegmentID segment_id) { | 179 bool HistoryDatabase::SetSegmentID(VisitID visit_id, SegmentID segment_id) { |
178 SQLStatement s; | 180 SQLStatement s; |
179 if (s.prepare(db_, "UPDATE visits SET segment_id = ? WHERE id = ?") != | 181 if (s.prepare(db_, "UPDATE visits SET segment_id = ? WHERE id = ?") != |
180 SQLITE_OK) { | 182 SQLITE_OK) { |
181 NOTREACHED(); | 183 NOTREACHED(); |
182 return false; | 184 return false; |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 NULL, NULL, NULL); | 311 NULL, NULL, NULL); |
310 | 312 |
311 // Erase all the full text index files. These will take a while to update and | 313 // Erase all the full text index files. These will take a while to update and |
312 // are less important, so we just blow them away. Same with the archived | 314 // are less important, so we just blow them away. Same with the archived |
313 // database. | 315 // database. |
314 needs_version_17_migration_ = true; | 316 needs_version_17_migration_ = true; |
315 } | 317 } |
316 #endif | 318 #endif |
317 | 319 |
318 } // namespace history | 320 } // namespace history |
OLD | NEW |