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" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 } | 51 } |
52 | 52 |
53 } // namespace | 53 } // namespace |
54 | 54 |
55 const char* SiteEngagementScore::kRawScoreKey = "rawScore"; | 55 const char* SiteEngagementScore::kRawScoreKey = "rawScore"; |
56 const char* SiteEngagementScore::kPointsAddedTodayKey = "pointsAddedToday"; | 56 const char* SiteEngagementScore::kPointsAddedTodayKey = "pointsAddedToday"; |
57 const char* SiteEngagementScore::kLastEngagementTimeKey = "lastEngagementTime"; | 57 const char* SiteEngagementScore::kLastEngagementTimeKey = "lastEngagementTime"; |
58 | 58 |
59 const double SiteEngagementScore::kMaxPoints = 100; | 59 const double SiteEngagementScore::kMaxPoints = 100; |
60 const double SiteEngagementScore::kMaxPointsPerDay = 5; | 60 const double SiteEngagementScore::kMaxPointsPerDay = 5; |
61 const double SiteEngagementScore::kNavigationPoints = 1; | 61 const double SiteEngagementScore::kUserInputPoints = 1; |
62 const int SiteEngagementScore::kDecayPeriodInDays = 7; | 62 const int SiteEngagementScore::kDecayPeriodInDays = 7; |
63 const double SiteEngagementScore::kDecayPoints = 5; | 63 const double SiteEngagementScore::kDecayPoints = 5; |
64 | 64 |
65 SiteEngagementScore::SiteEngagementScore( | 65 SiteEngagementScore::SiteEngagementScore( |
66 base::Clock* clock, | 66 base::Clock* clock, |
67 const base::DictionaryValue& score_dict) | 67 const base::DictionaryValue& score_dict) |
68 : SiteEngagementScore(clock) { | 68 : SiteEngagementScore(clock) { |
69 score_dict.GetDouble(kRawScoreKey, &raw_score_); | 69 score_dict.GetDouble(kRawScoreKey, &raw_score_); |
70 score_dict.GetDouble(kPointsAddedTodayKey, &points_added_today_); | 70 score_dict.GetDouble(kPointsAddedTodayKey, &points_added_today_); |
71 double internal_time; | 71 double internal_time; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 switches::kEnableSiteEngagementService); | 160 switches::kEnableSiteEngagementService); |
161 } | 161 } |
162 | 162 |
163 SiteEngagementService::SiteEngagementService(Profile* profile) | 163 SiteEngagementService::SiteEngagementService(Profile* profile) |
164 : profile_(profile) { | 164 : profile_(profile) { |
165 } | 165 } |
166 | 166 |
167 SiteEngagementService::~SiteEngagementService() { | 167 SiteEngagementService::~SiteEngagementService() { |
168 } | 168 } |
169 | 169 |
170 void SiteEngagementService::HandleNavigation(const GURL& url) { | 170 void SiteEngagementService::HandleUserInput(const GURL& url) { |
171 HostContentSettingsMap* settings_map = profile_->GetHostContentSettingsMap(); | 171 HostContentSettingsMap* settings_map = profile_->GetHostContentSettingsMap(); |
172 scoped_ptr<base::DictionaryValue> score_dict = | 172 scoped_ptr<base::DictionaryValue> score_dict = |
173 GetScoreDictForOrigin(settings_map, url); | 173 GetScoreDictForOrigin(settings_map, url); |
174 SiteEngagementScore score(&clock_, *score_dict); | 174 SiteEngagementScore score(&clock_, *score_dict); |
175 | 175 |
176 score.AddPoints(SiteEngagementScore::kNavigationPoints); | 176 score.AddPoints(SiteEngagementScore::kUserInputPoints); |
177 if (score.UpdateScoreDict(score_dict.get())) { | 177 if (score.UpdateScoreDict(score_dict.get())) { |
178 ContentSettingsPattern pattern( | 178 ContentSettingsPattern pattern( |
179 ContentSettingsPattern::FromURLNoWildcard(url)); | 179 ContentSettingsPattern::FromURLNoWildcard(url)); |
180 if (!pattern.IsValid()) | 180 if (!pattern.IsValid()) |
181 return; | 181 return; |
182 | 182 |
183 settings_map->SetWebsiteSetting(pattern, ContentSettingsPattern::Wildcard(), | 183 settings_map->SetWebsiteSetting(pattern, ContentSettingsPattern::Wildcard(), |
184 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, | 184 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, |
185 std::string(), score_dict.release()); | 185 std::string(), score_dict.release()); |
186 } | 186 } |
(...skipping 19 matching lines...) Expand all Loading... |
206 if (!origin.is_valid()) | 206 if (!origin.is_valid()) |
207 continue; | 207 continue; |
208 | 208 |
209 scoped_ptr<base::DictionaryValue> score_dict = | 209 scoped_ptr<base::DictionaryValue> score_dict = |
210 GetScoreDictForOrigin(settings_map, origin); | 210 GetScoreDictForOrigin(settings_map, origin); |
211 SiteEngagementScore score(&clock_, *score_dict); | 211 SiteEngagementScore score(&clock_, *score_dict); |
212 total_score += score.Score(); | 212 total_score += score.Score(); |
213 } | 213 } |
214 return total_score; | 214 return total_score; |
215 } | 215 } |
OLD | NEW |