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

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

Issue 1548113002: Switch to standard integer types in components/, part 2 of 4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: gn Created 4 years, 12 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 "components/history/core/browser/history_database.h" 5 #include "components/history/core/browser/history_database.h"
6 6
7 #include <stdint.h>
8
7 #include <algorithm> 9 #include <algorithm>
8 #include <set> 10 #include <set>
9 #include <string> 11 #include <string>
10 #include <utility> 12 #include <utility>
11 #include <vector> 13 #include <vector>
12 14
13 #include "base/command_line.h" 15 #include "base/command_line.h"
14 #include "base/containers/hash_tables.h" 16 #include "base/containers/hash_tables.h"
15 #include "base/files/file_util.h" 17 #include "base/files/file_util.h"
16 #include "base/metrics/histogram.h" 18 #include "base/metrics/histogram.h"
17 #include "base/numerics/safe_conversions.h" 19 #include "base/numerics/safe_conversions.h"
18 #include "base/rand_util.h" 20 #include "base/rand_util.h"
19 #include "base/strings/string_util.h" 21 #include "base/strings/string_util.h"
20 #include "base/time/time.h" 22 #include "base/time/time.h"
23 #include "build/build_config.h"
21 #include "components/history/core/browser/url_utils.h" 24 #include "components/history/core/browser/url_utils.h"
22 #include "sql/statement.h" 25 #include "sql/statement.h"
23 #include "sql/transaction.h" 26 #include "sql/transaction.h"
24 27
25 #if defined(OS_MACOSX) && !defined(OS_IOS) 28 #if defined(OS_MACOSX) && !defined(OS_IOS)
26 #include "base/mac/mac_util.h" 29 #include "base/mac/mac_util.h"
27 #endif 30 #endif
28 31
29 namespace history { 32 namespace history {
30 33
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 sql::InitStatus version_status = EnsureCurrentVersion(); 111 sql::InitStatus version_status = EnsureCurrentVersion();
109 if (version_status != sql::INIT_OK) 112 if (version_status != sql::INIT_OK)
110 return version_status; 113 return version_status;
111 114
112 return committer.Commit() ? sql::INIT_OK : sql::INIT_FAILURE; 115 return committer.Commit() ? sql::INIT_OK : sql::INIT_FAILURE;
113 } 116 }
114 117
115 void HistoryDatabase::ComputeDatabaseMetrics( 118 void HistoryDatabase::ComputeDatabaseMetrics(
116 const base::FilePath& history_name) { 119 const base::FilePath& history_name) {
117 base::TimeTicks start_time = base::TimeTicks::Now(); 120 base::TimeTicks start_time = base::TimeTicks::Now();
118 int64 file_size = 0; 121 int64_t file_size = 0;
119 if (!base::GetFileSize(history_name, &file_size)) 122 if (!base::GetFileSize(history_name, &file_size))
120 return; 123 return;
121 int file_mb = static_cast<int>(file_size / (1024 * 1024)); 124 int file_mb = static_cast<int>(file_size / (1024 * 1024));
122 UMA_HISTOGRAM_MEMORY_MB("History.DatabaseFileMB", file_mb); 125 UMA_HISTOGRAM_MEMORY_MB("History.DatabaseFileMB", file_mb);
123 126
124 sql::Statement url_count(db_.GetUniqueStatement("SELECT count(*) FROM urls")); 127 sql::Statement url_count(db_.GetUniqueStatement("SELECT count(*) FROM urls"));
125 if (!url_count.Step()) 128 if (!url_count.Step())
126 return; 129 return;
127 UMA_HISTOGRAM_COUNTS("History.URLTableCount", url_count.ColumnInt(0)); 130 UMA_HISTOGRAM_COUNTS("History.URLTableCount", url_count.ColumnInt(0));
128 131
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 "SELECT url, visit_count FROM urls WHERE last_visit_time > ?")); 204 "SELECT url, visit_count FROM urls WHERE last_visit_time > ?"));
202 url_sql.BindInt64(0, one_month_ago.ToInternalValue()); 205 url_sql.BindInt64(0, one_month_ago.ToInternalValue());
203 206
204 // Collect a map from host to visit count. 207 // Collect a map from host to visit count.
205 base::hash_map<std::string, int> host_count; 208 base::hash_map<std::string, int> host_count;
206 while (url_sql.Step()) { 209 while (url_sql.Step()) {
207 GURL url(url_sql.ColumnString(0)); 210 GURL url(url_sql.ColumnString(0));
208 if (!(url.is_valid() && (url.SchemeIsHTTPOrHTTPS() || url.SchemeIs("ftp")))) 211 if (!(url.is_valid() && (url.SchemeIsHTTPOrHTTPS() || url.SchemeIs("ftp"))))
209 continue; 212 continue;
210 213
211 int64 visit_count = url_sql.ColumnInt64(1); 214 int64_t visit_count = url_sql.ColumnInt64(1);
212 host_count[HostForTopHosts(url)] += visit_count; 215 host_count[HostForTopHosts(url)] += visit_count;
213 216
214 // kMaxHostsInMemory is well above typical values for 217 // kMaxHostsInMemory is well above typical values for
215 // History.MonthlyHostCount, but here to guard against unbounded memory 218 // History.MonthlyHostCount, but here to guard against unbounded memory
216 // growth in the event of an atypical history. 219 // growth in the event of an atypical history.
217 if (host_count.size() >= kMaxHostsInMemory) 220 if (host_count.size() >= kMaxHostsInMemory)
218 break; 221 break;
219 } 222 }
220 223
221 // Collect the top 100 hosts by visit count, into the range 224 // Collect the top 100 hosts by visit count, into the range
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 else 317 else
315 return s.ColumnInt64(0); 318 return s.ColumnInt64(0);
316 } 319 }
317 return 0; 320 return 0;
318 } 321 }
319 322
320 base::Time HistoryDatabase::GetEarlyExpirationThreshold() { 323 base::Time HistoryDatabase::GetEarlyExpirationThreshold() {
321 if (!cached_early_expiration_threshold_.is_null()) 324 if (!cached_early_expiration_threshold_.is_null())
322 return cached_early_expiration_threshold_; 325 return cached_early_expiration_threshold_;
323 326
324 int64 threshold; 327 int64_t threshold;
325 if (!meta_table_.GetValue(kEarlyExpirationThresholdKey, &threshold)) { 328 if (!meta_table_.GetValue(kEarlyExpirationThresholdKey, &threshold)) {
326 // Set to a very early non-zero time, so it's before all history, but not 329 // Set to a very early non-zero time, so it's before all history, but not
327 // zero to avoid re-retrieval. 330 // zero to avoid re-retrieval.
328 threshold = 1L; 331 threshold = 1L;
329 } 332 }
330 333
331 cached_early_expiration_threshold_ = base::Time::FromInternalValue(threshold); 334 cached_early_expiration_threshold_ = base::Time::FromInternalValue(threshold);
332 return cached_early_expiration_threshold_; 335 return cached_early_expiration_threshold_;
333 } 336 }
334 337
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 "SET visit_time = visit_time + 11644473600000000 " 510 "SET visit_time = visit_time + 11644473600000000 "
508 "WHERE id IN (SELECT id FROM visits WHERE visit_time > 0);")); 511 "WHERE id IN (SELECT id FROM visits WHERE visit_time > 0);"));
509 ignore_result(db_.Execute( 512 ignore_result(db_.Execute(
510 "UPDATE segment_usage " 513 "UPDATE segment_usage "
511 "SET time_slot = time_slot + 11644473600000000 " 514 "SET time_slot = time_slot + 11644473600000000 "
512 "WHERE id IN (SELECT id FROM segment_usage WHERE time_slot > 0);")); 515 "WHERE id IN (SELECT id FROM segment_usage WHERE time_slot > 0);"));
513 } 516 }
514 #endif 517 #endif
515 518
516 } // namespace history 519 } // namespace history
OLDNEW
« no previous file with comments | « components/history/core/browser/history_database.h ('k') | components/history/core/browser/history_match.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698