| Index: chrome/browser/banners/app_banner_settings_helper.cc
|
| diff --git a/chrome/browser/banners/app_banner_settings_helper.cc b/chrome/browser/banners/app_banner_settings_helper.cc
|
| index 3e821591163b0c21a050836abc2382cde5509079..3833e2bf8fcc79129c2d0ad2e7d2bdb7301c3ce8 100644
|
| --- a/chrome/browser/banners/app_banner_settings_helper.cc
|
| +++ b/chrome/browser/banners/app_banner_settings_helper.cc
|
| @@ -8,6 +8,8 @@
|
| #include <string>
|
|
|
| #include "base/command_line.h"
|
| +#include "base/metrics/field_trial.h"
|
| +#include "base/strings/string_number_conversions.h"
|
| #include "chrome/browser/banners/app_banner_data_fetcher.h"
|
| #include "chrome/browser/banners/app_banner_metrics.h"
|
| #include "chrome/browser/browser_process.h"
|
| @@ -36,6 +38,12 @@ const double kTotalEngagementToTrigger = 2;
|
| // Number of days that showing the banner will prevent it being seen again for.
|
| const unsigned int kMinimumDaysBetweenBannerShows = 60;
|
|
|
| +const unsigned int kNumberOfMinutesInADay = 1440;
|
| +
|
| +// Number of minutes between visits that will trigger a could show banner event.
|
| +// Defaults to the number of minutes in a day.
|
| +unsigned int gMinimumMinutesBetweenVisits = kNumberOfMinutesInADay;
|
| +
|
| // Number of days that the banner being blocked will prevent it being seen again
|
| // for.
|
| const unsigned int kMinimumBannerBlockedToBannerShown = 90;
|
| @@ -54,8 +62,7 @@ const char kBannerEngagementKey[] = "engagement";
|
|
|
| // Engagement weight assigned to direct and indirect navigations.
|
| // By default, a direct navigation is a page visit via ui::PAGE_TRANSITION_TYPED
|
| -// or ui::PAGE_TRANSITION_GENERATED. These are weighted twice the engagement of
|
| -// all other navigations.
|
| +// or ui::PAGE_TRANSITION_GENERATED.
|
| double kDirectNavigationEngagement = 1;
|
| double kIndirectNavigationEnagagement = 1;
|
|
|
| @@ -241,7 +248,7 @@ void AppBannerSettingsHelper::RecordBannerCouldShowEvent(
|
|
|
| // Trim any items that are older than we should care about. For comparisons
|
| // the times are converted to local dates.
|
| - base::Time date = time.LocalMidnight();
|
| + base::Time date = BucketTimeToResolution(time, gMinimumMinutesBetweenVisits);
|
| base::ValueVector::iterator it = could_show_list->begin();
|
| while (it != could_show_list->end()) {
|
| if ((*it)->IsType(base::Value::TYPE_DICTIONARY)) {
|
| @@ -251,7 +258,8 @@ void AppBannerSettingsHelper::RecordBannerCouldShowEvent(
|
|
|
| if (internal_value->GetDouble(kBannerTimeKey, &internal_date)) {
|
| base::Time other_date =
|
| - base::Time::FromInternalValue(internal_date).LocalMidnight();
|
| + BucketTimeToResolution(base::Time::FromInternalValue(internal_date),
|
| + gMinimumMinutesBetweenVisits);
|
| if (other_date == date) {
|
| double other_engagement = 0;
|
| if (internal_value->GetDouble(kBannerEngagementKey,
|
| @@ -433,3 +441,42 @@ void AppBannerSettingsHelper::SetEngagementWeights(double direct_engagement,
|
| kDirectNavigationEngagement = direct_engagement;
|
| kIndirectNavigationEnagagement = indirect_engagement;
|
| }
|
| +
|
| +void AppBannerSettingsHelper::SetMinimumMinutesBetweenVisits(
|
| + unsigned int minutes) {
|
| + gMinimumMinutesBetweenVisits = minutes;
|
| +}
|
| +
|
| +// Given a time, returns that time scoped to the nearest minute resolution
|
| +// locally. For example, if the resolution is one hour, this function will
|
| +// return the time to the closest (previous) hour in the local time zone.
|
| +base::Time AppBannerSettingsHelper::BucketTimeToResolution(
|
| + base::Time time,
|
| + unsigned int minutes) {
|
| + // Only support resolutions smaller than or equal to one day. Enforce
|
| + // that resolutions divide evenly into one day. Otherwise, default to a
|
| + // day resolution (each time converted to midnight local time).
|
| + if (minutes == 0 || minutes > kNumberOfMinutesInADay ||
|
| + kNumberOfMinutesInADay % minutes != 0) {
|
| + return time.LocalMidnight();
|
| + }
|
| +
|
| + // Extract the number of minutes past midnight in local time. Divide that
|
| + // number by the resolution size, and return the time converted to local
|
| + // midnight with the resulting truncated number added.
|
| + base::Time::Exploded exploded;
|
| + time.LocalExplode(&exploded);
|
| + int total_minutes = exploded.hour * 60 + exploded.minute;
|
| +
|
| + // Use truncating integer division here.
|
| + return time.LocalMidnight() +
|
| + base::TimeDelta::FromMinutes((total_minutes / minutes) * minutes);
|
| +}
|
| +
|
| +void AppBannerSettingsHelper::UpdateMinutesBetweenVisits() {
|
| + std::string minutes_between_visits =
|
| + base::FieldTrialList::FindFullName("AppBannersMinutesBetweenVisits");
|
| + int minimum_minutes = 0;
|
| + if (base::StringToInt(minutes_between_visits, &minimum_minutes))
|
| + AppBannerSettingsHelper::SetMinimumMinutesBetweenVisits(minimum_minutes);
|
| +}
|
|
|