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

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

Issue 2377643002: predictors: Make the resource_prefetch_predictor accessible from Java. (Closed)
Patch Set: Address comments. Created 4 years, 3 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 7461eab4562308d60c983c00de33f52738a83dab..eb0cfa69767c0f857b13e709e7b68854d0b07849 100644
--- a/chrome/browser/predictors/resource_prefetch_predictor.cc
+++ b/chrome/browser/predictors/resource_prefetch_predictor.cc
@@ -408,7 +408,7 @@ void ResourcePrefetchPredictor::OnMainFrameRequest(
DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK_EQ(INITIALIZED, initialization_state_);
- StartPrefetching(request.navigation_id);
+ StartPrefetching(request.navigation_id.main_frame_url);
// Cleanup older navigations.
CleanupAbandonedNavigations(request.navigation_id);
@@ -425,7 +425,7 @@ void ResourcePrefetchPredictor::OnMainFrameResponse(
if (initialization_state_ != INITIALIZED)
return;
- StopPrefetching(response.navigation_id);
+ StopPrefetching(response.navigation_id.main_frame_url);
}
void ResourcePrefetchPredictor::OnMainFrameRedirect(
@@ -438,7 +438,7 @@ void ResourcePrefetchPredictor::OnMainFrameRedirect(
// change.
// Stop any inflight prefetching. Remove the older navigation.
- StopPrefetching(response.navigation_id);
+ StopPrefetching(response.navigation_id.main_frame_url);
inflight_navigations_.erase(response.navigation_id);
// A redirect will not lead to another OnMainFrameRequest call, so record the
@@ -496,36 +496,30 @@ void ResourcePrefetchPredictor::OnNavigationComplete(
&history_lookup_consumer_);
}
-bool ResourcePrefetchPredictor::GetPrefetchData(
- const NavigationID& navigation_id,
- std::vector<GURL>* urls,
- PrefetchKeyType* key_type) {
+bool ResourcePrefetchPredictor::GetPrefetchData(const GURL& url,
gone 2016/09/28 18:18:15 Can you use something more descriptive than url he
Benoit L 2016/10/03 09:42:05 Done.
+ std::vector<GURL>* urls) {
DCHECK(urls);
- DCHECK(key_type);
-
- *key_type = PREFETCH_KEY_TYPE_URL;
- const GURL& main_frame_url = navigation_id.main_frame_url;
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(url.spec());
if (iterator != url_table_cache_->end())
PopulatePrefetcherRequest(iterator->second, urls);
}
+ if (!urls->empty())
+ return true;
bool use_host_data = config_.IsPrefetchingEnabled(profile_) ?
config_.IsHostPrefetchingEnabled(profile_) :
config_.IsHostLearningEnabled();
- if (urls->empty() && use_host_data) {
+ if (use_host_data) {
PrefetchDataMap::const_iterator iterator =
- host_table_cache_->find(main_frame_url.host());
- if (iterator != host_table_cache_->end()) {
- *key_type = PREFETCH_KEY_TYPE_HOST;
+ host_table_cache_->find(url.host());
+ if (iterator != host_table_cache_->end())
PopulatePrefetcherRequest(iterator->second, urls);
- }
}
return !urls->empty();
@@ -548,15 +542,12 @@ void ResourcePrefetchPredictor::PopulatePrefetcherRequest(
}
}
-void ResourcePrefetchPredictor::StartPrefetching(
- const NavigationID& navigation_id) {
+void ResourcePrefetchPredictor::StartPrefetching(const GURL& url) {
if (!prefetch_manager_.get()) // Prefetching not enabled.
return;
- // Prefer URL based data first.
- std::vector<GURL> urls;
- PrefetchKeyType key_type;
- if (!GetPrefetchData(navigation_id, &urls, &key_type)) {
+ std::vector<GURL> subresource_urls;
+ if (!GetPrefetchData(url, &subresource_urls)) {
// No prefetching data at host or URL level.
return;
}
@@ -564,19 +555,17 @@ void ResourcePrefetchPredictor::StartPrefetching(
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(&ResourcePrefetcherManager::MaybeAddPrefetch,
- prefetch_manager_, navigation_id, urls));
+ prefetch_manager_, url, subresource_urls));
}
-void ResourcePrefetchPredictor::StopPrefetching(
- const NavigationID& navigation_id) {
+void ResourcePrefetchPredictor::StopPrefetching(const GURL& url) {
if (!prefetch_manager_.get()) // Not enabled.
return;
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(&ResourcePrefetcherManager::MaybeRemovePrefetch,
- prefetch_manager_,
- navigation_id));
+ prefetch_manager_, url));
}
void ResourcePrefetchPredictor::StartInitialization() {

Powered by Google App Engine
This is Rietveld 408576698