Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(936)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetsLauncher.java

Issue 2366813003: [NTP Snippets] Add a bit of 'flex' to the background fetching intervals (Closed)
Patch Set: bauerb review Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetsLauncher.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetsLauncher.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetsLauncher.java
index c4d6fbf3be9c3728a52a5635a1639aa964810dc1..c7b148677ef28a5420e51ae408d6f20540adc01c 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetsLauncher.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetsLauncher.java
@@ -35,6 +35,9 @@ public class SnippetsLauncher {
// TODO(treib): Remove this after M55.
private static final String OBSOLETE_TASK_TAG_RESCHEDULE = "RescheduleSnippets";
+ // The amount of "flex" to add around the fetching periods, as a ratio of the period.
+ private static final double FLEX_FACTOR = 0.1;
+
// The instance of SnippetsLauncher currently owned by a C++ SnippetsLauncherAndroid, if any.
// If it is non-null then the browser is running.
private static SnippetsLauncher sInstance;
@@ -97,10 +100,18 @@ public class SnippetsLauncher {
private static PeriodicTask buildFetchTask(
String tag, long periodSeconds, int requiredNetwork) {
+ // Add a bit of "flex" around the target period. This achieves the following:
+ // - It makes sure the task doesn't run (significantly) before its initial period has
+ // elapsed. In practice, the scheduler seems to behave like that anyway, but it doesn't
+ // guarantee that, so we shouldn't rely on it.
+ // - It gives the scheduler a bit of room to optimize for battery life.
+ long effectivePeriodSeconds = (long) (periodSeconds * (1.0 + FLEX_FACTOR));
+ long flexSeconds = (long) (periodSeconds * (2.0 * FLEX_FACTOR));
return new PeriodicTask.Builder()
.setService(ChromeBackgroundService.class)
.setTag(tag)
- .setPeriod(periodSeconds)
+ .setPeriod(effectivePeriodSeconds)
+ .setFlex(flexSeconds)
.setRequiredNetwork(requiredNetwork)
.setPersisted(true)
.setUpdateCurrent(true)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698