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

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

Issue 2397943004: predictors: Use redirect data in prefetch. (Closed)
Patch Set: . Created 4 years, 2 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
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 03e9570a0b1cc020038315f01d97dc01a6468e85..86624316bb32d5a0ecb0cd46b819d627d0938248 100644
--- a/chrome/browser/predictors/resource_prefetch_predictor.cc
+++ b/chrome/browser/predictors/resource_prefetch_predictor.cc
@@ -419,9 +419,6 @@ void ResourcePrefetchPredictor::OnMainFrameRedirect(
const URLRequestSummary& response) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
- // Stop any inflight prefetching. Remove the older navigation.
- StopPrefetching(response.navigation_id.main_frame_url);
-
std::unique_ptr<PageRequestSummary> summary;
NavigationMap::iterator nav_it =
inflight_navigations_.find(response.navigation_id);
@@ -493,28 +490,56 @@ bool ResourcePrefetchPredictor::GetPrefetchData(const GURL& main_frame_url,
std::vector<GURL>* urls) {
DCHECK(urls);
+ if (GetURLPrefetchData(main_frame_url.spec(), urls))
+ return true;
+
+ if (GetHostPrefetchData(main_frame_url.host(), urls))
+ return true;
+
+ std::string final_redirect;
+ if (GetFinalRedirect(main_frame_url.spec(), url_redirect_table_cache_.get(),
+ &final_redirect)) {
+ GURL redirect_url(final_redirect);
+
+ if (GetURLPrefetchData(redirect_url.spec(), urls))
+ return true;
+
+ if (GetHostPrefetchData(redirect_url.host(), urls))
+ return true;
+ }
+
+ return GetFinalRedirect(main_frame_url.host(),
+ host_redirect_table_cache_.get(), &final_redirect) &&
+ GetHostPrefetchData(final_redirect, urls);
+}
+
+bool ResourcePrefetchPredictor::GetURLPrefetchData(
+ const std::string& main_frame_url,
+ std::vector<GURL>* urls) {
bool use_url_data = config_.IsPrefetchingEnabled(profile_) ?
config_.IsURLPrefetchingEnabled(profile_) :
config_.IsURLLearningEnabled();
if (use_url_data) {
PrefetchDataMap::const_iterator iterator =
- url_table_cache_->find(main_frame_url.spec());
+ url_table_cache_->find(main_frame_url);
if (iterator != url_table_cache_->end())
PopulatePrefetcherRequest(iterator->second, urls);
}
- if (!urls->empty())
- return true;
+ return !urls->empty();
+}
+bool ResourcePrefetchPredictor::GetHostPrefetchData(
+ const std::string& main_frame_host,
+ std::vector<GURL>* urls) {
bool use_host_data = config_.IsPrefetchingEnabled(profile_) ?
config_.IsHostPrefetchingEnabled(profile_) :
config_.IsHostLearningEnabled();
if (use_host_data) {
PrefetchDataMap::const_iterator iterator =
- host_table_cache_->find(main_frame_url.host());
+ host_table_cache_->find(main_frame_host);
if (iterator != host_table_cache_->end())
PopulatePrefetcherRequest(iterator->second, urls);
}
-
return !urls->empty();
}
@@ -535,6 +560,34 @@ void ResourcePrefetchPredictor::PopulatePrefetcherRequest(
}
}
+bool ResourcePrefetchPredictor::GetFinalRedirect(
Benoit L 2016/10/07 09:52:18 The scoring code is duplicated, and it even seems
alexilin 2016/10/07 10:49:07 No, I'm not walking all the redirects here, where
alexilin 2016/10/07 13:09:29 Scan all the redirects here instead of sort while
Benoit L 2016/10/07 13:55:15 Sorry, wasn't clear enough. Thanks for reading bet
+ const std::string& first_redirect,
+ RedirectDataMap* redirect_data_map,
+ std::string* final_redirect) {
+ DCHECK(final_redirect);
+
+ RedirectDataMap::const_iterator iterator =
+ redirect_data_map->find(first_redirect);
+ if (iterator == redirect_data_map->end())
+ return false;
+
+ DCHECK(iterator->second.redirect_endpoints_size() > 0);
+ const RedirectStat& best_redirect = iterator->second.redirect_endpoints(0);
+ float confidence =
+ (best_redirect.number_of_hits() + 0.0) /
+ (best_redirect.number_of_hits() + best_redirect.number_of_misses());
+
+ const float kMinRedirectConfidenceToTriggerPrefetch = 0.7f;
+ const int kMinRedirectHitsToTriggerPrefetch = 2;
+
+ if (confidence < kMinRedirectConfidenceToTriggerPrefetch ||
+ best_redirect.number_of_hits() < kMinRedirectHitsToTriggerPrefetch)
+ return false;
+
+ *final_redirect = best_redirect.url();
+ return true;
+}
+
void ResourcePrefetchPredictor::StartPrefetching(const GURL& url) {
if (!prefetch_manager_.get()) // Prefetching not enabled.
return;

Powered by Google App Engine
This is Rietveld 408576698