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

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: fix flag dependencies 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
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 {
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 return std::max(0.0, decayed_score); 244 return std::max(0.0, decayed_score);
244 } 245 }
245 246
246 // static 247 // static
247 SiteEngagementService* SiteEngagementService::Get(Profile* profile) { 248 SiteEngagementService* SiteEngagementService::Get(Profile* profile) {
248 return SiteEngagementServiceFactory::GetForProfile(profile); 249 return SiteEngagementServiceFactory::GetForProfile(profile);
249 } 250 }
250 251
251 // static 252 // static
252 bool SiteEngagementService::IsEnabled() { 253 bool SiteEngagementService::IsEnabled() {
253 const std::string group_name = 254 // If the engagement service or any of its dependencies are force-enabled,
254 base::FieldTrialList::FindFullName(kEngagementParams); 255 // return true immediately.
255 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 256 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
256 switches::kEnableSiteEngagementService)) { 257 switches::kEnableSiteEngagementService) ||
258 SiteEngagementEvictionPolicy::IsEnabled()) {
257 return true; 259 return true;
258 } 260 }
261
259 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 262 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
260 switches::kDisableSiteEngagementService)) { 263 switches::kDisableSiteEngagementService)) {
261 return false; 264 return false;
262 } 265 }
266 const std::string group_name =
267 base::FieldTrialList::FindFullName(kEngagementParams);
263 return base::StartsWith(group_name, "Enabled", base::CompareCase::SENSITIVE); 268 return base::StartsWith(group_name, "Enabled", base::CompareCase::SENSITIVE);
264 } 269 }
265 270
266 // static 271 // static
267 void SiteEngagementService::ClearHistoryForURLs(Profile* profile, 272 void SiteEngagementService::ClearHistoryForURLs(Profile* profile,
268 const std::set<GURL>& origins) { 273 const std::set<GURL>& origins) {
269 HostContentSettingsMap* settings_map = 274 HostContentSettingsMap* settings_map =
270 HostContentSettingsMapFactory::GetForProfile(profile); 275 HostContentSettingsMapFactory::GetForProfile(profile);
271 276
272 for (const GURL& origin_url : origins) { 277 for (const GURL& origin_url : origins) {
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 int SiteEngagementService::OriginsWithMaxEngagement( 495 int SiteEngagementService::OriginsWithMaxEngagement(
491 std::map<GURL, double>& score_map) { 496 std::map<GURL, double>& score_map) {
492 int total_origins = 0; 497 int total_origins = 0;
493 498
494 for (const auto& value : score_map) 499 for (const auto& value : score_map)
495 if (value.second == SiteEngagementScore::kMaxPoints) 500 if (value.second == SiteEngagementScore::kMaxPoints)
496 ++total_origins; 501 ++total_origins;
497 502
498 return total_origins; 503 return total_origins;
499 } 504 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698