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

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

Issue 849323002: Componentize HistoryDatabase (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix android compilation Created 5 years, 11 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 "chrome/browser/history/history_database.h" 5 #include "components/history/core/browser/history_database.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 10
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
13 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
14 #include "base/rand_util.h" 14 #include "base/rand_util.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "components/history/content/browser/download_constants_utils.h"
18 #include "content/public/browser/download_interrupt_reasons.h"
19 #include "sql/transaction.h" 17 #include "sql/transaction.h"
20 18
21 #if defined(OS_MACOSX) 19 #if defined(OS_MACOSX) && !defined(OS_IOS)
22 #include "base/mac/mac_util.h" 20 #include "base/mac/mac_util.h"
23 #endif 21 #endif
24 22
25 namespace history { 23 namespace history {
26 24
27 namespace { 25 namespace {
28 26
29 // Current version number. We write databases at the "current" version number, 27 // Current version number. We write databases at the "current" version number,
30 // but any previous version that can read the "compatible" one can make do with 28 // but any previous version that can read the "compatible" one can make do with
31 // our database without *too* many bad effects. 29 // our database without *too* many bad effects.
32 const int kCurrentVersionNumber = 29; 30 const int kCurrentVersionNumber = 29;
33 const int kCompatibleVersionNumber = 16; 31 const int kCompatibleVersionNumber = 16;
34 const char kEarlyExpirationThresholdKey[] = "early_expiration_threshold"; 32 const char kEarlyExpirationThresholdKey[] = "early_expiration_threshold";
35 33
36 } // namespace 34 } // namespace
37 35
38 HistoryDatabase::HistoryDatabase() 36 HistoryDatabase::HistoryDatabase(
39 : DownloadDatabase(ToHistoryDownloadInterruptReason( 37 DownloadInterruptReason download_interrupt_reason_none,
40 content::DOWNLOAD_INTERRUPT_REASON_NONE), 38 DownloadInterruptReason download_interrupt_reason_crash)
41 ToHistoryDownloadInterruptReason( 39 : DownloadDatabase(download_interrupt_reason_none,
42 content::DOWNLOAD_INTERRUPT_REASON_CRASH)) { 40 download_interrupt_reason_crash) {
43 } 41 }
44 42
45 HistoryDatabase::~HistoryDatabase() { 43 HistoryDatabase::~HistoryDatabase() {
46 } 44 }
47 45
48 sql::InitStatus HistoryDatabase::Init(const base::FilePath& history_name) { 46 sql::InitStatus HistoryDatabase::Init(const base::FilePath& history_name) {
49 db_.set_histogram_tag("History"); 47 db_.set_histogram_tag("History");
50 48
51 // Set the exceptional sqlite error handler. 49 // Set the exceptional sqlite error handler.
52 db_.set_error_callback(error_callback_); 50 db_.set_error_callback(error_callback_);
(...skipping 16 matching lines...) Expand all
69 67
70 if (!db_.Open(history_name)) 68 if (!db_.Open(history_name))
71 return sql::INIT_FAILURE; 69 return sql::INIT_FAILURE;
72 70
73 // Wrap the rest of init in a tranaction. This will prevent the database from 71 // Wrap the rest of init in a tranaction. This will prevent the database from
74 // getting corrupted if we crash in the middle of initialization or migration. 72 // getting corrupted if we crash in the middle of initialization or migration.
75 sql::Transaction committer(&db_); 73 sql::Transaction committer(&db_);
76 if (!committer.Begin()) 74 if (!committer.Begin())
77 return sql::INIT_FAILURE; 75 return sql::INIT_FAILURE;
78 76
79 #if defined(OS_MACOSX) 77 #if defined(OS_MACOSX) && !defined(OS_IOS)
80 // Exclude the history file from backups. 78 // Exclude the history file from backups.
81 base::mac::SetFileBackupExclusion(history_name); 79 base::mac::SetFileBackupExclusion(history_name);
82 #endif 80 #endif
83 81
84 // Prime the cache. 82 // Prime the cache.
85 db_.Preload(); 83 db_.Preload();
86 84
87 // Create the tables and indices. 85 // Create the tables and indices.
88 // NOTE: If you add something here, also add it to 86 // NOTE: If you add something here, also add it to
89 // RecreateAllButStarAndURLTables. 87 // RecreateAllButStarAndURLTables.
(...skipping 12 matching lines...) Expand all
102 // Version check. 100 // Version check.
103 sql::InitStatus version_status = EnsureCurrentVersion(); 101 sql::InitStatus version_status = EnsureCurrentVersion();
104 if (version_status != sql::INIT_OK) 102 if (version_status != sql::INIT_OK)
105 return version_status; 103 return version_status;
106 104
107 return committer.Commit() ? sql::INIT_OK : sql::INIT_FAILURE; 105 return committer.Commit() ? sql::INIT_OK : sql::INIT_FAILURE;
108 } 106 }
109 107
110 void HistoryDatabase::ComputeDatabaseMetrics( 108 void HistoryDatabase::ComputeDatabaseMetrics(
111 const base::FilePath& history_name) { 109 const base::FilePath& history_name) {
112 base::TimeTicks start_time = base::TimeTicks::Now(); 110 base::TimeTicks start_time = base::TimeTicks::Now();
113 int64 file_size = 0; 111 int64 file_size = 0;
114 if (!base::GetFileSize(history_name, &file_size)) 112 if (!base::GetFileSize(history_name, &file_size))
115 return; 113 return;
116 int file_mb = static_cast<int>(file_size / (1024 * 1024)); 114 int file_mb = static_cast<int>(file_size / (1024 * 1024));
117 UMA_HISTOGRAM_MEMORY_MB("History.DatabaseFileMB", file_mb); 115 UMA_HISTOGRAM_MEMORY_MB("History.DatabaseFileMB", file_mb);
118 116
119 sql::Statement url_count(db_.GetUniqueStatement("SELECT count(*) FROM urls")); 117 sql::Statement url_count(db_.GetUniqueStatement("SELECT count(*) FROM urls"));
120 if (!url_count.Step()) 118 if (!url_count.Step())
121 return; 119 return;
122 UMA_HISTOGRAM_COUNTS("History.URLTableCount", url_count.ColumnInt(0)); 120 UMA_HISTOGRAM_COUNTS("History.URLTableCount", url_count.ColumnInt(0));
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 "SET visit_time = visit_time + 11644473600000000 " 455 "SET visit_time = visit_time + 11644473600000000 "
458 "WHERE id IN (SELECT id FROM visits WHERE visit_time > 0);")); 456 "WHERE id IN (SELECT id FROM visits WHERE visit_time > 0);"));
459 ignore_result(db_.Execute( 457 ignore_result(db_.Execute(
460 "UPDATE segment_usage " 458 "UPDATE segment_usage "
461 "SET time_slot = time_slot + 11644473600000000 " 459 "SET time_slot = time_slot + 11644473600000000 "
462 "WHERE id IN (SELECT id FROM segment_usage WHERE time_slot > 0);")); 460 "WHERE id IN (SELECT id FROM segment_usage WHERE time_slot > 0);"));
463 } 461 }
464 #endif 462 #endif
465 463
466 } // namespace history 464 } // namespace history
OLDNEW
« no previous file with comments | « components/history/core/browser/history_database.h ('k') | components/history/core/browser/history_database_params.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698