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

Unified Diff: chrome/browser/predictors/resource_prefetch_predictor.cc

Issue 2632503005: predictors: Collect page load metrics for ResourcePrefetchPredictor. (Closed)
Patch Set: Mark suffix as base. Created 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/predictors/resource_prefetch_predictor.h ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/predictors/resource_prefetch_predictor.cc
diff --git a/chrome/browser/predictors/resource_prefetch_predictor.cc b/chrome/browser/predictors/resource_prefetch_predictor.cc
index e20ba57defd47cf09679ba46bc74bd5234b9b0d6..2da784f0cc482159d02edf1f6233ab8357c5e05e 100644
--- a/chrome/browser/predictors/resource_prefetch_predictor.cc
+++ b/chrome/browser/predictors/resource_prefetch_predictor.cc
@@ -539,6 +539,14 @@ void ResourcePrefetchPredictor::OnPrefetchingFinished(
observer_->OnPrefetchingFinished(main_frame_url);
}
+bool ResourcePrefetchPredictor::IsUrlPrefetchable(const GURL& main_frame_url) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ if (initialization_state_ != INITIALIZED)
+ return false;
+
+ return GetPrefetchData(main_frame_url, nullptr);
+}
+
void ResourcePrefetchPredictor::SetObserverForTesting(TestObserver* observer) {
observer_ = observer;
}
@@ -662,9 +670,8 @@ void ResourcePrefetchPredictor::OnNavigationComplete(
}
bool ResourcePrefetchPredictor::GetPrefetchData(const GURL& main_frame_url,
- std::vector<GURL>* urls) {
- DCHECK(urls);
- DCHECK(urls->empty());
+ std::vector<GURL>* urls) const {
+ DCHECK(!urls || urls->empty());
// Fetch URLs based on a redirect endpoint for URL/host first.
std::string redirect_endpoint;
@@ -693,19 +700,21 @@ bool ResourcePrefetchPredictor::GetPrefetchData(const GURL& main_frame_url,
bool ResourcePrefetchPredictor::PopulatePrefetcherRequest(
const std::string& main_frame_key,
const PrefetchDataMap& data_map,
- std::vector<GURL>* urls) {
- DCHECK(urls);
+ std::vector<GURL>* urls) const {
PrefetchDataMap::const_iterator it = data_map.find(main_frame_key);
if (it == data_map.end())
return false;
- size_t initial_size = urls->size();
+ bool has_prefetchable_resource = false;
for (const ResourceData& resource : it->second.resources()) {
- if (IsResourcePrefetchable(resource))
- urls->push_back(GURL(resource.resource_url()));
+ if (IsResourcePrefetchable(resource)) {
+ has_prefetchable_resource = true;
+ if (urls)
+ urls->push_back(GURL(resource.resource_url()));
+ }
}
- return urls->size() > initial_size;
+ return has_prefetchable_resource;
}
void ResourcePrefetchPredictor::CreateCaches(
@@ -1148,20 +1157,6 @@ void ResourcePrefetchPredictor::LearnRedirect(const std::string& key,
}
}
-bool ResourcePrefetchPredictor::IsDataPrefetchable(
- const std::string& main_frame_key,
- const PrefetchDataMap& data_map) const {
- PrefetchDataMap::const_iterator it = data_map.find(main_frame_key);
- if (it == data_map.end())
- return false;
-
- return std::any_of(it->second.resources().begin(),
- it->second.resources().end(),
- [this](const ResourceData& resource) {
- return IsResourcePrefetchable(resource);
- });
-}
-
bool ResourcePrefetchPredictor::IsResourcePrefetchable(
const ResourceData& resource) const {
float confidence = static_cast<float>(resource.number_of_hits()) /
@@ -1186,9 +1181,10 @@ void ResourcePrefetchPredictor::ReportDatabaseReadiness(
// Hostnames in TopHostsLists are stripped of their 'www.' prefix. We
// assume that www.foo.com entry from |host_table_cache_| is also suitable
// for foo.com.
- if (IsDataPrefetchable(host, *host_table_cache_) ||
+ if (PopulatePrefetcherRequest(host, *host_table_cache_, nullptr) ||
(!base::StartsWith(host, "www.", base::CompareCase::SENSITIVE) &&
- IsDataPrefetchable("www." + host, *host_table_cache_))) {
+ PopulatePrefetcherRequest("www." + host, *host_table_cache_,
+ nullptr))) {
++count_in_cache;
}
}
« no previous file with comments | « chrome/browser/predictors/resource_prefetch_predictor.h ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698