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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/engagement/site_engagement_eviction_policy.h"
6 #include "chrome/browser/engagement/site_engagement_service.h"
7 #include "content/public/browser/browser_thread.h"
8
9 namespace {
10 const int kExpectedEngagementSites = 200;
11 } // namespace
12
13 SiteEngagementEvictionPolicy::SiteEngagementEvictionPolicy(
14 SiteEngagementService* service)
15 : engagement_service_(service) {
16 }
17 SiteEngagementEvictionPolicy::~SiteEngagementEvictionPolicy() {
18 }
19
20 GURL SiteEngagementEvictionPolicy::GetEvictionOriginOnUIThread(
21 const std::map<GURL, int64>& usage_map,
22 int64 global_quota) {
23 GURL origin_to_evict;
24 int total_engagement_points = GetTotalEngagementPoints();
25 int64 max_overuse = std::numeric_limits<int64>::min();
26 for (auto usage : usage_map) {
raymes 2015/07/08 04:43:29 const auto& usage
calamity 2015/07/10 05:05:05 Done.
27 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.
28 usage.second - GetSoftQuotaForOrigin(usage.first, global_quota,
29 total_engagement_points);
30 if (overuse > max_overuse) {
31 max_overuse = overuse;
32 origin_to_evict = usage.first;
33 }
34 }
35 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.
36 }
37
38 void SiteEngagementEvictionPolicy::GetEvictionOrigin(
39 const std::map<GURL, int64>& usage_map,
40 int64 global_quota,
41 const storage::GetEvictionOriginCallback& callback) {
42 content::BrowserThread::PostTaskAndReplyWithResult(
43 content::BrowserThread::UI, FROM_HERE,
44 base::Bind(&SiteEngagementEvictionPolicy::GetEvictionOriginOnUIThread,
45 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
46 base::Bind(&SiteEngagementEvictionPolicy::ReplyWithEvictionOrigin,
47 base::Unretained(this), callback));
48 }
49
50 int SiteEngagementEvictionPolicy::GetScore(const GURL& origin) {
51 return engagement_service_->GetScore(origin);
52 }
53
54 int SiteEngagementEvictionPolicy::GetTotalEngagementPoints() {
55 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
56 }
57
58 int64 SiteEngagementEvictionPolicy::GetSoftQuotaForOrigin(
59 const GURL& origin,
60 int64 global_quota,
61 int total_engagement_points) {
62 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
63 global_quota /
64 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
65 static_cast<double>(total_engagement_points));
66
67 return GetScore(origin) * quota_per_point;
68 }
69
70 void SiteEngagementEvictionPolicy::ReplyWithEvictionOrigin(
71 const storage::GetEvictionOriginCallback& callback,
72 const GURL& origin_to_evict) {
73 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.
74 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698