Commit 090145cb authored by calamity's avatar calamity Committed by Commit bot

Small cleanup of SiteEngagementService.

This CL moves pref management into SiteEngagementScore so that
SiteEngagementService has a cleaner flow for operating on
SiteEngagementScores.

BUG=604305

Review-Url: https://codereview.chromium.org/1919383005
Cr-Commit-Position: refs/heads/master@{#396789}
parent 47bfa8f7
......@@ -6,11 +6,13 @@
#include <cmath>
#include "base/memory/ptr_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/time/clock.h"
#include "base/time/time.h"
#include "base/values.h"
#include "chrome/browser/engagement/site_engagement_metrics.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/variations/variations_associated_data.h"
namespace {
......@@ -47,6 +49,24 @@ bool DoublesConsideredDifferent(double value1, double value2, double delta) {
return abs_difference > delta;
}
std::unique_ptr<base::DictionaryValue> GetScoreDictForOrigin(
HostContentSettingsMap* settings,
const GURL& origin_url) {
if (!settings)
return std::unique_ptr<base::DictionaryValue>();
std::unique_ptr<base::Value> value = settings->GetWebsiteSetting(
origin_url, origin_url, CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT,
std::string(), NULL);
if (!value.get())
return base::WrapUnique(new base::DictionaryValue());
if (!value->IsType(base::Value::TYPE_DICTIONARY))
return base::WrapUnique(new base::DictionaryValue());
return base::WrapUnique(static_cast<base::DictionaryValue*>(value.release()));
}
} // namespace
const double SiteEngagementScore::kMaxPoints = 100;
......@@ -143,20 +163,20 @@ void SiteEngagementScore::UpdateFromVariations(const char* param_name) {
}
SiteEngagementScore::SiteEngagementScore(base::Clock* clock,
const base::DictionaryValue& score_dict)
: SiteEngagementScore(clock) {
score_dict.GetDouble(kRawScoreKey, &raw_score_);
score_dict.GetDouble(kPointsAddedTodayKey, &points_added_today_);
double internal_time;
if (score_dict.GetDouble(kLastEngagementTimeKey, &internal_time))
last_engagement_time_ = base::Time::FromInternalValue(internal_time);
if (score_dict.GetDouble(kLastShortcutLaunchTimeKey, &internal_time))
last_shortcut_launch_time_ = base::Time::FromInternalValue(internal_time);
const GURL& origin,
HostContentSettingsMap* settings_map)
: SiteEngagementScore(clock, GetScoreDictForOrigin(settings_map, origin)) {
origin_ = origin;
settings_map_ = settings_map;
}
SiteEngagementScore::SiteEngagementScore(SiteEngagementScore&& other) = default;
SiteEngagementScore::~SiteEngagementScore() {}
SiteEngagementScore& SiteEngagementScore::operator=(
SiteEngagementScore&& other) = default;
void SiteEngagementScore::AddPoints(double points) {
DCHECK_NE(0, points);
double decayed_score = DecayedScore();
......@@ -198,6 +218,15 @@ double SiteEngagementScore::GetScore() const {
return std::min(DecayedScore() + BonusScore(), kMaxPoints);
}
void SiteEngagementScore::Commit() {
if (!UpdateScoreDict(score_dict_.get()))
return;
settings_map_->SetWebsiteSettingDefaultScope(
origin_, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(),
score_dict_.release());
}
bool SiteEngagementScore::MaxPointsPerDayAdded() const {
if (!last_engagement_time_.is_null() &&
clock_->Now().LocalMidnight() != last_engagement_time_.LocalMidnight()) {
......@@ -207,18 +236,13 @@ bool SiteEngagementScore::MaxPointsPerDayAdded() const {
return points_added_today_ == GetMaxPointsPerDay();
}
void SiteEngagementScore::Reset(double points, const base::Time* updated_time) {
void SiteEngagementScore::Reset(double points,
const base::Time last_engagement_time) {
raw_score_ = points;
points_added_today_ = 0;
// This must be set in order to prevent the score from decaying when read.
if (updated_time) {
last_engagement_time_ = *updated_time;
if (!last_shortcut_launch_time_.is_null())
last_shortcut_launch_time_ = *updated_time;
} else {
last_engagement_time_ = clock_->Now();
}
last_engagement_time_ = last_engagement_time;
}
bool SiteEngagementScore::UpdateScoreDict(base::DictionaryValue* score_dict) {
......@@ -257,12 +281,27 @@ bool SiteEngagementScore::UpdateScoreDict(base::DictionaryValue* score_dict) {
return true;
}
SiteEngagementScore::SiteEngagementScore(base::Clock* clock)
SiteEngagementScore::SiteEngagementScore(
base::Clock* clock,
std::unique_ptr<base::DictionaryValue> score_dict)
: clock_(clock),
raw_score_(0),
points_added_today_(0),
last_engagement_time_(),
last_shortcut_launch_time_() {}
last_shortcut_launch_time_(),
score_dict_(score_dict.release()) {
if (!score_dict_)
return;
score_dict_->GetDouble(kRawScoreKey, &raw_score_);
score_dict_->GetDouble(kPointsAddedTodayKey, &points_added_today_);
double internal_time;
if (score_dict_->GetDouble(kLastEngagementTimeKey, &internal_time))
last_engagement_time_ = base::Time::FromInternalValue(internal_time);
if (score_dict_->GetDouble(kLastShortcutLaunchTimeKey, &internal_time))
last_shortcut_launch_time_ = base::Time::FromInternalValue(internal_time);
}
double SiteEngagementScore::DecayedScore() const {
// Note that users can change their clock, so from this system's perspective
......
......@@ -5,15 +5,20 @@
#ifndef CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SCORE_H_
#define CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SCORE_H_
#include <memory>
#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "base/time/time.h"
#include "base/values.h"
#include "url/gurl.h"
namespace base {
class Clock;
}
class HostContentSettingsMap;
class SiteEngagementScore {
public:
// The parameters which can be varied via field trial. All "points" values
......@@ -84,15 +89,22 @@ class SiteEngagementScore {
// responsibility of the caller to make sure |clock| outlives this
// SiteEngagementScore.
SiteEngagementScore(base::Clock* clock,
const base::DictionaryValue& score_dict);
const GURL& origin,
HostContentSettingsMap* settings_map);
SiteEngagementScore(SiteEngagementScore&& other);
~SiteEngagementScore();
SiteEngagementScore& operator=(SiteEngagementScore&& other);
// Adds |points| to this score, respecting daily limits and the maximum
// possible score. Decays the score if it has not been updated recently
// enough.
void AddPoints(double points);
double GetScore() const;
// Writes the values in this score into |settings_map_|.
void Commit();
// Returns true if the maximum number of points today has been added.
bool MaxPointsPerDayAdded() const;
......@@ -101,15 +113,7 @@ class SiteEngagementScore {
// shortcut launch time (if it is non-null) to |updated_time|. Otherwise, last
// engagement time is set to the current time and last shortcut launch time is
// left unchanged.
// TODO(calamity): Ideally, all SiteEngagementScore methods should take a
// base::Time argument like this one does rather than each SiteEngagementScore
// hold a pointer to a base::Clock. Then SiteEngagementScore doesn't need to
// worry about clock vending. See crbug.com/604305.
void Reset(double points, const base::Time* updated_time);
// Updates the content settings dictionary |score_dict| with the current score
// fields. Returns true if |score_dict| changed, otherwise return false.
bool UpdateScoreDict(base::DictionaryValue* score_dict);
void Reset(double points, const base::Time updated_time);
// Get/set the last time this origin was launched from an installed shortcut.
base::Time last_shortcut_launch_time() const {
......@@ -139,7 +143,8 @@ class SiteEngagementScore {
static const char* kLastShortcutLaunchTimeKey;
// This version of the constructor is used in unit tests.
explicit SiteEngagementScore(base::Clock* clock);
SiteEngagementScore(base::Clock* clock,
std::unique_ptr<base::DictionaryValue> score_dict);
// Determine the score, accounting for any decay.
double DecayedScore() const;
......@@ -151,6 +156,10 @@ class SiteEngagementScore {
// newly added parameters receive a fixed value here.
static void SetParamValuesForTesting();
// Updates the content settings dictionary |score_dict| with the current score
// fields. Returns true if |score_dict| changed, otherwise return false.
bool UpdateScoreDict(base::DictionaryValue* score_dict);
// The clock used to vend times. Enables time travelling in tests. Owned by
// the SiteEngagementService.
base::Clock* clock_;
......@@ -171,6 +180,15 @@ class SiteEngagementScore {
// shortcut.
base::Time last_shortcut_launch_time_;
// The dictionary that represents this engagement score.
std::unique_ptr<base::DictionaryValue> score_dict_;
// The origin this score represents.
GURL origin_;
// The settings map to write this score to when Commit() is called.
HostContentSettingsMap* settings_map_;
DISALLOW_COPY_AND_ASSIGN(SiteEngagementScore);
};
......
......@@ -40,7 +40,7 @@ base::Time GetReferenceTime() {
class SiteEngagementScoreTest : public testing::Test {
public:
SiteEngagementScoreTest() : score_(&test_clock_) {}
SiteEngagementScoreTest() : score_(&test_clock_, nullptr) {}
void SetUp() override {
testing::Test::SetUp();
......@@ -68,25 +68,26 @@ class SiteEngagementScoreTest : public testing::Test {
}
void TestScoreInitializesAndUpdates(
base::DictionaryValue* score_dict,
std::unique_ptr<base::DictionaryValue> score_dict,
double expected_raw_score,
double expected_points_added_today,
base::Time expected_last_engagement_time) {
SiteEngagementScore initial_score(&test_clock_, *score_dict);
std::unique_ptr<base::DictionaryValue> copy(score_dict->DeepCopy());
SiteEngagementScore initial_score(&test_clock_, std::move(score_dict));
VerifyScore(initial_score, expected_raw_score, expected_points_added_today,
expected_last_engagement_time);
// Updating the score dict should return false, as the score shouldn't
// have changed at this point.
EXPECT_FALSE(initial_score.UpdateScoreDict(score_dict));
EXPECT_FALSE(initial_score.UpdateScoreDict(copy.get()));
// Update the score to new values and verify it updates the score dict
// correctly.
base::Time different_day =
GetReferenceTime() + base::TimeDelta::FromDays(1);
UpdateScore(&initial_score, 5, 10, different_day);
EXPECT_TRUE(initial_score.UpdateScoreDict(score_dict));
SiteEngagementScore updated_score(&test_clock_, *score_dict);
EXPECT_TRUE(initial_score.UpdateScoreDict(copy.get()));
SiteEngagementScore updated_score(&test_clock_, std::move(copy));
VerifyScore(updated_score, 5, 10, different_day);
}
......@@ -295,37 +296,39 @@ TEST_F(SiteEngagementScoreTest, GoBackInTime) {
// Test that scores are read / written correctly from / to empty score
// dictionaries.
TEST_F(SiteEngagementScoreTest, EmptyDictionary) {
base::DictionaryValue dict;
TestScoreInitializesAndUpdates(&dict, 0, 0, base::Time());
std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
TestScoreInitializesAndUpdates(std::move(dict), 0, 0, base::Time());
}
// Test that scores are read / written correctly from / to partially empty
// score dictionaries.
TEST_F(SiteEngagementScoreTest, PartiallyEmptyDictionary) {
base::DictionaryValue dict;
dict.SetDouble(SiteEngagementScore::kPointsAddedTodayKey, 2);
std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
dict->SetDouble(SiteEngagementScore::kPointsAddedTodayKey, 2);
TestScoreInitializesAndUpdates(&dict, 0, 2, base::Time());
TestScoreInitializesAndUpdates(std::move(dict), 0, 2, base::Time());
}
// Test that scores are read / written correctly from / to populated score
// dictionaries.
TEST_F(SiteEngagementScoreTest, PopulatedDictionary) {
base::DictionaryValue dict;
dict.SetDouble(SiteEngagementScore::kRawScoreKey, 1);
dict.SetDouble(SiteEngagementScore::kPointsAddedTodayKey, 2);
dict.SetDouble(SiteEngagementScore::kLastEngagementTimeKey,
GetReferenceTime().ToInternalValue());
std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
dict->SetDouble(SiteEngagementScore::kRawScoreKey, 1);
dict->SetDouble(SiteEngagementScore::kPointsAddedTodayKey, 2);
dict->SetDouble(SiteEngagementScore::kLastEngagementTimeKey,
GetReferenceTime().ToInternalValue());
TestScoreInitializesAndUpdates(&dict, 1, 2, GetReferenceTime());
TestScoreInitializesAndUpdates(std::move(dict), 1, 2, GetReferenceTime());
}
// Ensure bonus engagement is awarded for the first engagement of a day.
TEST_F(SiteEngagementScoreTest, FirstDailyEngagementBonus) {
SetFirstDailyEngagementPointsForTesting(0.5);
SiteEngagementScore score1(&test_clock_);
SiteEngagementScore score2(&test_clock_);
SiteEngagementScore score1(&test_clock_,
std::unique_ptr<base::DictionaryValue>());
SiteEngagementScore score2(&test_clock_,
std::unique_ptr<base::DictionaryValue>());
base::Time current_day = GetReferenceTime();
test_clock_.SetNow(current_day);
......@@ -371,7 +374,7 @@ TEST_F(SiteEngagementScoreTest, Reset) {
current_day += base::TimeDelta::FromDays(7);
test_clock_.SetNow(current_day);
score_.Reset(20.0, nullptr);
score_.Reset(20.0, current_day);
EXPECT_DOUBLE_EQ(20.0, score_.GetScore());
EXPECT_DOUBLE_EQ(0, score_.points_added_today_);
EXPECT_EQ(current_day, score_.last_engagement_time_);
......@@ -391,21 +394,23 @@ TEST_F(SiteEngagementScoreTest, Reset) {
score_.AddPoints(5);
test_clock_.SetNow(GetReferenceTime());
base::Time now = test_clock_.Now();
score_.Reset(10.0, &now);
score_.Reset(10.0, now);
EXPECT_DOUBLE_EQ(10.0, score_.GetScore());
EXPECT_DOUBLE_EQ(0, score_.points_added_today_);
EXPECT_EQ(now, score_.last_engagement_time_);
EXPECT_TRUE(score_.last_shortcut_launch_time_.is_null());
base::Time old_now = test_clock_.Now();
score_.set_last_shortcut_launch_time(test_clock_.Now());
test_clock_.SetNow(GetReferenceTime() + base::TimeDelta::FromDays(3));
now = test_clock_.Now();
score_.Reset(15.0, &now);
score_.Reset(15.0, now);
// 5 bonus from the last shortcut launch.
EXPECT_DOUBLE_EQ(20.0, score_.GetScore());
EXPECT_DOUBLE_EQ(0, score_.points_added_today_);
EXPECT_EQ(now, score_.last_engagement_time_);
EXPECT_EQ(now, score_.last_shortcut_launch_time_);
EXPECT_EQ(old_now, score_.last_shortcut_launch_time_);
}
......@@ -51,24 +51,6 @@ std::unique_ptr<ContentSettingsForOneType> GetEngagementContentSettings(
return engagement_settings;
}
std::unique_ptr<base::DictionaryValue> GetScoreDictForOrigin(
HostContentSettingsMap* settings,
const GURL& origin_url) {
if (!settings)
return std::unique_ptr<base::DictionaryValue>();
std::unique_ptr<base::Value> value = settings->GetWebsiteSetting(
origin_url, origin_url, CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT,
std::string(), NULL);
if (!value.get())
return base::WrapUnique(new base::DictionaryValue());
if (!value->IsType(base::Value::TYPE_DICTIONARY))
return base::WrapUnique(new base::DictionaryValue());
return base::WrapUnique(static_cast<base::DictionaryValue*>(value.release()));
}
// Only accept a navigation event for engagement if it is one of:
// a. direct typed navigation
// b. clicking on an omnibox suggestion brought up by typing a keyword
......@@ -173,16 +155,13 @@ std::map<GURL, double> SiteEngagementService::GetScoreMap() const {
if (!origin.is_valid())
continue;
std::unique_ptr<base::DictionaryValue> score_dict =
GetScoreDictForOrigin(settings_map, origin);
SiteEngagementScore score(clock_.get(), *score_dict);
score_map[origin] = score.GetScore();
score_map[origin] = GetScore(origin);
}
return score_map;
}
bool SiteEngagementService::IsBootstrapped() {
bool SiteEngagementService::IsBootstrapped() const {
return GetTotalEngagementPoints() >=
SiteEngagementScore::GetBootstrapPoints();
}
......@@ -210,15 +189,13 @@ bool SiteEngagementService::IsEngagementAtLeast(
}
void SiteEngagementService::ResetScoreForURL(const GURL& url, double score) {
ResetScoreAndAccessTimesForURL(url, score, nullptr);
SiteEngagementScore engagement_score = CreateEngagementScore(url);
engagement_score.Reset(score, clock_->Now());
engagement_score.Commit();
}
void SiteEngagementService::SetLastShortcutLaunchTime(const GURL& url) {
HostContentSettingsMap* settings_map =
HostContentSettingsMapFactory::GetForProfile(profile_);
std::unique_ptr<base::DictionaryValue> score_dict =
GetScoreDictForOrigin(settings_map, url);
SiteEngagementScore score(clock_.get(), *score_dict);
SiteEngagementScore score = CreateEngagementScore(url);
// Record the number of days since the last launch in UMA. If the user's clock
// has changed back in time, set this to 0.
......@@ -232,21 +209,11 @@ void SiteEngagementService::SetLastShortcutLaunchTime(const GURL& url) {
SiteEngagementMetrics::ENGAGEMENT_WEBAPP_SHORTCUT_LAUNCH);
score.set_last_shortcut_launch_time(now);
if (score.UpdateScoreDict(score_dict.get())) {
settings_map->SetWebsiteSettingDefaultScope(
url, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(),
score_dict.release());
}
score.Commit();
}
double SiteEngagementService::GetScore(const GURL& url) const {
HostContentSettingsMap* settings_map =
HostContentSettingsMapFactory::GetForProfile(profile_);
std::unique_ptr<base::DictionaryValue> score_dict =
GetScoreDictForOrigin(settings_map, url);
SiteEngagementScore score(clock_.get(), *score_dict);
return score.GetScore();
return CreateEngagementScore(url).GetScore();
}
double SiteEngagementService::GetTotalEngagementPoints() const {
......@@ -270,18 +237,10 @@ SiteEngagementService::SiteEngagementService(Profile* profile,
}
void SiteEngagementService::AddPoints(const GURL& url, double points) {
HostContentSettingsMap* settings_map =
HostContentSettingsMapFactory::GetForProfile(profile_);
std::unique_ptr<base::DictionaryValue> score_dict =
GetScoreDictForOrigin(settings_map, url);
SiteEngagementScore score(clock_.get(), *score_dict);
SiteEngagementScore score = CreateEngagementScore(url);
score.AddPoints(points);
if (score.UpdateScoreDict(score_dict.get())) {
settings_map->SetWebsiteSettingDefaultScope(
url, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(),
score_dict.release());
}
score.Commit();
}
void SiteEngagementService::AfterStartupTask() {
......@@ -297,13 +256,8 @@ void SiteEngagementService::CleanupEngagementScores() {
for (const auto& site : *engagement_settings) {
GURL origin(site.primary_pattern.ToString());
if (origin.is_valid()) {
std::unique_ptr<base::DictionaryValue> score_dict =
GetScoreDictForOrigin(settings_map, origin);
SiteEngagementScore score(clock_.get(), *score_dict);
if (score.GetScore() != 0)
if (origin.is_valid() && GetScore(origin) != 0)
continue;
}
settings_map->SetWebsiteSettingDefaultScope(
origin, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(),
......@@ -412,6 +366,20 @@ void SiteEngagementService::OnURLsDeleted(
weak_factory_.GetWeakPtr(), hs, origins, expired));
}
const SiteEngagementScore SiteEngagementService::CreateEngagementScore(
const GURL& origin) const {
return SiteEngagementScore(
clock_.get(), origin,
HostContentSettingsMapFactory::GetForProfile(profile_));
}
SiteEngagementScore SiteEngagementService::CreateEngagementScore(
const GURL& origin) {
return SiteEngagementScore(
clock_.get(), origin,
HostContentSettingsMapFactory::GetForProfile(profile_));
}
int SiteEngagementService::OriginsWithMaxDailyEngagement() const {
HostContentSettingsMap* settings_map =
HostContentSettingsMapFactory::GetForProfile(profile_);
......@@ -426,10 +394,7 @@ int SiteEngagementService::OriginsWithMaxDailyEngagement() const {
if (!origin.is_valid())
continue;
std::unique_ptr<base::DictionaryValue> score_dict =
GetScoreDictForOrigin(settings_map, origin);
SiteEngagementScore score(clock_.get(), *score_dict);
if (score.MaxPointsPerDayAdded())
if (CreateEngagementScore(origin).MaxPointsPerDayAdded())
++total_origins;
}
......@@ -462,6 +427,11 @@ void SiteEngagementService::GetCountsAndLastVisitForOriginsComplete(
for (const auto& origin_to_count : remaining_origins) {
GURL origin = origin_to_count.first;
// It appears that the history service occasionally sends bad URLs to us.
// See crbug.com/612881.
if (!origin.is_valid())
continue;
int remaining = origin_to_count.second.first;
base::Time last_visit = origin_to_count.second.second;
int deleted = deleted_origins.count(origin);
......@@ -496,40 +466,17 @@ void SiteEngagementService::GetCountsAndLastVisitForOriginsComplete(
undecay = periods * SiteEngagementScore::GetDecayPoints();
}
double score =
std::min(SiteEngagementScore::kMaxPoints,
(proportion_remaining * GetScore(origin)) + undecay);
ResetScoreAndAccessTimesForURL(origin, score, &last_visit);
}
}
void SiteEngagementService::ResetScoreAndAccessTimesForURL(
const GURL& url, double score, const base::Time* updated_time) {
// It appears that the history service occassionally sends bad URLs to us.
// See crbug.com/612881.
if (!url.is_valid())
return;
DCHECK_GE(score, 0);
DCHECK_LE(score, SiteEngagementScore::kMaxPoints);
SiteEngagementScore engagement_score = CreateEngagementScore(origin);
HostContentSettingsMap* settings_map =
HostContentSettingsMapFactory::GetForProfile(profile_);
std::unique_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;
}
double score = std::min(
SiteEngagementScore::kMaxPoints,
(proportion_remaining * engagement_score.GetScore()) + undecay);
engagement_score.Reset(score, last_visit);
if (!engagement_score.last_shortcut_launch_time().is_null()
&& engagement_score.last_shortcut_launch_time() > last_visit) {
engagement_score.set_last_shortcut_launch_time(last_visit);
}
if (engagement_score.UpdateScoreDict(score_dict.get())) {
settings_map->SetWebsiteSettingDefaultScope(
url, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(),
score_dict.release());
engagement_score.Commit();
}
}
......@@ -29,6 +29,7 @@ class HistoryService;
class GURL;
class Profile;
class SiteEngagementScore;
class SiteEngagementScoreProvider {
public:
......@@ -92,7 +93,7 @@ class SiteEngagementService : public KeyedService,
// Returns whether the engagement service has enough data to make meaningful
// decisions. Clients should avoid using engagement in their heuristic until
// this is true.
bool IsBootstrapped();
bool IsBootstrapped() const;
// Returns whether |url| has at least the given |level| of engagement.
bool IsEngagementAtLeast(const GURL& url, EngagementLevel level) const;
......@@ -130,6 +131,10 @@ class SiteEngagementService : public KeyedService,
// maximum limits for the day and overall.
void AddPoints(const GURL& url, double points);
// Retrieves the SiteEngagementScore object for |origin|.
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.
void AfterStartupTask();
......@@ -167,17 +172,10 @@ class SiteEngagementService : public KeyedService,
// Callback for the history service when it is asked for a map of origins to
// how many URLs corresponding to that origin remain in history.
void GetCountsAndLastVisitForOriginsComplete(
history::HistoryService* history_service,
const std::multiset<GURL>& deleted_url_origins,
bool expired,
const history::OriginCountAndLastVisitMap& remaining_origin_counts);
// Resets the engagement score for |url| to |score|, and sets the last
// engagement time and last shortcut launch time (if it is non-null) to
// |updated_time|. Clears daily limits.
void ResetScoreAndAccessTimesForURL(const GURL& url,
double score,
const base::Time* updated_time);
history::HistoryService* history_service,
const std::multiset<GURL>& deleted_url_origins,
bool expired,
const history::OriginCountAndLastVisitMap& remaining_origin_counts);
Profile* profile_;
......