Index: chrome/browser/engagement/site_engagement_service.h |
diff --git a/chrome/browser/engagement/site_engagement_service.h b/chrome/browser/engagement/site_engagement_service.h |
index e18e9808a9fbda9d7871e3a90cb7d759a50293f1..a98dd6c46a02cbecb64f4b68742238477822f6db 100644 |
--- a/chrome/browser/engagement/site_engagement_service.h |
+++ b/chrome/browser/engagement/site_engagement_service.h |
@@ -126,6 +126,8 @@ class SiteEngagementService : public KeyedService, |
FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, IsBootstrapped); |
FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, EngagementLevel); |
FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, ScoreDecayHistograms); |
+ FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, |
+ PersistLastEngagementTime); |
FRIEND_TEST_ALL_PREFIXES(AppBannerSettingsHelperTest, SiteEngagementTrigger); |
// Only used in tests. |
@@ -139,10 +141,21 @@ class SiteEngagementService : public KeyedService, |
SiteEngagementScore CreateEngagementScore(const GURL& origin); |
const SiteEngagementScore CreateEngagementScore(const GURL& origin) const; |
- // Post startup tasks: cleaning up origins which have decayed to 0, and |
- // logging UMA statistics. |
+ // Runs site engagement maintenance tasks. |
void AfterStartupTask(); |
- void CleanupEngagementScores(); |
+ |
+ // Removes any origins which have decayed to 0 engagement. If |
+ // |update_last_engagement_time| is true, the last engagement time of all |
+ // origins is reset by calculating the delta between the last engagement event |
+ // recorded by the site engagement service and the origin. The origin's last |
+ // engagement time is then set to clock_->Now() - delta. |
+ // |
+ // If a user does not use the browser at all for some period of time, |
+ // engagement is not decayed, and the state is restored equivalent to how they |
+ // left it once they return. |
+ void CleanupEngagementScores(bool update_last_engagement_time); |
+ |
+ // Records UMA metrics. |
void RecordMetrics(); |
// Returns the median engagement score of all recorded origins. |
@@ -163,6 +176,12 @@ class SiteEngagementService : public KeyedService, |
void HandleUserInput(content::WebContents* web_contents, |
SiteEngagementMetrics::EngagementType type); |
+ // Returns true if the last engagement increasing event seen by the site |
+ // engagement service was sufficiently long ago that we need to reset all |
+ // scores to be relative to now. This ensures that users who do not use Chrome |
+ // at all for an extended period of time do not have their engagement decay. |
+ bool IsLastEngagementObsolete(); |
+ |
// Overridden from history::HistoryServiceObserver: |
void OnURLsDeleted(history::HistoryService* history_service, |
bool all_history, |
@@ -195,6 +214,11 @@ class SiteEngagementService : public KeyedService, |
// upload. |
base::Time last_metrics_time_; |
+ // Keep track of the last time any engagement was recorded. If this date is |
+ // too far in the past, assume that the user has not been using Chrome, and |
+ // ensure that scores are not decayed as usual. |
+ base::Time last_engagement_time_; |
+ |
base::WeakPtrFactory<SiteEngagementService> weak_factory_; |
DISALLOW_COPY_AND_ASSIGN(SiteEngagementService); |