OLD | NEW |
---|---|
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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
49 : DownloadDatabase(download_interrupt_reason_none, | 49 : DownloadDatabase(download_interrupt_reason_none, |
50 download_interrupt_reason_crash) { | 50 download_interrupt_reason_crash) { |
51 } | 51 } |
52 | 52 |
53 HistoryDatabase::~HistoryDatabase() { | 53 HistoryDatabase::~HistoryDatabase() { |
54 } | 54 } |
55 | 55 |
56 sql::InitStatus HistoryDatabase::Init(const base::FilePath& history_name) { | 56 sql::InitStatus HistoryDatabase::Init(const base::FilePath& history_name) { |
57 db_.set_histogram_tag("History"); | 57 db_.set_histogram_tag("History"); |
58 | 58 |
59 // Set the exceptional sqlite error handler. | |
60 db_.set_error_callback(error_callback_); | |
61 | |
62 // Set the database page size to something a little larger to give us | 59 // Set the database page size to something a little larger to give us |
63 // better performance (we're typically seek rather than bandwidth limited). | 60 // better performance (we're typically seek rather than bandwidth limited). |
64 // This only has an effect before any tables have been created, otherwise | 61 // This only has an effect before any tables have been created, otherwise |
65 // this is a NOP. Must be a power of 2 and a max of 8192. | 62 // this is a NOP. Must be a power of 2 and a max of 8192. |
66 db_.set_page_size(4096); | 63 db_.set_page_size(4096); |
67 | 64 |
68 // Set the cache size. The page size, plus a little extra, times this | 65 // Set the cache size. The page size, plus a little extra, times this |
69 // value, tells us how much memory the cache will use maximum. | 66 // value, tells us how much memory the cache will use maximum. |
70 // 1000 * 4kB = 4MB | 67 // 1000 * 4kB = 4MB |
71 // TODO(brettw) scale this value to the amount of available memory. | 68 // TODO(brettw) scale this value to the amount of available memory. |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
252 | 249 |
253 void HistoryDatabase::BeginTransaction() { | 250 void HistoryDatabase::BeginTransaction() { |
254 db_.BeginTransaction(); | 251 db_.BeginTransaction(); |
255 } | 252 } |
256 | 253 |
257 void HistoryDatabase::CommitTransaction() { | 254 void HistoryDatabase::CommitTransaction() { |
258 db_.CommitTransaction(); | 255 db_.CommitTransaction(); |
259 } | 256 } |
260 | 257 |
261 void HistoryDatabase::RollbackTransaction() { | 258 void HistoryDatabase::RollbackTransaction() { |
262 db_.RollbackTransaction(); | 259 if (db_.transaction_nesting()) |
sky
2016/08/02 13:27:21
Why are you doing this change now? Shouldn't this
afakhry
2016/08/02 23:58:24
Exactly. It is a DCHECK that I'm trying to avoid.
sky
2016/08/03 15:19:30
Got it. Please add a comment.
afakhry
2016/08/03 17:51:23
Done.
| |
260 db_.RollbackTransaction(); | |
263 } | 261 } |
264 | 262 |
265 bool HistoryDatabase::RecreateAllTablesButURL() { | 263 bool HistoryDatabase::RecreateAllTablesButURL() { |
266 if (!DropVisitTable()) | 264 if (!DropVisitTable()) |
267 return false; | 265 return false; |
268 if (!InitVisitTable()) | 266 if (!InitVisitTable()) |
269 return false; | 267 return false; |
270 | 268 |
271 if (!DropKeywordSearchTermsTable()) | 269 if (!DropKeywordSearchTermsTable()) |
272 return false; | 270 return false; |
(...skipping 16 matching lines...) Expand all Loading... | |
289 } | 287 } |
290 | 288 |
291 void HistoryDatabase::TrimMemory(bool aggressively) { | 289 void HistoryDatabase::TrimMemory(bool aggressively) { |
292 db_.TrimMemory(aggressively); | 290 db_.TrimMemory(aggressively); |
293 } | 291 } |
294 | 292 |
295 bool HistoryDatabase::Raze() { | 293 bool HistoryDatabase::Raze() { |
296 return db_.Raze(); | 294 return db_.Raze(); |
297 } | 295 } |
298 | 296 |
297 std::string HistoryDatabase::GetDiagnosticInfo(int extended_error, | |
298 sql::Statement* statement) { | |
299 return db_.GetDiagnosticInfo(extended_error, statement); | |
300 } | |
301 | |
299 bool HistoryDatabase::SetSegmentID(VisitID visit_id, SegmentID segment_id) { | 302 bool HistoryDatabase::SetSegmentID(VisitID visit_id, SegmentID segment_id) { |
300 sql::Statement s(db_.GetCachedStatement(SQL_FROM_HERE, | 303 sql::Statement s(db_.GetCachedStatement(SQL_FROM_HERE, |
301 "UPDATE visits SET segment_id = ? WHERE id = ?")); | 304 "UPDATE visits SET segment_id = ? WHERE id = ?")); |
302 s.BindInt64(0, segment_id); | 305 s.BindInt64(0, segment_id); |
303 s.BindInt64(1, visit_id); | 306 s.BindInt64(1, visit_id); |
304 DCHECK(db_.GetLastChangeCount() == 1); | 307 DCHECK(db_.GetLastChangeCount() == 1); |
305 | 308 |
306 return s.Run(); | 309 return s.Run(); |
307 } | 310 } |
308 | 311 |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
537 "SET visit_time = visit_time + 11644473600000000 " | 540 "SET visit_time = visit_time + 11644473600000000 " |
538 "WHERE id IN (SELECT id FROM visits WHERE visit_time > 0);")); | 541 "WHERE id IN (SELECT id FROM visits WHERE visit_time > 0);")); |
539 ignore_result(db_.Execute( | 542 ignore_result(db_.Execute( |
540 "UPDATE segment_usage " | 543 "UPDATE segment_usage " |
541 "SET time_slot = time_slot + 11644473600000000 " | 544 "SET time_slot = time_slot + 11644473600000000 " |
542 "WHERE id IN (SELECT id FROM segment_usage WHERE time_slot > 0);")); | 545 "WHERE id IN (SELECT id FROM segment_usage WHERE time_slot > 0);")); |
543 } | 546 } |
544 #endif | 547 #endif |
545 | 548 |
546 } // namespace history | 549 } // namespace history |
OLD | NEW |