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

Side by Side Diff: chrome/browser/engagement/site_engagement_service.cc

Issue 1363523003: Enable SiteEngagementEvictionPolicy behind --enable-site-eviction-policy flag. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lru_policy_gooood
Patch Set: Created 5 years, 1 month 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
« no previous file with comments | « chrome/browser/engagement/site_engagement_service.h ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/engagement/site_engagement_service.h" 5 #include "chrome/browser/engagement/site_engagement_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/metrics/field_trial.h" 12 #include "base/metrics/field_trial.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/time/clock.h" 14 #include "base/time/clock.h"
15 #include "base/time/default_clock.h" 15 #include "base/time/default_clock.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 17 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
18 #include "chrome/browser/engagement/site_engagement_eviction_policy.h"
18 #include "chrome/browser/engagement/site_engagement_helper.h" 19 #include "chrome/browser/engagement/site_engagement_helper.h"
19 #include "chrome/browser/engagement/site_engagement_service_factory.h" 20 #include "chrome/browser/engagement/site_engagement_service_factory.h"
20 #include "chrome/common/chrome_switches.h" 21 #include "chrome/common/chrome_switches.h"
21 #include "components/content_settings/core/browser/host_content_settings_map.h" 22 #include "components/content_settings/core/browser/host_content_settings_map.h"
22 #include "components/content_settings/core/common/content_settings_pattern.h" 23 #include "components/content_settings/core/common/content_settings_pattern.h"
23 #include "components/variations/variations_associated_data.h" 24 #include "components/variations/variations_associated_data.h"
24 #include "content/public/browser/browser_thread.h" 25 #include "content/public/browser/browser_thread.h"
25 #include "url/gurl.h" 26 #include "url/gurl.h"
26 27
27 namespace { 28 namespace {
28 29
29 // Global bool to ensure we only update the parameters from variations once. 30 // Global bool to ensure we only update the parameters from variations once.
30 bool g_updated_from_variations = false; 31 bool g_updated_from_variations = false;
31 32
32 // Keys used in the variations params. 33 // Keys used in the variations params.
33 const char kEngagementParams[] = "SiteEngagement";
34 const char kMaxPointsPerDayParam[] = "max_points_per_day"; 34 const char kMaxPointsPerDayParam[] = "max_points_per_day";
35 const char kNavigationPointsParam[] = "navigation_points"; 35 const char kNavigationPointsParam[] = "navigation_points";
36 const char kUserInputPointsParam[] = "user_input_points"; 36 const char kUserInputPointsParam[] = "user_input_points";
37 const char kDecayPeriodInDaysParam[] = "decay_period_in_days"; 37 const char kDecayPeriodInDaysParam[] = "decay_period_in_days";
38 const char kDecayPointsParam[] = "decay_points"; 38 const char kDecayPointsParam[] = "decay_points";
39 39
40 // Length of time between metrics logging. 40 // Length of time between metrics logging.
41 const base::TimeDelta metrics_interval = base::TimeDelta::FromMinutes(60); 41 const base::TimeDelta metrics_interval = base::TimeDelta::FromMinutes(60);
42 42
43 // Delta within which to consider scores equal. 43 // Delta within which to consider scores equal.
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 double SiteEngagementScore::g_user_input_points = 0.05; 103 double SiteEngagementScore::g_user_input_points = 0.05;
104 int SiteEngagementScore::g_decay_period_in_days = 7; 104 int SiteEngagementScore::g_decay_period_in_days = 7;
105 double SiteEngagementScore::g_decay_points = 5; 105 double SiteEngagementScore::g_decay_points = 5;
106 106
107 const char* SiteEngagementScore::kRawScoreKey = "rawScore"; 107 const char* SiteEngagementScore::kRawScoreKey = "rawScore";
108 const char* SiteEngagementScore::kPointsAddedTodayKey = "pointsAddedToday"; 108 const char* SiteEngagementScore::kPointsAddedTodayKey = "pointsAddedToday";
109 const char* SiteEngagementScore::kLastEngagementTimeKey = "lastEngagementTime"; 109 const char* SiteEngagementScore::kLastEngagementTimeKey = "lastEngagementTime";
110 110
111 void SiteEngagementScore::UpdateFromVariations() { 111 void SiteEngagementScore::UpdateFromVariations() {
112 std::string max_points_per_day_param = variations::GetVariationParamValue( 112 std::string max_points_per_day_param = variations::GetVariationParamValue(
113 kEngagementParams, kMaxPointsPerDayParam); 113 SiteEngagementService::kEngagementParams, kMaxPointsPerDayParam);
114 std::string navigation_points_param = variations::GetVariationParamValue( 114 std::string navigation_points_param = variations::GetVariationParamValue(
115 kEngagementParams, kNavigationPointsParam); 115 SiteEngagementService::kEngagementParams, kNavigationPointsParam);
116 std::string user_input_points_param = variations::GetVariationParamValue( 116 std::string user_input_points_param = variations::GetVariationParamValue(
117 kEngagementParams, kUserInputPointsParam); 117 SiteEngagementService::kEngagementParams, kUserInputPointsParam);
118 std::string decay_period_in_days_param = variations::GetVariationParamValue( 118 std::string decay_period_in_days_param = variations::GetVariationParamValue(
119 kEngagementParams, kDecayPeriodInDaysParam); 119 SiteEngagementService::kEngagementParams, kDecayPeriodInDaysParam);
120 std::string decay_points_param = variations::GetVariationParamValue( 120 std::string decay_points_param = variations::GetVariationParamValue(
121 kEngagementParams, kDecayPointsParam); 121 SiteEngagementService::kEngagementParams, kDecayPointsParam);
122 122
123 if (!max_points_per_day_param.empty() && !navigation_points_param.empty() && 123 if (!max_points_per_day_param.empty() && !navigation_points_param.empty() &&
124 !user_input_points_param.empty() && !decay_period_in_days_param.empty() && 124 !user_input_points_param.empty() && !decay_period_in_days_param.empty() &&
125 !decay_points_param.empty()) { 125 !decay_points_param.empty()) {
126 double max_points_per_day = 0; 126 double max_points_per_day = 0;
127 double navigation_points = 0; 127 double navigation_points = 0;
128 double user_input_points = 0; 128 double user_input_points = 0;
129 int decay_period_in_days = 0; 129 int decay_period_in_days = 0;
130 double decay_points = 0; 130 double decay_points = 0;
131 131
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 // applied. 236 // applied.
237 int days_since_engagement = (clock_->Now() - last_engagement_time_).InDays(); 237 int days_since_engagement = (clock_->Now() - last_engagement_time_).InDays();
238 if (days_since_engagement < 0) 238 if (days_since_engagement < 0)
239 return raw_score_; 239 return raw_score_;
240 240
241 int periods = days_since_engagement / g_decay_period_in_days; 241 int periods = days_since_engagement / g_decay_period_in_days;
242 double decayed_score = raw_score_ - periods * g_decay_points; 242 double decayed_score = raw_score_ - periods * g_decay_points;
243 return std::max(0.0, decayed_score); 243 return std::max(0.0, decayed_score);
244 } 244 }
245 245
246 const char SiteEngagementService::kEngagementParams[] = "SiteEngagement";
247
246 // static 248 // static
247 SiteEngagementService* SiteEngagementService::Get(Profile* profile) { 249 SiteEngagementService* SiteEngagementService::Get(Profile* profile) {
248 return SiteEngagementServiceFactory::GetForProfile(profile); 250 return SiteEngagementServiceFactory::GetForProfile(profile);
249 } 251 }
250 252
251 // static 253 // static
252 bool SiteEngagementService::IsEnabled() { 254 bool SiteEngagementService::IsEnabled() {
253 const std::string group_name = 255 // If the engagement service or any of its dependencies are force-enabled,
254 base::FieldTrialList::FindFullName(kEngagementParams); 256 // return true immediately.
255 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 257 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
256 switches::kEnableSiteEngagementService)) { 258 switches::kEnableSiteEngagementService) ||
259 SiteEngagementEvictionPolicy::IsEnabled()) {
257 return true; 260 return true;
258 } 261 }
262
259 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 263 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
260 switches::kDisableSiteEngagementService)) { 264 switches::kDisableSiteEngagementService)) {
261 return false; 265 return false;
262 } 266 }
267 const std::string group_name =
268 base::FieldTrialList::FindFullName(kEngagementParams);
263 return base::StartsWith(group_name, "Enabled", base::CompareCase::SENSITIVE); 269 return base::StartsWith(group_name, "Enabled", base::CompareCase::SENSITIVE);
264 } 270 }
265 271
266 // static 272 // static
267 void SiteEngagementService::ClearHistoryForURLs(Profile* profile, 273 void SiteEngagementService::ClearHistoryForURLs(Profile* profile,
268 const std::set<GURL>& origins) { 274 const std::set<GURL>& origins) {
269 HostContentSettingsMap* settings_map = 275 HostContentSettingsMap* settings_map =
270 HostContentSettingsMapFactory::GetForProfile(profile); 276 HostContentSettingsMapFactory::GetForProfile(profile);
271 277
272 for (const GURL& origin_url : origins) { 278 for (const GURL& origin_url : origins) {
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 int SiteEngagementService::OriginsWithMaxEngagement( 496 int SiteEngagementService::OriginsWithMaxEngagement(
491 std::map<GURL, double>& score_map) { 497 std::map<GURL, double>& score_map) {
492 int total_origins = 0; 498 int total_origins = 0;
493 499
494 for (const auto& value : score_map) 500 for (const auto& value : score_map)
495 if (value.second == SiteEngagementScore::kMaxPoints) 501 if (value.second == SiteEngagementScore::kMaxPoints)
496 ++total_origins; 502 ++total_origins;
497 503
498 return total_origins; 504 return total_origins;
499 } 505 }
OLDNEW
« no previous file with comments | « chrome/browser/engagement/site_engagement_service.h ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698