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

Unified Diff: components/precache/core/precache_fetcher.cc

Issue 2707053005: precache: Fix top_resources_count + experiments. (Closed)
Patch Set: Rebase (again). Created 3 years, 10 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 | « no previous file | components/precache/core/precache_fetcher_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/precache/core/precache_fetcher.cc
diff --git a/components/precache/core/precache_fetcher.cc b/components/precache/core/precache_fetcher.cc
index 910659921849f0022557c1ae68e90cb0c7b66b72..1e32f6b4ea06b46f9629b9472d6e87ac189905f4 100644
--- a/components/precache/core/precache_fetcher.cc
+++ b/components/precache/core/precache_fetcher.cc
@@ -764,12 +764,14 @@ void PrecacheFetcher::OnManifestFetchComplete(int64_t host_visits,
PrecacheManifest manifest;
if (ParseProtoFromFetchResponse(*source.network_url_fetcher(), &manifest)) {
- const int32_t len =
- std::min(manifest.resource_size(),
- unfinished_work_->config_settings().top_resources_count());
const base::Optional<std::vector<bool>> resource_bitset =
GetResourceBitset(manifest, experiment_id_);
- for (int i = 0; i < len; ++i) {
+ const int32_t included_resources_max =
+ unfinished_work_->config_settings().top_resources_count();
+ int32_t included_resources = 0;
+ for (int i = 0; i < manifest.resource_size() &&
+ included_resources < included_resources_max;
+ ++i) {
if ((!resource_bitset.has_value() || resource_bitset.value()[i]) &&
manifest.resource(i).has_url()) {
GURL url(manifest.resource(i).url());
@@ -777,8 +779,10 @@ void PrecacheFetcher::OnManifestFetchComplete(int64_t host_visits,
double weight = ResourceWeight(
unfinished_work_->config_settings().resource_weight_function(),
manifest.resource(i).weight_ratio(), host_visits);
- if (weight >= unfinished_work_->config_settings().min_weight())
+ if (weight >= unfinished_work_->config_settings().min_weight()) {
resources_to_rank_.emplace_back(url, source.referrer(), weight);
+ ++included_resources;
+ }
}
}
}
« no previous file with comments | « no previous file | components/precache/core/precache_fetcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698