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

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

Issue 2362323002: [NTP Snippets] Reschedule background fetching on app upgrade if it was scheduled before (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
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 c7b148677ef28a5420e51ae408d6f20540adc01c..f18c5adb864ccd11d530e97cfdd6ef2956ed93e7 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
@@ -10,6 +10,7 @@ import com.google.android.gms.gcm.GcmNetworkManager;
import com.google.android.gms.gcm.PeriodicTask;
import com.google.android.gms.gcm.Task;
+import org.chromium.base.ContextUtils;
import org.chromium.base.Log;
import org.chromium.base.VisibleForTesting;
import org.chromium.base.annotations.CalledByNative;
@@ -38,6 +39,9 @@ public class SnippetsLauncher {
// The amount of "flex" to add around the fetching periods, as a ratio of the period.
private static final double FLEX_FACTOR = 0.1;
+ @VisibleForTesting
+ public static final String PREF_IS_SCHEDULED = "ntp_snippets.is_scheduled";
+
// 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;
@@ -129,7 +133,14 @@ public class SnippetsLauncher {
@CalledByNative
private boolean schedule(long periodWifiSeconds, long periodFallbackSeconds) {
if (!mGCMEnabled) return false;
- Log.d(TAG, "Scheduling: " + periodWifiSeconds + " " + periodFallbackSeconds);
+ Log.i(TAG, "Scheduling: " + periodWifiSeconds + " " + periodFallbackSeconds);
+
+ boolean isScheduled = periodWifiSeconds != 0 || periodFallbackSeconds != 0;
+ ContextUtils.getAppSharedPreferences()
+ .edit()
+ .putBoolean(PREF_IS_SCHEDULED, isScheduled)
+ .apply();
+
// Google Play Services may not be up to date, if the application was not installed through
// the Play Store. In this case, scheduling the task will fail silently.
try {
@@ -142,6 +153,8 @@ public class SnippetsLauncher {
} catch (IllegalArgumentException e) {
// Disable GCM for the remainder of this session.
mGCMEnabled = false;
+
+ ContextUtils.getAppSharedPreferences().edit().remove(PREF_IS_SCHEDULED).apply();
// Return false so that the failure will be logged.
return false;
}
@@ -154,5 +167,10 @@ public class SnippetsLauncher {
Log.i(TAG, "Unscheduling");
return schedule(0, 0);
}
+
+ public static boolean shouldRescheduleTasksOnUpgrade() {
+ // Reschedule the periodic tasks if they were enabled previously.
+ return ContextUtils.getAppSharedPreferences().getBoolean(PREF_IS_SCHEDULED, false);
+ }
}

Powered by Google App Engine
This is Rietveld 408576698