Chromium Code Reviews| 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. |
| * |