Commit b1ef86c6 authored by Mounir Lamouri's avatar Mounir Lamouri Committed by Commit Bot

Media Engagement: better handling of history service callbacks.

- When all history is cleared, simply wipe all of MEI data instead of
  handling it per website.
- When history is expired, do nothing. Better handling of this event
  will be implemented as par tof bug 818153

Bug: 815163
Change-Id: I87c5d3e91b4c4e0c3191bb3c4e9c889ac6830790
Reviewed-on: https://chromium-review.googlesource.com/946169
Commit-Queue: Tommy Steimel <steimel@chromium.org>
Reviewed-by: default avatarTommy Steimel <steimel@chromium.org>
Reviewed-by: default avatarIlya Sherman <isherman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#540842}
parent 124ef83e
......@@ -29,12 +29,24 @@ const char MediaEngagementService::kHistogramScoreAtStartupName[] =
const char MediaEngagementService::kHistogramURLsDeletedScoreReductionName[] =
"Media.Engagement.URLsDeletedScoreReduction";
const char MediaEngagementService::kHistogramClearName[] =
"Media.Engagement.Clear";
namespace {
// The current schema version of the MEI data. If this value is higher
// than the stored value, all MEI data will be wiped.
static const int kSchemaVersion = 4;
// Do not change the values of this enum as it is used for UMA.
enum class MediaEngagementClearReason {
kDataAll = 0,
kDataRange = 1,
kHistoryAll = 2,
kHistoryRange = 3,
kCount
};
bool MediaEngagementFilterAdapter(
const GURL& predicate,
const ContentSettingsPattern& primary_pattern,
......@@ -66,6 +78,11 @@ void RecordURLsDeletedScoreReduction(double previous_score,
difference);
}
void RecordClear(MediaEngagementClearReason reason) {
UMA_HISTOGRAM_ENUMERATION(MediaEngagementService::kHistogramClearName, reason,
MediaEngagementClearReason::kCount);
}
} // namespace
// static
......@@ -149,6 +166,11 @@ void MediaEngagementService::SetSchemaVersion(int version) {
void MediaEngagementService::ClearDataBetweenTime(
const base::Time& delete_begin,
const base::Time& delete_end) {
if (delete_begin == base::Time() && delete_end == base::Time::Max())
RecordClear(MediaEngagementClearReason::kDataAll);
else
RecordClear(MediaEngagementClearReason::kDataRange);
HostContentSettingsMapFactory::GetForProfile(profile_)
->ClearSettingsForOneTypeWithPredicate(
CONTENT_SETTINGS_TYPE_MEDIA_ENGAGEMENT, base::Time(),
......@@ -177,6 +199,19 @@ void MediaEngagementService::OnURLsDeleted(
bool expired,
const history::URLRows& deleted_rows,
const std::set<GURL>& favicon_urls) {
if (all_history) {
RecordClear(MediaEngagementClearReason::kHistoryAll);
HostContentSettingsMapFactory::GetForProfile(profile_)
->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_MEDIA_ENGAGEMENT);
return;
}
// TODO(818153): history expiration currently has no effect on MEI but entries
// that no longer appear in history should be removed from the database.
if (expired)
return;
std::map<GURL, int> origins;
for (const history::URLRow& row : deleted_rows) {
GURL origin = row.url().GetOrigin();
......@@ -186,6 +221,9 @@ void MediaEngagementService::OnURLsDeleted(
origins[origin]++;
}
if (!origins.empty())
RecordClear(MediaEngagementClearReason::kHistoryRange);
for (auto const& kv : origins) {
// Remove the number of visits consistent with the number
// of URLs from the same origin we are removing.
......
......@@ -102,6 +102,10 @@ class MediaEngagementService : public KeyedService,
// is cleared.
static const char kHistogramURLsDeletedScoreReductionName[];
// The name of the histogram that records the reason why the engagement was
// cleared, either partially or fully.
static const char kHistogramClearName[];
private:
friend class MediaEngagementBrowserTest;
friend class MediaEngagementContentsObserverTest;
......
......@@ -28536,6 +28536,13 @@ Called by update_use_counter_css.py.-->
<int value="21" label="Gesture requirement overridden by play method."/>
</enum>
<enum name="MediaEngagementClearReason">
<int value="0" label="Data (all)"/>
<int value="1" label="Data (range)"/>
<int value="2" label="History (all)"/>
<int value="3" label="History (range)"/>
</enum>
<enum name="MediaEngagementSessionEvent">
<int value="0" label="Created"/>
<int value="1" label="Significant Playback"/>
......@@ -35372,6 +35372,15 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
</summary>
</histogram>
<histogram name="Media.Engagement.Clear" enum="MediaEngagementClearReason">
<owner>mlamouri@chromium.org</owner>
<owner>media-dev@chromium.org</owner>
<summary>
Records the reason why the Media Engagement data was cleared. Partial
changes and full wipeout will both be recorded as one event.
</summary>
</histogram>
<histogram name="Media.Engagement.PreloadedList.CheckResult"
enum="PreloadedListCheckResult">
<owner>beccahughes@chromium.org</owner>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment