OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.components.invalidation; | 5 package org.chromium.components.invalidation; |
6 | 6 |
7 import android.accounts.Account; | 7 import android.accounts.Account; |
8 import android.content.Context; | 8 import android.content.Context; |
9 import android.content.Intent; | 9 import android.content.Intent; |
10 | 10 |
11 import com.google.protos.ipc.invalidation.Types; | 11 import com.google.protos.ipc.invalidation.Types; |
12 | 12 |
13 import org.chromium.base.ApplicationStatus; | |
14 import org.chromium.base.BuildInfo; | |
15 import org.chromium.base.Log; | |
13 import org.chromium.base.ThreadUtils; | 16 import org.chromium.base.ThreadUtils; |
14 import org.chromium.base.VisibleForTesting; | 17 import org.chromium.base.VisibleForTesting; |
15 import org.chromium.base.annotations.CalledByNative; | 18 import org.chromium.base.annotations.CalledByNative; |
16 import org.chromium.base.annotations.JNINamespace; | 19 import org.chromium.base.annotations.JNINamespace; |
17 import org.chromium.components.sync.notifier.InvalidationClientNameProvider; | 20 import org.chromium.components.sync.notifier.InvalidationClientNameProvider; |
18 import org.chromium.components.sync.notifier.InvalidationIntentProtocol; | 21 import org.chromium.components.sync.notifier.InvalidationIntentProtocol; |
19 import org.chromium.components.sync.notifier.InvalidationPreferences; | 22 import org.chromium.components.sync.notifier.InvalidationPreferences; |
20 | 23 |
21 /** | 24 /** |
22 * Wrapper for invalidations::InvalidationServiceAndroid. | 25 * Wrapper for invalidations::InvalidationServiceAndroid. |
23 * | 26 * |
24 * Serves as the bridge between Java and C++ for the invalidations component. | 27 * Serves as the bridge between Java and C++ for the invalidations component. |
25 */ | 28 */ |
26 @JNINamespace("invalidation") | 29 @JNINamespace("invalidation") |
27 public class InvalidationService { | 30 public class InvalidationService { |
28 private final Context mContext; | 31 private final Context mContext; |
29 | 32 |
30 private final long mNativeInvalidationServiceAndroid; | 33 private final long mNativeInvalidationServiceAndroid; |
31 | 34 |
35 private static final String TAG = "cr_invalidation"; | |
36 | |
32 private InvalidationService(Context context, long nativeInvalidationServiceA ndroid) { | 37 private InvalidationService(Context context, long nativeInvalidationServiceA ndroid) { |
33 mContext = context.getApplicationContext(); | 38 mContext = context.getApplicationContext(); |
34 if (mContext == null) { | 39 if (mContext == null) { |
35 throw new NullPointerException("mContext is null."); | 40 throw new NullPointerException("mContext is null."); |
36 } | 41 } |
37 mNativeInvalidationServiceAndroid = nativeInvalidationServiceAndroid; | 42 mNativeInvalidationServiceAndroid = nativeInvalidationServiceAndroid; |
38 } | 43 } |
39 | 44 |
40 public void notifyInvalidationToNativeChrome( | 45 public void notifyInvalidationToNativeChrome( |
41 int objectSource, String objectId, long version, String payload) { | 46 int objectSource, String objectId, long version, String payload) { |
(...skipping 22 matching lines...) Expand all Loading... | |
64 */ | 69 */ |
65 @VisibleForTesting | 70 @VisibleForTesting |
66 @CalledByNative | 71 @CalledByNative |
67 public void setRegisteredObjectIds(int[] objectSources, String[] objectNames ) { | 72 public void setRegisteredObjectIds(int[] objectSources, String[] objectNames ) { |
68 InvalidationPreferences invalidationPreferences = new InvalidationPrefer ences(); | 73 InvalidationPreferences invalidationPreferences = new InvalidationPrefer ences(); |
69 Account account = invalidationPreferences.getSavedSyncedAccount(); | 74 Account account = invalidationPreferences.getSavedSyncedAccount(); |
70 Intent registerIntent = InvalidationIntentProtocol.createRegisterIntent( | 75 Intent registerIntent = InvalidationIntentProtocol.createRegisterIntent( |
71 account, objectSources, objectNames); | 76 account, objectSources, objectNames); |
72 registerIntent.setClass( | 77 registerIntent.setClass( |
73 mContext, InvalidationClientService.getRegisteredClass()); | 78 mContext, InvalidationClientService.getRegisteredClass()); |
79 | |
80 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
| |
81 Log.e(TAG, "Failed to register objects"); | |
82 return; | |
83 } | |
74 mContext.startService(registerIntent); | 84 mContext.startService(registerIntent); |
75 } | 85 } |
76 | 86 |
87 private boolean shouldRestrictBackgroundServices() { | |
88 // Restricts the use of background services when not in foreground. See crbug.com/680812. | |
89 return BuildInfo.isGreaterThanN() && !ApplicationStatus.hasVisibleActivi ties(); | |
90 } | |
91 | |
77 /** | 92 /** |
78 * Fetches the Invalidator client name. | 93 * Fetches the Invalidator client name. |
79 * | 94 * |
80 * Note that there is a naming discrepancy here. In C++, we refer to the in validation client | 95 * Note that there is a naming discrepancy here. In C++, we refer to the in validation client |
81 * identifier that is unique for every invalidation client instance in an ac count as the client | 96 * identifier that is unique for every invalidation client instance in an ac count as the client |
82 * ID. In Java, we call it the client name. | 97 * ID. In Java, we call it the client name. |
83 */ | 98 */ |
84 @CalledByNative | 99 @CalledByNative |
85 private byte[] getInvalidatorClientId() { | 100 private byte[] getInvalidatorClientId() { |
86 return InvalidationClientNameProvider.get().getInvalidatorClientName(); | 101 return InvalidationClientNameProvider.get().getInvalidatorClientName(); |
87 } | 102 } |
88 | 103 |
89 private native void nativeInvalidate(long nativeInvalidationServiceAndroid, int objectSource, | 104 private native void nativeInvalidate(long nativeInvalidationServiceAndroid, int objectSource, |
90 String objectId, long version, String payload); | 105 String objectId, long version, String payload); |
91 } | 106 } |
OLD | NEW |