| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_score.h" | 5 #include "chrome/browser/engagement/site_engagement_score.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 void SiteEngagementScore::Commit() { | 240 void SiteEngagementScore::Commit() { |
| 241 DCHECK(settings_map_); | 241 DCHECK(settings_map_); |
| 242 if (!UpdateScoreDict(score_dict_.get())) | 242 if (!UpdateScoreDict(score_dict_.get())) |
| 243 return; | 243 return; |
| 244 | 244 |
| 245 settings_map_->SetWebsiteSettingDefaultScope( | 245 settings_map_->SetWebsiteSettingDefaultScope( |
| 246 origin_, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), | 246 origin_, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), |
| 247 std::move(score_dict_)); | 247 std::move(score_dict_)); |
| 248 } | 248 } |
| 249 | 249 |
| 250 blink::mojom::EngagementLevel SiteEngagementScore::GetEngagementLevel() const { |
| 251 DCHECK_LT(GetMediumEngagementBoundary(), GetHighEngagementBoundary()); |
| 252 |
| 253 double score = GetScore(); |
| 254 if (score == 0) |
| 255 return blink::mojom::EngagementLevel::NONE; |
| 256 |
| 257 if (score < 1) |
| 258 return blink::mojom::EngagementLevel::MINIMAL; |
| 259 |
| 260 if (score < GetMediumEngagementBoundary()) |
| 261 return blink::mojom::EngagementLevel::LOW; |
| 262 |
| 263 if (score < GetHighEngagementBoundary()) |
| 264 return blink::mojom::EngagementLevel::MEDIUM; |
| 265 |
| 266 if (score < SiteEngagementScore::kMaxPoints) |
| 267 return blink::mojom::EngagementLevel::HIGH; |
| 268 |
| 269 return blink::mojom::EngagementLevel::MAX; |
| 270 } |
| 271 |
| 250 bool SiteEngagementScore::MaxPointsPerDayAdded() const { | 272 bool SiteEngagementScore::MaxPointsPerDayAdded() const { |
| 251 if (!last_engagement_time_.is_null() && | 273 if (!last_engagement_time_.is_null() && |
| 252 clock_->Now().LocalMidnight() != last_engagement_time_.LocalMidnight()) { | 274 clock_->Now().LocalMidnight() != last_engagement_time_.LocalMidnight()) { |
| 253 return false; | 275 return false; |
| 254 } | 276 } |
| 255 | 277 |
| 256 return points_added_today_ == GetMaxPointsPerDay(); | 278 return points_added_today_ == GetMaxPointsPerDay(); |
| 257 } | 279 } |
| 258 | 280 |
| 259 void SiteEngagementScore::Reset(double points, | 281 void SiteEngagementScore::Reset(double points, |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 GetParamValues()[HIGH_ENGAGEMENT_BOUNDARY].second = 50; | 385 GetParamValues()[HIGH_ENGAGEMENT_BOUNDARY].second = 50; |
| 364 GetParamValues()[MAX_DECAYS_PER_SCORE].second = 1; | 386 GetParamValues()[MAX_DECAYS_PER_SCORE].second = 1; |
| 365 GetParamValues()[LAST_ENGAGEMENT_GRACE_PERIOD_IN_HOURS].second = 72; | 387 GetParamValues()[LAST_ENGAGEMENT_GRACE_PERIOD_IN_HOURS].second = 72; |
| 366 | 388 |
| 367 // This is set to values that avoid interference with tests and are set when | 389 // This is set to values that avoid interference with tests and are set when |
| 368 // testing these features. | 390 // testing these features. |
| 369 GetParamValues()[FIRST_DAILY_ENGAGEMENT].second = 0; | 391 GetParamValues()[FIRST_DAILY_ENGAGEMENT].second = 0; |
| 370 GetParamValues()[DECAY_PROPORTION].second = 1; | 392 GetParamValues()[DECAY_PROPORTION].second = 1; |
| 371 GetParamValues()[SCORE_CLEANUP_THRESHOLD].second = 0; | 393 GetParamValues()[SCORE_CLEANUP_THRESHOLD].second = 0; |
| 372 } | 394 } |
| OLD | NEW |