Chromium Code Reviews| 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 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/time/clock.h" | 11 #include "base/time/clock.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | |
| 13 #include "chrome/browser/engagement/site_engagement_helper.h" | 14 #include "chrome/browser/engagement/site_engagement_helper.h" |
| 14 #include "chrome/browser/engagement/site_engagement_service_factory.h" | 15 #include "chrome/browser/engagement/site_engagement_service_factory.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
|
benwells
2015/09/14 03:50:05
Nit: I think you should be able to remove this inc
| |
| 16 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
| 17 #include "components/content_settings/core/browser/host_content_settings_map.h" | 18 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 18 #include "components/content_settings/core/common/content_settings_pattern.h" | 19 #include "components/content_settings/core/common/content_settings_pattern.h" |
| 19 #include "url/gurl.h" | 20 #include "url/gurl.h" |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 // Delta within which to consider scores equal. | 24 // Delta within which to consider scores equal. |
| 24 const double kScoreDelta = 0.001; | 25 const double kScoreDelta = 0.001; |
| 25 | 26 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 } | 162 } |
| 162 | 163 |
| 163 SiteEngagementService::SiteEngagementService(Profile* profile) | 164 SiteEngagementService::SiteEngagementService(Profile* profile) |
| 164 : profile_(profile) { | 165 : profile_(profile) { |
| 165 } | 166 } |
| 166 | 167 |
| 167 SiteEngagementService::~SiteEngagementService() { | 168 SiteEngagementService::~SiteEngagementService() { |
| 168 } | 169 } |
| 169 | 170 |
| 170 void SiteEngagementService::HandleNavigation(const GURL& url) { | 171 void SiteEngagementService::HandleNavigation(const GURL& url) { |
| 171 HostContentSettingsMap* settings_map = profile_->GetHostContentSettingsMap(); | 172 HostContentSettingsMap* settings_map = |
| 173 HostContentSettingsMapFactory::GetForProfile(profile_); | |
| 172 scoped_ptr<base::DictionaryValue> score_dict = | 174 scoped_ptr<base::DictionaryValue> score_dict = |
| 173 GetScoreDictForOrigin(settings_map, url); | 175 GetScoreDictForOrigin(settings_map, url); |
| 174 SiteEngagementScore score(&clock_, *score_dict); | 176 SiteEngagementScore score(&clock_, *score_dict); |
| 175 | 177 |
| 176 score.AddPoints(SiteEngagementScore::kNavigationPoints); | 178 score.AddPoints(SiteEngagementScore::kNavigationPoints); |
| 177 if (score.UpdateScoreDict(score_dict.get())) { | 179 if (score.UpdateScoreDict(score_dict.get())) { |
| 178 ContentSettingsPattern pattern( | 180 ContentSettingsPattern pattern( |
| 179 ContentSettingsPattern::FromURLNoWildcard(url)); | 181 ContentSettingsPattern::FromURLNoWildcard(url)); |
| 180 if (!pattern.IsValid()) | 182 if (!pattern.IsValid()) |
| 181 return; | 183 return; |
| 182 | 184 |
| 183 settings_map->SetWebsiteSetting(pattern, ContentSettingsPattern::Wildcard(), | 185 settings_map->SetWebsiteSetting(pattern, ContentSettingsPattern::Wildcard(), |
| 184 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, | 186 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, |
| 185 std::string(), score_dict.release()); | 187 std::string(), score_dict.release()); |
| 186 } | 188 } |
| 187 } | 189 } |
| 188 | 190 |
| 189 int SiteEngagementService::GetScore(const GURL& url) { | 191 int SiteEngagementService::GetScore(const GURL& url) { |
| 190 HostContentSettingsMap* settings_map = profile_->GetHostContentSettingsMap(); | 192 HostContentSettingsMap* settings_map = |
| 193 HostContentSettingsMapFactory::GetForProfile(profile_); | |
| 191 scoped_ptr<base::DictionaryValue> score_dict = | 194 scoped_ptr<base::DictionaryValue> score_dict = |
| 192 GetScoreDictForOrigin(settings_map, url); | 195 GetScoreDictForOrigin(settings_map, url); |
| 193 SiteEngagementScore score(&clock_, *score_dict); | 196 SiteEngagementScore score(&clock_, *score_dict); |
| 194 | 197 |
| 195 return score.Score(); | 198 return score.Score(); |
| 196 } | 199 } |
| 197 | 200 |
| 198 int SiteEngagementService::GetTotalEngagementPoints() { | 201 int SiteEngagementService::GetTotalEngagementPoints() { |
| 199 HostContentSettingsMap* settings_map = profile_->GetHostContentSettingsMap(); | 202 HostContentSettingsMap* settings_map = |
| 203 HostContentSettingsMapFactory::GetForProfile(profile_); | |
| 200 ContentSettingsForOneType engagement_settings; | 204 ContentSettingsForOneType engagement_settings; |
| 201 settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, | 205 settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, |
| 202 std::string(), &engagement_settings); | 206 std::string(), &engagement_settings); |
| 203 int total_score = 0; | 207 int total_score = 0; |
| 204 for (const auto& site : engagement_settings) { | 208 for (const auto& site : engagement_settings) { |
| 205 GURL origin(site.primary_pattern.ToString()); | 209 GURL origin(site.primary_pattern.ToString()); |
| 206 if (!origin.is_valid()) | 210 if (!origin.is_valid()) |
| 207 continue; | 211 continue; |
| 208 | 212 |
| 209 scoped_ptr<base::DictionaryValue> score_dict = | 213 scoped_ptr<base::DictionaryValue> score_dict = |
| 210 GetScoreDictForOrigin(settings_map, origin); | 214 GetScoreDictForOrigin(settings_map, origin); |
| 211 SiteEngagementScore score(&clock_, *score_dict); | 215 SiteEngagementScore score(&clock_, *score_dict); |
| 212 total_score += score.Score(); | 216 total_score += score.Score(); |
| 213 } | 217 } |
| 214 return total_score; | 218 return total_score; |
| 215 } | 219 } |
| OLD | NEW |