Index: components/history/core/browser/history_backend.h |
diff --git a/components/history/core/browser/history_backend.h b/components/history/core/browser/history_backend.h |
index 303847502e6d92ef849e1042dfb818c5eb9b84f4..86173fce7c1a0b19b46a5d0fd3b691e11155a0a6 100644 |
--- a/components/history/core/browser/history_backend.h |
+++ b/components/history/core/browser/history_backend.h |
@@ -10,6 +10,7 @@ |
#include <utility> |
#include <vector> |
+#include "base/containers/hash_tables.h" |
#include "base/containers/mru_cache.h" |
#include "base/files/file_path.h" |
#include "base/gtest_prod_util.h" |
@@ -202,6 +203,9 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>, |
// Computes the |num_hosts| most-visited hostnames in the past 30 days. See |
// history_service.h for details. Returns an empty list if db_ is not |
// initialized. |
+ // |
+ // As a side effect, caches the list of top hosts for the purposes of |
+ // generating internal metrics. |
TopHostsList TopHosts(int num_hosts) const; |
// Navigation ---------------------------------------------------------------- |
@@ -521,6 +525,7 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>, |
FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, TopHosts_OnlyLast30Days); |
FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, TopHosts_MaxNumHosts); |
FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, TopHosts_IgnoreUnusualURLs); |
+ FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, RecordTopHostsMetrics); |
FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, UpdateVisitDuration); |
FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, ExpireHistoryForTimes); |
FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, DeleteFTSIndexDatabases); |
@@ -738,6 +743,8 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>, |
const URLRows& rows, |
const std::set<GURL>& favicon_urls) override; |
+ void RecordTopHostsMetrics(const GURL& url); |
+ |
// Deleting all history ------------------------------------------------------ |
// Deletes all history. This is a special case of deleting that is separated |
@@ -836,6 +843,10 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>, |
// Listens for the system being under memory pressure. |
scoped_ptr<base::MemoryPressureListener> memory_pressure_listener_; |
+ // Map from host to index in the TopHosts list. It is updated only by |
+ // TopHosts(), so it's usually stale. |
+ mutable base::hash_map<std::string, int> host_ranks_; |
+ |
// List of observers |
base::ObserverList<HistoryBackendObserver> observers_; |