summaryrefslogtreecommitdiffstats
path: root/components/history
diff options
context:
space:
mode:
authortwifkak <twifkak@chromium.org>2015-08-13 10:56:08 -0700
committerCommit bot <commit-bot@chromium.org>2015-08-13 17:56:43 +0000
commit981c7eacd300a5bfb885a120e642e329a4eb68ce (patch)
treec5767619da3fc61a2b2dea73c278abdaab5d6084 /components/history
parent20db97e72888c16ac148d37b91aa349a9363daed (diff)
downloadchromium_src-981c7eacd300a5bfb885a120e642e329a4eb68ce.zip
chromium_src-981c7eacd300a5bfb885a120e642e329a4eb68ce.tar.gz
chromium_src-981c7eacd300a5bfb885a120e642e329a4eb68ce.tar.bz2
Add {,Non}TopHosts variants of Precache.Latency.
Add Precache.Latency.NonPrefetch.TopHosts, which records the latency only for non-prefetch requests whose referer is in the top hosts, and Precache.Latency.NonPrefetch.NonTopHosts, which records the latency for the rest of the non-prefetch requests. This allows us to evaluate the effect of precaching on latency only on those requests it has a chance of improving. Thus, we can better distinguish the effectiveness of the host selection algorithm from the effectiveness of the manifests. This adds a HostRankIfAvailable method to HistoryService, in order to expose the pre-computed TopHosts, as requiring that computation for every request would be untenable. This also adds a Control group, where TopHosts is computed for users, but no resources are prefetched. BUG=499532 Review URL: https://codereview.chromium.org/1280673004 Cr-Commit-Position: refs/heads/master@{#343230}
Diffstat (limited to 'components/history')
-rw-r--r--components/history/core/browser/history_backend.cc14
-rw-r--r--components/history/core/browser/history_backend.h7
-rw-r--r--components/history/core/browser/history_backend_unittest.cc21
-rw-r--r--components/history/core/browser/history_constants.cc2
-rw-r--r--components/history/core/browser/history_constants.h3
-rw-r--r--components/history/core/browser/history_service.cc11
-rw-r--r--components/history/core/browser/history_service.h10
7 files changed, 61 insertions, 7 deletions
diff --git a/components/history/core/browser/history_backend.cc b/components/history/core/browser/history_backend.cc
index d6dcb62..8e4cfaa 100644
--- a/components/history/core/browser/history_backend.cc
+++ b/components/history/core/browser/history_backend.cc
@@ -90,8 +90,6 @@ const int kMaxRedirectCount = 32;
// and is deleted.
const int kExpireDaysThreshold = 90;
-const int kMaxTopHostsForMetrics = 50;
-
// Converts from PageUsageData to MostVisitedURL. |redirects| is a
// list of redirects for this URL. Empty list means no redirects.
MostVisitedURL MakeMostVisitedURL(const PageUsageData& page_data,
@@ -430,6 +428,11 @@ TopHostsList HistoryBackend::TopHosts(int num_hosts) const {
return top_hosts;
}
+int HistoryBackend::HostRankIfAvailable(const GURL& url) const {
+ auto it = host_ranks_.find(HostForTopHosts(url));
+ return it != host_ranks_.end() ? it->second : kMaxTopHosts;
+}
+
void HistoryBackend::AddPage(const HistoryAddPageArgs& request) {
if (!db_)
return;
@@ -743,12 +746,9 @@ void HistoryBackend::CloseAllDatabases() {
}
void HistoryBackend::RecordTopHostsMetrics(const GURL& url) {
- auto it = host_ranks_.find(HostForTopHosts(url));
- int host_rank = it != host_ranks_.end() ? it->second : kMaxTopHostsForMetrics;
-
// Convert index from 0-based to 1-based.
- UMA_HISTOGRAM_ENUMERATION("History.TopHostsVisitsByRank", host_rank + 1,
- kMaxTopHostsForMetrics + 2);
+ UMA_HISTOGRAM_ENUMERATION("History.TopHostsVisitsByRank",
+ HostRankIfAvailable(url) + 1, kMaxTopHosts + 2);
}
std::pair<URLID, VisitID> HistoryBackend::AddPageVisit(
diff --git a/components/history/core/browser/history_backend.h b/components/history/core/browser/history_backend.h
index 78de7d4..51f9519 100644
--- a/components/history/core/browser/history_backend.h
+++ b/components/history/core/browser/history_backend.h
@@ -212,6 +212,12 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>,
// generating internal metrics.
TopHostsList TopHosts(int num_hosts) const;
+ // Returns, for the given URL, a 0-based index into the list produced by
+ // TopHosts(), corresponding to that URL's host. If TopHosts() has not
+ // previously been run, or the host is not in the top kMaxTopHosts, returns
+ // kMaxTopHosts.
+ int HostRankIfAvailable(const GURL& url) const;
+
// Navigation ----------------------------------------------------------------
// |request.time| must be unique with high probability.
@@ -541,6 +547,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, HostRankIfAvailable);
FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, RecordTopHostsMetrics);
FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, UpdateVisitDuration);
FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, ExpireHistoryForTimes);
diff --git a/components/history/core/browser/history_backend_unittest.cc b/components/history/core/browser/history_backend_unittest.cc
index 54df3f2..a4a3d9d9 100644
--- a/components/history/core/browser/history_backend_unittest.cc
+++ b/components/history/core/browser/history_backend_unittest.cc
@@ -3263,6 +3263,27 @@ TEST_F(HistoryBackendTest, TopHosts_IgnoreUnusualURLs) {
EXPECT_THAT(backend_->TopHosts(5), ElementsAre(std::make_pair("cnn.com", 3)));
}
+TEST_F(HistoryBackendTest, HostRankIfAvailable) {
+ std::vector<GURL> urls;
+ urls.push_back(GURL("http://cnn.com/us"));
+ urls.push_back(GURL("http://cnn.com/intl"));
+ urls.push_back(GURL("http://dogtopia.com/"));
+ for (const auto& url : urls) {
+ backend_->AddPageVisit(url, base::Time::Now(), 0, ui::PAGE_TRANSITION_LINK,
+ history::SOURCE_BROWSED);
+ }
+
+ EXPECT_EQ(kMaxTopHosts,
+ backend_->HostRankIfAvailable(GURL("http://cnn.com/")));
+
+ backend_->TopHosts(3);
+
+ EXPECT_EQ(0, backend_->HostRankIfAvailable(GURL("http://cnn.com/")));
+ EXPECT_EQ(1, backend_->HostRankIfAvailable(GURL("http://dogtopia.com/")));
+ EXPECT_EQ(kMaxTopHosts,
+ backend_->HostRankIfAvailable(GURL("http://catsylvania.com/")));
+}
+
TEST_F(HistoryBackendTest, RecordTopHostsMetrics) {
base::HistogramTester histogram;
diff --git a/components/history/core/browser/history_constants.cc b/components/history/core/browser/history_constants.cc
index 1b18dc7..842ed43 100644
--- a/components/history/core/browser/history_constants.cc
+++ b/components/history/core/browser/history_constants.cc
@@ -20,4 +20,6 @@ const base::FilePath::CharType kThumbnailsFilename[] =
const base::FilePath::CharType kTopSitesFilename[] =
FILE_PATH_LITERAL("Top Sites");
+const int kMaxTopHosts = 50;
+
} // namespace history
diff --git a/components/history/core/browser/history_constants.h b/components/history/core/browser/history_constants.h
index 875b099..14b0c24 100644
--- a/components/history/core/browser/history_constants.h
+++ b/components/history/core/browser/history_constants.h
@@ -16,6 +16,9 @@ extern const base::FilePath::CharType kHistoryFilename[];
extern const base::FilePath::CharType kThumbnailsFilename[];
extern const base::FilePath::CharType kTopSitesFilename[];
+// The maximum size of the list returned by history::HistoryService::TopHosts().
+extern const int kMaxTopHosts;
+
} // namespace history
#endif // COMPONENTS_HISTORY_CORE_BROWSER_HISTORY_CONSTANTS_H_
diff --git a/components/history/core/browser/history_service.cc b/components/history/core/browser/history_service.cc
index 12e83d4..28bdd51 100644
--- a/components/history/core/browser/history_service.cc
+++ b/components/history/core/browser/history_service.cc
@@ -368,6 +368,17 @@ void HistoryService::TopHosts(int num_hosts,
callback);
}
+void HistoryService::HostRankIfAvailable(
+ const GURL& url,
+ const base::Callback<void(int)>& callback) const {
+ DCHECK(thread_) << "History service being called after cleanup";
+ DCHECK(thread_checker_.CalledOnValidThread());
+ PostTaskAndReplyWithResult(thread_->task_runner().get(), FROM_HERE,
+ base::Bind(&HistoryBackend::HostRankIfAvailable,
+ history_backend_.get(), url),
+ callback);
+}
+
void HistoryService::AddPage(const GURL& url,
Time time,
ContextID context_id,
diff --git a/components/history/core/browser/history_service.h b/components/history/core/browser/history_service.h
index fbf1e72..f197d2b 100644
--- a/components/history/core/browser/history_service.h
+++ b/components/history/core/browser/history_service.h
@@ -166,6 +166,16 @@ class HistoryService : public syncer::SyncableService, public KeyedService {
// Note: Virtual needed for mocking.
virtual void TopHosts(int num_hosts, const TopHostsCallback& callback) const;
+ // Returns, for the given URL, a 0-based index into the list produced by
+ // TopHosts(), corresponding to that URL's host. If TopHosts() has not
+ // previously been run, or the host is not in the top kMaxTopHosts, returns
+ // kMaxTopHosts.
+ //
+ // Note: Virtual needed for mocking.
+ virtual void HostRankIfAvailable(
+ const GURL& url,
+ const base::Callback<void(int)>& callback) const;
+
// Navigation ----------------------------------------------------------------
// Adds the given canonical URL to history with the given time as the visit