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 22 matching lines...) Expand all Loading... |
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 = 32; | 39 const int kCurrentVersionNumber = 32; |
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 const int kDefaultCacheSize = 1000; |
43 | 44 |
44 } // namespace | 45 } // namespace |
45 | 46 |
46 HistoryDatabase::HistoryDatabase( | 47 HistoryDatabase::HistoryDatabase( |
47 DownloadInterruptReason download_interrupt_reason_none, | 48 DownloadInterruptReason download_interrupt_reason_none, |
48 DownloadInterruptReason download_interrupt_reason_crash) | 49 DownloadInterruptReason download_interrupt_reason_crash) |
49 : DownloadDatabase(download_interrupt_reason_none, | 50 : DownloadDatabase(download_interrupt_reason_none, |
50 download_interrupt_reason_crash) { | 51 download_interrupt_reason_crash) { |
51 } | 52 } |
52 | 53 |
53 HistoryDatabase::~HistoryDatabase() { | 54 HistoryDatabase::~HistoryDatabase() { |
54 } | 55 } |
55 | 56 |
56 sql::InitStatus HistoryDatabase::Init(const base::FilePath& history_name) { | 57 sql::InitStatus HistoryDatabase::Init(const base::FilePath& history_name) { |
57 db_.set_histogram_tag("History"); | 58 db_.set_histogram_tag("History"); |
58 | 59 |
59 // Set the database page size to something a little larger to give us | 60 // Set the database page size to something a little larger to give us |
60 // better performance (we're typically seek rather than bandwidth limited). | 61 // better performance (we're typically seek rather than bandwidth limited). |
61 // This only has an effect before any tables have been created, otherwise | 62 // This only has an effect before any tables have been created, otherwise |
62 // this is a NOP. Must be a power of 2 and a max of 8192. | 63 // this is a NOP. Must be a power of 2 and a max of 8192. |
63 db_.set_page_size(4096); | 64 db_.set_page_size(4096); |
64 | 65 |
65 // Set the cache size. The page size, plus a little extra, times this | 66 // Set the cache size. The page size, plus a little extra, times this |
66 // value, tells us how much memory the cache will use maximum. | 67 // value, tells us how much memory the cache will use maximum. |
67 // 1000 * 4kB = 4MB | 68 // 1000 * 4kB = 4MB |
68 // TODO(brettw) scale this value to the amount of available memory. | 69 // TODO(brettw) scale this value to the amount of available memory. |
69 db_.set_cache_size(1000); | 70 db_.set_cache_size(kDefaultCacheSize); |
70 | 71 |
71 // Note that we don't set exclusive locking here. That's done by | 72 // Note that we don't set exclusive locking here. That's done by |
72 // BeginExclusiveMode below which is called later (we have to be in shared | 73 // BeginExclusiveMode below which is called later (we have to be in shared |
73 // mode to start out for the in-memory backend to read the data). | 74 // mode to start out for the in-memory backend to read the data). |
74 | 75 |
75 if (!db_.Open(history_name)) | 76 if (!db_.Open(history_name)) |
76 return sql::INIT_FAILURE; | 77 return sql::INIT_FAILURE; |
77 | 78 |
78 // Wrap the rest of init in a tranaction. This will prevent the database from | 79 // Wrap the rest of init in a tranaction. This will prevent the database from |
79 // getting corrupted if we crash in the middle of initialization or migration. | 80 // getting corrupted if we crash in the middle of initialization or migration. |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 void HistoryDatabase::Vacuum() { | 289 void HistoryDatabase::Vacuum() { |
289 DCHECK_EQ(0, db_.transaction_nesting()) << | 290 DCHECK_EQ(0, db_.transaction_nesting()) << |
290 "Can not have a transaction when vacuuming."; | 291 "Can not have a transaction when vacuuming."; |
291 ignore_result(db_.Execute("VACUUM")); | 292 ignore_result(db_.Execute("VACUUM")); |
292 } | 293 } |
293 | 294 |
294 void HistoryDatabase::TrimMemory(bool aggressively) { | 295 void HistoryDatabase::TrimMemory(bool aggressively) { |
295 db_.TrimMemory(aggressively); | 296 db_.TrimMemory(aggressively); |
296 } | 297 } |
297 | 298 |
| 299 void HistoryDatabase::AdjustCacheMemory(memory_coordinator::MemoryState state) { |
| 300 int cache_size = kDefaultCacheSize; |
| 301 if (state == memory_coordinator::MemoryState::THROTTLED) { |
| 302 cache_size = cache_size / 2; |
| 303 } else if (state == memory_coordinator::MemoryState::SUSPENDED) { |
| 304 cache_size = cache_size / 4; |
| 305 } |
| 306 db_.UpdateCacheSize(cache_size); |
| 307 } |
| 308 |
298 bool HistoryDatabase::Raze() { | 309 bool HistoryDatabase::Raze() { |
299 return db_.Raze(); | 310 return db_.Raze(); |
300 } | 311 } |
301 | 312 |
302 std::string HistoryDatabase::GetDiagnosticInfo(int extended_error, | 313 std::string HistoryDatabase::GetDiagnosticInfo(int extended_error, |
303 sql::Statement* statement) { | 314 sql::Statement* statement) { |
304 return db_.GetDiagnosticInfo(extended_error, statement); | 315 return db_.GetDiagnosticInfo(extended_error, statement); |
305 } | 316 } |
306 | 317 |
307 bool HistoryDatabase::SetSegmentID(VisitID visit_id, SegmentID segment_id) { | 318 bool HistoryDatabase::SetSegmentID(VisitID visit_id, SegmentID segment_id) { |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 "SET visit_time = visit_time + 11644473600000000 " | 556 "SET visit_time = visit_time + 11644473600000000 " |
546 "WHERE id IN (SELECT id FROM visits WHERE visit_time > 0);")); | 557 "WHERE id IN (SELECT id FROM visits WHERE visit_time > 0);")); |
547 ignore_result(db_.Execute( | 558 ignore_result(db_.Execute( |
548 "UPDATE segment_usage " | 559 "UPDATE segment_usage " |
549 "SET time_slot = time_slot + 11644473600000000 " | 560 "SET time_slot = time_slot + 11644473600000000 " |
550 "WHERE id IN (SELECT id FROM segment_usage WHERE time_slot > 0);")); | 561 "WHERE id IN (SELECT id FROM segment_usage WHERE time_slot > 0);")); |
551 } | 562 } |
552 #endif | 563 #endif |
553 | 564 |
554 } // namespace history | 565 } // namespace history |
OLD | NEW |