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

Side by Side Diff: chrome/browser/history/history_database.cc

Issue 9071014: Database usage adjustment for .../history (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include <string>
10 10
(...skipping 30 matching lines...) Expand all
41 if (base::RandInt(1, 100) != 50) 41 if (base::RandInt(1, 100) != 50)
42 return; // Only do this computation sometimes since it can be expensive. 42 return; // Only do this computation sometimes since it can be expensive.
43 43
44 int64 file_size = 0; 44 int64 file_size = 0;
45 if (!file_util::GetFileSize(history_name, &file_size)) 45 if (!file_util::GetFileSize(history_name, &file_size))
46 return; 46 return;
47 int file_mb = static_cast<int>(file_size / (1024 * 1024)); 47 int file_mb = static_cast<int>(file_size / (1024 * 1024));
48 UMA_HISTOGRAM_MEMORY_MB("History.DatabaseFileMB", file_mb); 48 UMA_HISTOGRAM_MEMORY_MB("History.DatabaseFileMB", file_mb);
49 49
50 sql::Statement url_count(db.GetUniqueStatement("SELECT count(*) FROM urls")); 50 sql::Statement url_count(db.GetUniqueStatement("SELECT count(*) FROM urls"));
51 if (!url_count || !url_count.Step()) 51 if (!url_count.Step())
52 return; 52 return;
53 UMA_HISTOGRAM_COUNTS("History.URLTableCount", url_count.ColumnInt(0)); 53 UMA_HISTOGRAM_COUNTS("History.URLTableCount", url_count.ColumnInt(0));
54 54
55 sql::Statement visit_count(db.GetUniqueStatement( 55 sql::Statement visit_count(db.GetUniqueStatement(
56 "SELECT count(*) FROM visits")); 56 "SELECT count(*) FROM visits"));
57 if (!visit_count || !visit_count.Step()) 57 if (!visit_count.Step())
58 return; 58 return;
59 UMA_HISTOGRAM_COUNTS("History.VisitTableCount", visit_count.ColumnInt(0)); 59 UMA_HISTOGRAM_COUNTS("History.VisitTableCount", visit_count.ColumnInt(0));
60 } 60 }
61 61
62 } // namespace 62 } // namespace
63 63
64 HistoryDatabase::HistoryDatabase() 64 HistoryDatabase::HistoryDatabase()
65 : needs_version_17_migration_(false) { 65 : needs_version_17_migration_(false) {
66 } 66 }
67 67
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 181
182 bool HistoryDatabase::GetNeedsThumbnailMigration() { 182 bool HistoryDatabase::GetNeedsThumbnailMigration() {
183 int value = 0; 183 int value = 0;
184 return (meta_table_.GetValue(kNeedsThumbnailMigrationKey, &value) && 184 return (meta_table_.GetValue(kNeedsThumbnailMigrationKey, &value) &&
185 value != 0); 185 value != 0);
186 } 186 }
187 187
188 bool HistoryDatabase::SetSegmentID(VisitID visit_id, SegmentID segment_id) { 188 bool HistoryDatabase::SetSegmentID(VisitID visit_id, SegmentID segment_id) {
189 sql::Statement s(db_.GetCachedStatement(SQL_FROM_HERE, 189 sql::Statement s(db_.GetCachedStatement(SQL_FROM_HERE,
190 "UPDATE visits SET segment_id = ? WHERE id = ?")); 190 "UPDATE visits SET segment_id = ? WHERE id = ?"));
191 if (!s) {
192 NOTREACHED() << db_.GetErrorMessage();
193 return false;
194 }
195 s.BindInt64(0, segment_id); 191 s.BindInt64(0, segment_id);
196 s.BindInt64(1, visit_id); 192 s.BindInt64(1, visit_id);
197 DCHECK(db_.GetLastChangeCount() == 1); 193 DCHECK(db_.GetLastChangeCount() == 1);
Scott Hess - ex-Googler 2012/01/03 23:41:57 I'm having troubles seeing how this line could pos
Greg Billock 2012/01/04 19:20:20 I read it as saying "ASSERT(number of rows changed
Scott Hess - ex-Googler 2012/01/10 22:04:56 Do you mean an update statement which ran sometime
194
198 return s.Run(); 195 return s.Run();
199 } 196 }
200 197
201 SegmentID HistoryDatabase::GetSegmentID(VisitID visit_id) { 198 SegmentID HistoryDatabase::GetSegmentID(VisitID visit_id) {
202 sql::Statement s(db_.GetCachedStatement(SQL_FROM_HERE, 199 sql::Statement s(db_.GetCachedStatement(SQL_FROM_HERE,
203 "SELECT segment_id FROM visits WHERE id = ?")); 200 "SELECT segment_id FROM visits WHERE id = ?"));
204 if (!s) { 201 s.BindInt64(0, visit_id);
205 NOTREACHED() << db_.GetErrorMessage();
206 return 0;
207 }
208 202
209 s.BindInt64(0, visit_id);
210 if (s.Step()) { 203 if (s.Step()) {
211 if (s.ColumnType(0) == sql::COLUMN_TYPE_NULL) 204 if (s.ColumnType(0) == sql::COLUMN_TYPE_NULL)
212 return 0; 205 return 0;
213 else 206 else
214 return s.ColumnInt64(0); 207 return s.ColumnInt64(0);
Scott Hess - ex-Googler 2012/01/03 23:41:57 This line would give 0 if the column type is NULL.
Greg Billock 2012/01/04 19:20:20 So we can just return s.ColumnInt64(0)?
Scott Hess - ex-Googler 2012/01/10 22:04:56 Yes, NULL is interpreted as zero for integer reque
215 } 208 }
216 return 0; 209 return 0;
217 } 210 }
218 211
219 base::Time HistoryDatabase::GetEarlyExpirationThreshold() { 212 base::Time HistoryDatabase::GetEarlyExpirationThreshold() {
220 if (!cached_early_expiration_threshold_.is_null()) 213 if (!cached_early_expiration_threshold_.is_null())
221 return cached_early_expiration_threshold_; 214 return cached_early_expiration_threshold_;
222 215
223 int64 threshold; 216 int64 threshold;
224 if (!meta_table_.GetValue(kEarlyExpirationThresholdKey, &threshold)) { 217 if (!meta_table_.GetValue(kEarlyExpirationThresholdKey, &threshold)) {
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 "WHERE id IN (SELECT id FROM segment_usage WHERE time_slot > 0);")); 330 "WHERE id IN (SELECT id FROM segment_usage WHERE time_slot > 0);"));
338 331
339 // Erase all the full text index files. These will take a while to update and 332 // Erase all the full text index files. These will take a while to update and
340 // are less important, so we just blow them away. Same with the archived 333 // are less important, so we just blow them away. Same with the archived
341 // database. 334 // database.
342 needs_version_17_migration_ = true; 335 needs_version_17_migration_ = true;
343 } 336 }
344 #endif 337 #endif
345 338
346 } // namespace history 339 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698