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/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
13 #include "base/time/clock.h" | 14 #include "base/time/clock.h" |
14 #include "base/time/default_clock.h" | 15 #include "base/time/default_clock.h" |
15 #include "base/values.h" | 16 #include "base/values.h" |
16 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 17 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
17 #include "chrome/browser/engagement/site_engagement_helper.h" | 18 #include "chrome/browser/engagement/site_engagement_helper.h" |
18 #include "chrome/browser/engagement/site_engagement_service_factory.h" | 19 #include "chrome/browser/engagement/site_engagement_service_factory.h" |
19 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
20 #include "components/content_settings/core/browser/host_content_settings_map.h" | 21 #include "components/content_settings/core/browser/host_content_settings_map.h" |
21 #include "components/content_settings/core/common/content_settings_pattern.h" | 22 #include "components/content_settings/core/common/content_settings_pattern.h" |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 return std::max(0.0, decayed_score); | 248 return std::max(0.0, decayed_score); |
248 } | 249 } |
249 | 250 |
250 // static | 251 // static |
251 SiteEngagementService* SiteEngagementService::Get(Profile* profile) { | 252 SiteEngagementService* SiteEngagementService::Get(Profile* profile) { |
252 return SiteEngagementServiceFactory::GetForProfile(profile); | 253 return SiteEngagementServiceFactory::GetForProfile(profile); |
253 } | 254 } |
254 | 255 |
255 // static | 256 // static |
256 bool SiteEngagementService::IsEnabled() { | 257 bool SiteEngagementService::IsEnabled() { |
257 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 258 const std::string group_name = |
258 switches::kEnableSiteEngagementService); | 259 base::FieldTrialList::FindFullName(kEngagementParams); |
| 260 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 261 switches::kEnableSiteEngagementService)) { |
| 262 return true; |
| 263 } |
| 264 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 265 switches::kDisableSiteEngagementService)) { |
| 266 return false; |
| 267 } |
| 268 return base::StartsWith(group_name, "Enabled", base::CompareCase::SENSITIVE); |
259 } | 269 } |
260 | 270 |
261 // static | 271 // static |
262 void SiteEngagementService::ClearHistoryForURLs(Profile* profile, | 272 void SiteEngagementService::ClearHistoryForURLs(Profile* profile, |
263 const std::set<GURL>& origins) { | 273 const std::set<GURL>& origins) { |
264 HostContentSettingsMap* settings_map = | 274 HostContentSettingsMap* settings_map = |
265 HostContentSettingsMapFactory::GetForProfile(profile); | 275 HostContentSettingsMapFactory::GetForProfile(profile); |
266 | 276 |
267 for (const GURL& origin_url : origins) { | 277 for (const GURL& origin_url : origins) { |
268 ContentSettingsPattern pattern( | 278 ContentSettingsPattern pattern( |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 int SiteEngagementService::OriginsWithMaxEngagement( | 495 int SiteEngagementService::OriginsWithMaxEngagement( |
486 std::map<GURL, double>& score_map) { | 496 std::map<GURL, double>& score_map) { |
487 int total_origins = 0; | 497 int total_origins = 0; |
488 | 498 |
489 for (const auto& value : score_map) | 499 for (const auto& value : score_map) |
490 if (value.second == SiteEngagementScore::kMaxPoints) | 500 if (value.second == SiteEngagementScore::kMaxPoints) |
491 ++total_origins; | 501 ++total_origins; |
492 | 502 |
493 return total_origins; | 503 return total_origins; |
494 } | 504 } |
OLD | NEW |