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

Unified Diff: chrome/browser/engagement/site_engagement_eviction_policy.cc

Issue 1221523003: Add a SiteEngagementEvictionPolicy. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@get_total_engagement_points
Patch Set: Created 5 years, 5 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/engagement/site_engagement_eviction_policy.cc
diff --git a/chrome/browser/engagement/site_engagement_eviction_policy.cc b/chrome/browser/engagement/site_engagement_eviction_policy.cc
new file mode 100644
index 0000000000000000000000000000000000000000..36ff260cbffe83c47328af819cc79d034f3be589
--- /dev/null
+++ b/chrome/browser/engagement/site_engagement_eviction_policy.cc
@@ -0,0 +1,74 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/engagement/site_engagement_eviction_policy.h"
+#include "chrome/browser/engagement/site_engagement_service.h"
+#include "content/public/browser/browser_thread.h"
+
+namespace {
+const int kExpectedEngagementSites = 200;
+} // namespace
+
+SiteEngagementEvictionPolicy::SiteEngagementEvictionPolicy(
+ SiteEngagementService* service)
+ : engagement_service_(service) {
+}
+SiteEngagementEvictionPolicy::~SiteEngagementEvictionPolicy() {
+}
+
+GURL SiteEngagementEvictionPolicy::GetEvictionOriginOnUIThread(
+ const std::map<GURL, int64>& usage_map,
+ int64 global_quota) {
+ GURL origin_to_evict;
+ int total_engagement_points = GetTotalEngagementPoints();
+ int64 max_overuse = std::numeric_limits<int64>::min();
+ for (auto usage : usage_map) {
raymes 2015/07/08 04:43:29 const auto& usage
calamity 2015/07/10 05:05:05 Done.
+ int64 overuse =
raymes 2015/07/21 03:16:00 hmm overuse sort of implies that this will always
calamity 2015/07/21 04:57:09 Done.
+ usage.second - GetSoftQuotaForOrigin(usage.first, global_quota,
+ total_engagement_points);
+ if (overuse > max_overuse) {
+ max_overuse = overuse;
+ origin_to_evict = usage.first;
+ }
+ }
+ return origin_to_evict;
raymes 2015/07/08 04:43:29 As discussed offline, this is a heuristic but I th
calamity 2015/07/10 05:05:05 Done.
+}
+
+void SiteEngagementEvictionPolicy::GetEvictionOrigin(
+ const std::map<GURL, int64>& usage_map,
+ int64 global_quota,
+ const storage::GetEvictionOriginCallback& callback) {
+ content::BrowserThread::PostTaskAndReplyWithResult(
+ content::BrowserThread::UI, FROM_HERE,
+ base::Bind(&SiteEngagementEvictionPolicy::GetEvictionOriginOnUIThread,
+ base::Unretained(this), usage_map, global_quota),
raymes 2015/07/08 04:43:29 Are we sure this object will be alive for the life
calamity 2015/07/10 05:05:05 As discussed this should be solved with a big refa
+ base::Bind(&SiteEngagementEvictionPolicy::ReplyWithEvictionOrigin,
+ base::Unretained(this), callback));
+}
+
+int SiteEngagementEvictionPolicy::GetScore(const GURL& origin) {
+ return engagement_service_->GetScore(origin);
+}
+
+int SiteEngagementEvictionPolicy::GetTotalEngagementPoints() {
+ return engagement_service_->GetTotalEngagementPoints();
raymes 2015/07/08 04:43:29 Did you consider making these functions virtual in
calamity 2015/07/10 05:05:05 I did. I'm not sure how much the site engagement s
raymes 2015/07/21 03:16:00 Ok, sounds good. I didn't notice a TODO but maybe
calamity 2015/07/21 04:57:09 This changed and there's a TestSiteEngagementServi
raymes 2015/07/21 09:22:19 I still think we should eventually remove the virt
+}
+
+int64 SiteEngagementEvictionPolicy::GetSoftQuotaForOrigin(
+ const GURL& origin,
+ int64 global_quota,
+ int total_engagement_points) {
+ double quota_per_point =
raymes 2015/07/08 04:43:29 Out of curiosity, what units is quota? I would gue
calamity 2015/07/10 05:05:05 Bytes. Do you think that it's worth doing this any
+ global_quota /
+ std::max(kExpectedEngagementSites * SiteEngagementScore::kMaxPoints,
raymes 2015/07/08 04:43:29 Hmm, what is kExpectedEngagementSites exactly? Is
calamity 2015/07/10 05:05:05 It's a reasonable minimum. This is there so that t
raymes 2015/07/21 03:16:00 Hmm say the number of points was 3 and site A had
calamity 2015/07/21 04:57:09 Yeah, this was definitely something I was thinking
+ static_cast<double>(total_engagement_points));
+
+ return GetScore(origin) * quota_per_point;
+}
+
+void SiteEngagementEvictionPolicy::ReplyWithEvictionOrigin(
+ const storage::GetEvictionOriginCallback& callback,
+ const GURL& origin_to_evict) {
+ callback.Run(origin_to_evict);
raymes 2015/07/08 04:43:29 We should be able to pull this out into a function
calamity 2015/07/10 05:05:05 Done.
+}

Powered by Google App Engine
This is Rietveld 408576698