OLD | NEW |
---|---|
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 Loading... | |
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 const std::string group_name = |
raymes
2015/10/27 01:57:05
nit: move this line down to where it is used?
calamity
2015/10/28 04:38:54
Done.
| |
254 base::FieldTrialList::FindFullName(kEngagementParams); | 255 base::FieldTrialList::FindFullName(kEngagementParams); |
255 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 256 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
256 switches::kEnableSiteEngagementService)) { | 257 switches::kEnableSiteEngagementService)) { |
257 return true; | 258 return true; |
258 } | 259 } |
259 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 260 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
260 switches::kDisableSiteEngagementService)) { | 261 switches::kDisableSiteEngagementService)) { |
261 return false; | 262 return false; |
262 } | 263 } |
263 return base::StartsWith(group_name, "Enabled", base::CompareCase::SENSITIVE); | 264 return base::StartsWith(group_name, "Enabled", |
265 base::CompareCase::SENSITIVE) || | |
266 SiteEngagementEvictionPolicy::IsEnabled(); | |
264 } | 267 } |
265 | 268 |
266 // static | 269 // static |
267 void SiteEngagementService::ClearHistoryForURLs(Profile* profile, | 270 void SiteEngagementService::ClearHistoryForURLs(Profile* profile, |
268 const std::set<GURL>& origins) { | 271 const std::set<GURL>& origins) { |
269 HostContentSettingsMap* settings_map = | 272 HostContentSettingsMap* settings_map = |
270 HostContentSettingsMapFactory::GetForProfile(profile); | 273 HostContentSettingsMapFactory::GetForProfile(profile); |
271 | 274 |
272 for (const GURL& origin_url : origins) { | 275 for (const GURL& origin_url : origins) { |
273 ContentSettingsPattern pattern( | 276 ContentSettingsPattern pattern( |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
490 int SiteEngagementService::OriginsWithMaxEngagement( | 493 int SiteEngagementService::OriginsWithMaxEngagement( |
491 std::map<GURL, double>& score_map) { | 494 std::map<GURL, double>& score_map) { |
492 int total_origins = 0; | 495 int total_origins = 0; |
493 | 496 |
494 for (const auto& value : score_map) | 497 for (const auto& value : score_map) |
495 if (value.second == SiteEngagementScore::kMaxPoints) | 498 if (value.second == SiteEngagementScore::kMaxPoints) |
496 ++total_origins; | 499 ++total_origins; |
497 | 500 |
498 return total_origins; | 501 return total_origins; |
499 } | 502 } |
OLD | NEW |