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

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

Issue 2623553003: precache: Add geometric resource weight function. (Closed)
Patch Set: Add comments and tests. 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 | « components/precache/core/precache_fetcher.h ('k') | 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 1a372c8dd152cf6d6d3b0c00a6f017e468c928a0..fd3ea88c7c3a5046116a29a3b583be44fcb04fa8 100644
--- a/components/precache/core/precache_fetcher.cc
+++ b/components/precache/core/precache_fetcher.cc
@@ -28,7 +28,6 @@
#include "components/data_use_measurement/core/data_use_user_data.h"
#include "components/precache/core/precache_database.h"
#include "components/precache/core/precache_switches.h"
-#include "components/precache/core/proto/precache.pb.h"
#include "components/precache/core/proto/quota.pb.h"
#include "components/precache/core/proto/unfinished_work.pb.h"
#include "net/base/completion_callback.h"
@@ -229,12 +228,31 @@ bool IsQuotaTimeExpired(const PrecacheQuota& quota,
start_time + base::TimeDelta::FromDays(1) < time_now;
}
-double ResourceWeight(const PrecacheResource& resource, int64_t host_visits) {
- return resource.weight_ratio() * host_visits;
+// Models the expected number of requests for the resource.
bengr 2017/01/12 18:48:01 Please describe the parameters here and at lines 2
twifkak 2017/01/12 20:53:39 Done.
+double NaiveResourceWeight(double resource_weight_ratio, int64_t host_visits) {
+ return resource_weight_ratio * host_visits;
+}
+
+// Models the probability of at least one request for the resource.
+double GeometricResourceWeight(double resource_weight_ratio,
+ int64_t host_visits) {
+ return 1 - pow(1 - resource_weight_ratio, host_visits);
}
} // namespace
+double ResourceWeight(
+ PrecacheConfigurationSettings::ResourceWeightFunction function,
+ double resource_weight_ratio,
+ int64_t host_visits) {
+ switch (function) {
+ case PrecacheConfigurationSettings::FUNCTION_NAIVE:
+ return NaiveResourceWeight(resource_weight_ratio, host_visits);
+ case PrecacheConfigurationSettings::FUNCTION_GEOMETRIC:
+ return GeometricResourceWeight(resource_weight_ratio, host_visits);
+ }
+}
+
PrecacheFetcher::Fetcher::Fetcher(
net::URLRequestContextGetter* request_context,
const GURL& url,
@@ -717,7 +735,9 @@ void PrecacheFetcher::OnManifestFetchComplete(int64_t host_visits,
manifest.resource(i).has_url()) {
GURL url(manifest.resource(i).url());
if (url.is_valid()) {
- double weight = ResourceWeight(manifest.resource(i), 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())
resources_to_rank_.emplace_back(url, source.referrer(), weight);
}
« no previous file with comments | « components/precache/core/precache_fetcher.h ('k') | components/precache/core/precache_fetcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698