| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/containers/hash_tables.h" | 14 #include "base/containers/hash_tables.h" |
| 15 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
| 16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
| 17 #include "base/numerics/safe_conversions.h" | 17 #include "base/numerics/safe_conversions.h" |
| 18 #include "base/rand_util.h" | 18 #include "base/rand_util.h" |
| 19 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
| 20 #include "base/time/time.h" | 20 #include "base/time/time.h" |
| 21 #include "components/history/core/browser/url_utils.h" |
| 21 #include "sql/statement.h" | 22 #include "sql/statement.h" |
| 22 #include "sql/transaction.h" | 23 #include "sql/transaction.h" |
| 23 | 24 |
| 24 #if defined(OS_MACOSX) && !defined(OS_IOS) | 25 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 25 #include "base/mac/mac_util.h" | 26 #include "base/mac/mac_util.h" |
| 26 #endif | 27 #endif |
| 27 | 28 |
| 28 namespace history { | 29 namespace history { |
| 29 | 30 |
| 30 namespace { | 31 namespace { |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 url_sql.BindInt64(0, one_month_ago.ToInternalValue()); | 202 url_sql.BindInt64(0, one_month_ago.ToInternalValue()); |
| 202 | 203 |
| 203 // Collect a map from host to visit count. | 204 // Collect a map from host to visit count. |
| 204 base::hash_map<std::string, int> host_count; | 205 base::hash_map<std::string, int> host_count; |
| 205 while (url_sql.Step()) { | 206 while (url_sql.Step()) { |
| 206 GURL url(url_sql.ColumnString(0)); | 207 GURL url(url_sql.ColumnString(0)); |
| 207 if (!(url.is_valid() && (url.SchemeIsHTTPOrHTTPS() || url.SchemeIs("ftp")))) | 208 if (!(url.is_valid() && (url.SchemeIsHTTPOrHTTPS() || url.SchemeIs("ftp")))) |
| 208 continue; | 209 continue; |
| 209 | 210 |
| 210 int64 visit_count = url_sql.ColumnInt64(1); | 211 int64 visit_count = url_sql.ColumnInt64(1); |
| 211 std::string host = url.host(); | 212 host_count[HostForTopHosts(url)] += visit_count; |
| 212 if (StartsWithASCII(host, "www.", true)) | |
| 213 host.assign(host, 4, std::string::npos); | |
| 214 host_count[host] += visit_count; | |
| 215 | 213 |
| 216 // kMaxHostsInMemory is well above typical values for | 214 // kMaxHostsInMemory is well above typical values for |
| 217 // History.MonthlyHostCount, but here to guard against unbounded memory | 215 // History.MonthlyHostCount, but here to guard against unbounded memory |
| 218 // growth in the event of an atypical history. | 216 // growth in the event of an atypical history. |
| 219 if (host_count.size() >= kMaxHostsInMemory) | 217 if (host_count.size() >= kMaxHostsInMemory) |
| 220 break; | 218 break; |
| 221 } | 219 } |
| 222 | 220 |
| 223 // Collect the top 100 hosts by visit count, into the range | 221 // Collect the top 100 hosts by visit count, into the range |
| 224 // [top_hosts.begin(), middle). | 222 // [top_hosts.begin(), middle). |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 "SET visit_time = visit_time + 11644473600000000 " | 508 "SET visit_time = visit_time + 11644473600000000 " |
| 511 "WHERE id IN (SELECT id FROM visits WHERE visit_time > 0);")); | 509 "WHERE id IN (SELECT id FROM visits WHERE visit_time > 0);")); |
| 512 ignore_result(db_.Execute( | 510 ignore_result(db_.Execute( |
| 513 "UPDATE segment_usage " | 511 "UPDATE segment_usage " |
| 514 "SET time_slot = time_slot + 11644473600000000 " | 512 "SET time_slot = time_slot + 11644473600000000 " |
| 515 "WHERE id IN (SELECT id FROM segment_usage WHERE time_slot > 0);")); | 513 "WHERE id IN (SELECT id FROM segment_usage WHERE time_slot > 0);")); |
| 516 } | 514 } |
| 517 #endif | 515 #endif |
| 518 | 516 |
| 519 } // namespace history | 517 } // namespace history |
| OLD | NEW |