Chromium Code Reviews| Index: chrome/browser/engagement/site_engagement_service.cc |
| diff --git a/chrome/browser/engagement/site_engagement_service.cc b/chrome/browser/engagement/site_engagement_service.cc |
| index b336708446b92eed4f5abd471451282c781efd75..a16ccc586b9ea5ac435e7dfc66d57d7b7381ef4a 100644 |
| --- a/chrome/browser/engagement/site_engagement_service.cc |
| +++ b/chrome/browser/engagement/site_engagement_service.cc |
| @@ -267,12 +267,18 @@ void SiteEngagementScore::AddPoints(double points) { |
| last_engagement_time_ = now; |
| } |
| -void SiteEngagementScore::Reset(double points) { |
| +void SiteEngagementScore::Reset(double points, const base::Time* updated_time) { |
| raw_score_ = points; |
| points_added_today_ = 0; |
| // This must be set in order to prevent the score from decaying when read. |
| - last_engagement_time_ = clock_->Now(); |
| + if (updated_time == nullptr) { |
|
benwells
2016/04/18 07:01:42
Nit: Can you rearrange to be
if (updated_time) {
dominickn
2016/04/18 23:27:52
Done.
|
| + last_engagement_time_ = clock_->Now(); |
| + } else { |
| + last_engagement_time_ = *updated_time; |
| + if (!last_shortcut_launch_time_.is_null()) |
| + last_shortcut_launch_time_ = *updated_time; |
| + } |
| } |
| bool SiteEngagementScore::MaxPointsPerDayAdded() const { |
| @@ -445,29 +451,7 @@ void SiteEngagementService::HandleMediaPlaying(const GURL& url, |
| } |
| void SiteEngagementService::ResetScoreForURL(const GURL& url, double score) { |
|
benwells
2016/04/18 07:01:42
Is this still used?
dominickn
2016/04/18 23:27:52
Yes, in the WebUI code for changing engagement sco
|
| - DCHECK(url.is_valid()); |
| - DCHECK_GE(score, 0); |
| - DCHECK_LE(score, SiteEngagementScore::kMaxPoints); |
| - |
| - HostContentSettingsMap* settings_map = |
| - HostContentSettingsMapFactory::GetForProfile(profile_); |
| - scoped_ptr<base::DictionaryValue> score_dict = |
| - GetScoreDictForOrigin(settings_map, url); |
| - SiteEngagementScore engagement_score(clock_.get(), *score_dict); |
| - |
| - engagement_score.Reset(score); |
| - if (score == 0) { |
| - settings_map->SetWebsiteSettingDefaultScope( |
| - url, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), |
| - nullptr); |
| - return; |
| - } |
| - |
| - if (engagement_score.UpdateScoreDict(score_dict.get())) { |
| - settings_map->SetWebsiteSettingDefaultScope( |
| - url, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), |
| - score_dict.release()); |
| - } |
| + ResetScoreAndAccessTimesForURL(url, score, nullptr); |
| } |
| void SiteEngagementService::OnURLsDeleted( |
| @@ -485,7 +469,7 @@ void SiteEngagementService::OnURLsDeleted( |
| hs->GetCountsForOrigins( |
| std::set<GURL>(origins.begin(), origins.end()), |
| base::Bind(&SiteEngagementService::GetCountsForOriginsComplete, |
| - weak_factory_.GetWeakPtr(), origins, expired)); |
| + weak_factory_.GetWeakPtr(), hs, origins, expired)); |
| } |
| void SiteEngagementService::SetLastShortcutLaunchTime(const GURL& url) { |
| @@ -744,6 +728,7 @@ int SiteEngagementService::OriginsWithMaxEngagement( |
| } |
| void SiteEngagementService::GetCountsForOriginsComplete( |
| + history::HistoryService* history_service, |
| const std::multiset<GURL>& deleted_origins, |
| bool expired, |
| const history::OriginCountMap& remaining_origins) { |
| @@ -757,10 +742,47 @@ void SiteEngagementService::GetCountsForOriginsComplete( |
| if ((expired && remaining != 0) || deleted == 0) |
| continue; |
| + // Retrieve the last visit time for this origin, and use this for the last |
| + // engagement time and last shortcut launch time (if that is non-null). |
| + // TODO(calamity): ensure that we have sufficient data to lookup the last |
| + // visit to any URL under the origin, rather than just the origin. |
| + base::Time updated_time; |
| + if (!history_service->GetLastVisitTimeForURL(origin, &updated_time)) |
| + updated_time = clock_->Now(); |
|
benwells
2016/04/18 07:01:42
IIUC this will be fairly common:
- usually people
dominickn
2016/04/18 23:27:52
Yes, I agree with you here.
As it turns out, His
benwells
2016/04/19 00:18:53
Ack.
Can you also move this code to below where p
dominickn
2016/04/19 07:01:58
Done.
|
| + |
| // Remove engagement proportional to the urls expired from the origin's |
| // entire history. |
| double proportion_remaining = |
| static_cast<double>(remaining) / (remaining + deleted); |
| - ResetScoreForURL(origin, proportion_remaining * GetScore(origin)); |
| + ResetScoreAndAccessTimesForURL(origin, |
| + proportion_remaining * GetScore(origin), |
| + &updated_time); |
| + } |
| +} |
| + |
| +void SiteEngagementService::ResetScoreAndAccessTimesForURL( |
| + const GURL& url, double score, const base::Time* updated_time) { |
|
benwells
2016/04/18 07:01:42
Should this score by undecayed? That is, what happ
dominickn
2016/04/18 23:27:52
Having thought about this more, it seems counter-i
benwells
2016/04/19 00:18:53
Undecaying should not lead to any increase in enga
dominickn
2016/04/19 07:01:57
I finally understand what's going on here. Done, w
|
| + DCHECK(url.is_valid()); |
| + DCHECK_GE(score, 0); |
| + DCHECK_LE(score, SiteEngagementScore::kMaxPoints); |
| + |
| + HostContentSettingsMap* settings_map = |
| + HostContentSettingsMapFactory::GetForProfile(profile_); |
| + scoped_ptr<base::DictionaryValue> score_dict = |
| + GetScoreDictForOrigin(settings_map, url); |
| + SiteEngagementScore engagement_score(clock_.get(), *score_dict); |
| + |
| + engagement_score.Reset(score, updated_time); |
| + if (score == 0) { |
| + settings_map->SetWebsiteSettingDefaultScope( |
| + url, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), |
| + nullptr); |
| + return; |
| + } |
| + |
| + if (engagement_score.UpdateScoreDict(score_dict.get())) { |
| + settings_map->SetWebsiteSettingDefaultScope( |
| + url, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), |
| + score_dict.release()); |
| } |
| } |