Skip to content

Commit

Permalink
[ios] Add finch params for Foreground Refresh
Browse files Browse the repository at this point in the history
Bug: 1418430
Change-Id: I5a7680c22c6fb0af345d39bb23ee691c42fee08e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4300422
Reviewed-by: Sergio Collazos <sczs@chromium.org>
Commit-Queue: edchin <edchin@google.com>
Cr-Commit-Position: refs/heads/main@{#1111983}
  • Loading branch information
edx246 authored and Chromium LUCI CQ committed Mar 2, 2023
1 parent 783979b commit 2ecfdcd
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 10 deletions.
22 changes: 22 additions & 0 deletions ios/chrome/browser/ntp/features.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ extern const char kEnableFeedRefreshPostFeedSession[];
// backgrounding.
extern const char kEnableFeedRefreshOnAppBackgrounding[];

// Feature param under `kEnableFeedForegroundRefresh` for the time interval used
// to set the session end timer.
extern const char kFeedSessionEndTimerTimeoutInSeconds[];

// Feature param under `kEnableFeedForegroundRefresh` for the refresh threshold
// when the last refresh was seen.
extern const char kFeedSeenRefreshThresholdInSeconds[];

// Feature param under `kEnableFeedForegroundRefresh` for the refresh threshold
// when the last refresh was unseen.
extern const char kFeedUnseenRefreshThresholdInSeconds[];

// Whether the Following Feed is enabled on NTP.
bool IsWebChannelsEnabled();

Expand Down Expand Up @@ -135,6 +147,16 @@ bool IsFeedRefreshPostFeedSessionEnabled();
// different from background refresh.
bool IsFeedRefreshOnAppBackgroundingEnabled();

// Returns the time interval used to set the session end timer.
double GetFeedSessionEndTimerTimeoutInSeconds();

// Returns the refresh threshold (aka feed expiration) for a feed that has been
// seen.
double GetFeedSeenRefreshThresholdInSeconds();

// Returns the refresh threshold (aka feed expiration) for an unseen feed.
double GetFeedUnseenRefreshThresholdInSeconds();

// YES if enabled Feed bottom sign-in promo.
bool IsFeedBottomSignInPromoEnabled();

Expand Down
39 changes: 39 additions & 0 deletions ios/chrome/browser/ntp/features.mm
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@
"EnableFeedRefreshPostFeedSession";
const char kEnableFeedRefreshOnAppBackgrounding[] =
"EnableFeedRefreshOnAppBackgrounding";
const char kFeedSessionEndTimerTimeoutInSeconds[] =
"FeedSessionEndTimerTimeoutInSeconds";
const char kFeedSeenRefreshThresholdInSeconds[] =
"FeedSeenRefreshThresholdInSeconds";
const char kFeedUnseenRefreshThresholdInSeconds[] =
"FeedUnseenRefreshThresholdInSeconds";

bool IsWebChannelsEnabled() {
return base::FeatureList::IsEnabled(kEnableWebChannels);
Expand Down Expand Up @@ -204,6 +210,39 @@ bool IsFeedRefreshOnAppBackgroundingEnabled() {
/*default=*/false);
}

double GetFeedSessionEndTimerTimeoutInSeconds() {
double override_value = [[NSUserDefaults standardUserDefaults]
doubleForKey:@"FeedSessionEndTimerTimeoutInSeconds"];
if (override_value > 0.0) {
return override_value;
}
return base::GetFieldTrialParamByFeatureAsDouble(
kEnableFeedForegroundRefresh, kFeedSessionEndTimerTimeoutInSeconds,
/*default=*/base::Minutes(5).InSecondsF());
}

double GetFeedSeenRefreshThresholdInSeconds() {
double override_value = [[NSUserDefaults standardUserDefaults]
doubleForKey:@"FeedSeenRefreshThresholdInSeconds"];
if (override_value > 0.0) {
return override_value;
}
return base::GetFieldTrialParamByFeatureAsDouble(
kEnableFeedForegroundRefresh, kFeedSeenRefreshThresholdInSeconds,
/*default=*/base::Hours(1).InSecondsF());
}

double GetFeedUnseenRefreshThresholdInSeconds() {
double override_value = [[NSUserDefaults standardUserDefaults]
doubleForKey:@"FeedUnseenRefreshThresholdInSeconds"];
if (override_value > 0.0) {
return override_value;
}
return base::GetFieldTrialParamByFeatureAsDouble(
kEnableFeedForegroundRefresh, kFeedUnseenRefreshThresholdInSeconds,
/*default=*/base::Hours(6).InSecondsF());
}

bool IsFeedBottomSignInPromoEnabled() {
return base::FeatureList::IsEnabled(kEnableFeedBottomSignInPromo);
}
Expand Down
19 changes: 9 additions & 10 deletions ios/chrome/browser/ui/ntp/metrics/feed_metrics_recorder.mm
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ @interface FeedMetricsRecorder ()
@property(nonatomic, assign) NSTimeInterval discoverPreviousTimeInFeedGV;
@property(nonatomic, assign) NSTimeInterval followingPreviousTimeInFeedGV;

// Timer to signal end of session. Set for `kMinutesBetweenSessions`.
// Timer to signal end of session.
@property(nonatomic, strong) NSTimer* sessionEndTimer;

@end
Expand Down Expand Up @@ -1191,18 +1191,17 @@ - (void)recordOpenURL {
}
}

// Sets or extends the session end timer by `kMinutesBetweenSessions`.
// Sets or extends the session end timer.
- (void)setOrExtendSessionEndTimer {
[self.sessionEndTimer invalidate];
__weak FeedMetricsRecorder* weakSelf = self;
self.sessionEndTimer =
[NSTimer scheduledTimerWithTimeInterval:kMinutesBetweenSessions *
60 /*seconds per minute*/
target:weakSelf
selector:@selector
(refreshFeedIfSessionConditionsAreMet)
userInfo:nil
repeats:NO];
self.sessionEndTimer = [NSTimer
scheduledTimerWithTimeInterval:GetFeedSessionEndTimerTimeoutInSeconds()
target:weakSelf
selector:@selector
(refreshFeedIfSessionConditionsAreMet)
userInfo:nil
repeats:NO];
}

// Refresh the feed if session conditions are met. See implementation for which
Expand Down

0 comments on commit 2ecfdcd

Please sign in to comment.