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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/precache/PrecacheServiceLauncher.java

Issue 1266243003: Tweaks to the precache triggering code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 5 years, 4 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/precache/PrecacheServiceLauncher.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/precache/PrecacheServiceLauncher.java b/chrome/android/java/src/org/chromium/chrome/browser/precache/PrecacheServiceLauncher.java
index 5df6c9b7bb1e850791e0add5f628f3fec948929c..f87edd24be64cfdfa4a71958a2b16ce6bd767079 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/precache/PrecacheServiceLauncher.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/precache/PrecacheServiceLauncher.java
@@ -16,6 +16,7 @@ import android.os.PowerManager.WakeLock;
import android.os.SystemClock;
import android.preference.PreferenceManager;
+import org.chromium.base.Log;
import org.chromium.base.ThreadUtils;
import org.chromium.base.VisibleForTesting;
import org.chromium.components.precache.DeviceState;
@@ -27,7 +28,7 @@ import org.chromium.components.precache.DeviceState;
* |WAIT_UNTIL_NEXT_PRECACHE_MS| have passed since the last time precaching was done.
*/
public class PrecacheServiceLauncher extends BroadcastReceiver {
- private static final String TAG = "PrecacheServiceLauncher";
+ private static final String TAG = "cr.Precache";
@VisibleForTesting
static final String PREF_IS_PRECACHING_ENABLED = "precache.is_precaching_enabled";
@@ -61,6 +62,7 @@ public class PrecacheServiceLauncher extends BroadcastReceiver {
* @param enabled Whether or not precaching is enabled.
*/
public static void setIsPrecachingEnabled(Context context, boolean enabled) {
+ Log.v(TAG, "setIsPrecachingEnabled(%s)", enabled);
Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
editor.putBoolean(PREF_IS_PRECACHING_ENABLED, enabled);
editor.apply();
@@ -73,11 +75,15 @@ public class PrecacheServiceLauncher extends BroadcastReceiver {
}
}
+ @VisibleForTesting
+ static boolean isPrecachingEnabled(Context context) {
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
+ return prefs.getBoolean(PREF_IS_PRECACHING_ENABLED, false);
+ }
@Override
public void onReceive(Context context, Intent intent) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
- boolean isPrecachingEnabled = prefs.getBoolean(PREF_IS_PRECACHING_ENABLED, false);
long lastPrecacheTimeMs = prefs.getLong(PREF_PRECACHE_LAST_TIME, 0L);
if (lastPrecacheTimeMs > getElapsedRealtimeOnSystem()) {
// System.elapsedRealtime() counts milliseconds since boot, so if the device has been
@@ -86,7 +92,7 @@ public class PrecacheServiceLauncher extends BroadcastReceiver {
}
// Do nothing if precaching is disabled.
- if (!isPrecachingEnabled) return;
+ if (!isPrecachingEnabled(context)) return;
boolean isPowerConnected = mDeviceState.isPowerConnected(context);
boolean isWifiAvailable = mDeviceState.isWifiAvailable(context);

Powered by Google App Engine
This is Rietveld 408576698