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

Unified Diff: components/invalidation/impl/android/java/src/org/chromium/components/invalidation/InvalidationService.java

Issue 2698723003: chrome[android]: Restrict the use of startService for invalidations. (Closed)
Patch Set: Created 3 years, 10 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: components/invalidation/impl/android/java/src/org/chromium/components/invalidation/InvalidationService.java
diff --git a/components/invalidation/impl/android/java/src/org/chromium/components/invalidation/InvalidationService.java b/components/invalidation/impl/android/java/src/org/chromium/components/invalidation/InvalidationService.java
index 92c017ad1b8679f919de121af17d81454c1a5ab2..170681bd1d7df0695d8a62c49b89351adf21750c 100644
--- a/components/invalidation/impl/android/java/src/org/chromium/components/invalidation/InvalidationService.java
+++ b/components/invalidation/impl/android/java/src/org/chromium/components/invalidation/InvalidationService.java
@@ -10,6 +10,9 @@ import android.content.Intent;
import com.google.protos.ipc.invalidation.Types;
+import org.chromium.base.ApplicationStatus;
+import org.chromium.base.BuildInfo;
+import org.chromium.base.Log;
import org.chromium.base.ThreadUtils;
import org.chromium.base.VisibleForTesting;
import org.chromium.base.annotations.CalledByNative;
@@ -29,6 +32,8 @@ public class InvalidationService {
private final long mNativeInvalidationServiceAndroid;
+ private static final String TAG = "cr_invalidation";
+
private InvalidationService(Context context, long nativeInvalidationServiceAndroid) {
mContext = context.getApplicationContext();
if (mContext == null) {
@@ -71,9 +76,19 @@ public class InvalidationService {
account, objectSources, objectNames);
registerIntent.setClass(
mContext, InvalidationClientService.getRegisteredClass());
+
+ if (shouldRestrictBackgroundServices()) {
Khushal 2017/02/16 05:34:23 Sigh. I considered this one in particular, since w
ghc 2017/02/17 19:27:38 I think that would involve sending all registratio
Khushal 2017/02/17 21:12:01 That's what the current code tries to do I think.
ghc 2017/02/17 21:31:36 There is logic to avoid sending a message if the s
Khushal 2017/02/17 21:54:52 What about this code: https://cs.chromium.org/chro
nyquist 2017/02/21 19:46:18 So this is a little bit scary. If this ends up fai
Khushal 2017/02/21 20:52:25 About the discussion on persisted state, on taking
nyquist 2017/02/22 10:48:13 Well then, unless ghc@ has a better idea, I guess
ghc 2017/02/22 22:03:23 I don't think I have any better ideas. The ticl is
+ Log.e(TAG, "Failed to register objects");
+ return;
+ }
mContext.startService(registerIntent);
}
+ private boolean shouldRestrictBackgroundServices() {
+ // Restricts the use of background services when not in foreground. See crbug.com/680812.
+ return BuildInfo.isGreaterThanN() && !ApplicationStatus.hasVisibleActivities();
+ }
+
/**
* Fetches the Invalidator client name.
*

Powered by Google App Engine
This is Rietveld 408576698