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

Unified Diff: sync/android/java/src/org/chromium/sync/notifier/InvalidationController.java

Issue 23643002: Enable invalidations for arbitrary objects on Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 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: sync/android/java/src/org/chromium/sync/notifier/InvalidationController.java
diff --git a/sync/android/java/src/org/chromium/sync/notifier/InvalidationController.java b/sync/android/java/src/org/chromium/sync/notifier/InvalidationController.java
index 663ca00ab9ee4db0e58a493ffc1b2394f5d9f488..3aaf2cbc83a50047f79b1789cc12b3368a2d9978 100644
--- a/sync/android/java/src/org/chromium/sync/notifier/InvalidationController.java
+++ b/sync/android/java/src/org/chromium/sync/notifier/InvalidationController.java
@@ -10,11 +10,14 @@ import android.content.Intent;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
+import com.google.ipc.invalidation.external.client.types.ObjectId;
import org.chromium.base.ActivityStatus;
+import org.chromium.base.CalledByNative;
import org.chromium.base.CollectionUtil;
import org.chromium.sync.internal_api.pub.base.ModelType;
+import java.util.HashSet;
import java.util.Set;
/**
@@ -44,6 +47,18 @@ public class InvalidationController implements ActivityStatus.StateListener {
public static final String EXTRA_REGISTERED_TYPES = "registered_types";
/**
+ * Int-array-valued intent extra containing sources of objects to register for.
+ * The array is parallel to EXTRA_REGISTERED_OBJECT_NAMES.
+ */
+ public static final String EXTRA_REGISTERED_OBJECT_SOURCES = "registered_object_sources";
+
+ /**
+ * String-array-valued intent extra containing names of objects to register for.
+ * The array is parallel to EXTRA_REGISTERED_OBJECT_SOURCES.
+ */
+ public static final String EXTRA_REGISTERED_OBJECT_NAMES = "registered_object_names";
+
+ /**
* Boolean-valued intent extra indicating that the service should be stopped.
*/
public static final String EXTRA_STOP = "stop";
@@ -71,6 +86,19 @@ public class InvalidationController implements ActivityStatus.StateListener {
return registerIntent;
}
+ /**
+ * Create an Intent that will start the invalidation listener service and
+ * register for the object ids with the specified sources and names.
+ */
+ public static Intent createRegisterIntent(Account account, int[] objectSources,
+ String[] objectNames) {
+ Intent registerIntent = new Intent(ACTION_REGISTER);
+ registerIntent.putExtra(EXTRA_REGISTERED_OBJECT_SOURCES, objectSources);
+ registerIntent.putExtra(EXTRA_REGISTERED_OBJECT_NAMES, objectNames);
+ registerIntent.putExtra(EXTRA_ACCOUNT, account);
+ return registerIntent;
+ }
+
/** Returns whether {@code intent} is a stop intent. */
public static boolean isStop(Intent intent) {
return intent.getBooleanExtra(EXTRA_STOP, false);
@@ -78,7 +106,23 @@ public class InvalidationController implements ActivityStatus.StateListener {
/** Returns whether {@code intent} is a registered types change intent. */
public static boolean isRegisteredTypesChange(Intent intent) {
- return intent.hasExtra(EXTRA_REGISTERED_TYPES);
+ return intent.hasExtra(EXTRA_REGISTERED_TYPES) ||
+ intent.hasExtra(EXTRA_REGISTERED_OBJECT_SOURCES);
+ }
+
+ /** Returns the object ids for which to register contained in the intent. */
+ public static Set<ObjectId> getRegisteredObjectIds(Intent intent) {
+ int[] objectSources = intent.getIntArrayExtra(EXTRA_REGISTERED_OBJECT_SOURCES);
+ String[] objectNames = intent.getStringArrayExtra(EXTRA_REGISTERED_OBJECT_NAMES);
+ if (objectSources == null || objectNames == null ||
+ objectSources.length != objectNames.length) {
+ return null;
+ }
+ Set<ObjectId> objectIds = new HashSet<ObjectId>(objectSources.length);
+ for (int i = 0; i < objectSources.length; i++) {
+ objectIds.add(ObjectId.newInstance(objectSources[i], objectNames[i].getBytes()));
+ }
+ return objectIds;
}
private IntentProtocol() {
@@ -122,6 +166,23 @@ public class InvalidationController implements ActivityStatus.StateListener {
}
/**
+ * Sets object ids for which the client should register for notification. This is intended for
+ * registering non-Sync types; Sync types are registered with {@code setRegisteredTypes}.
+ *
+ * @param objectSources The sources of the objects.
+ * @param objectNames The names of the objects.
+ */
+ @CalledByNative
+ public void setRegisteredObjectIds(int[] objectSources, String[] objectNames) {
+ InvalidationPreferences invalidationPreferences = new InvalidationPreferences(mContext);
+ Account account = invalidationPreferences.getSavedSyncedAccount();
+ Intent registerIntent = IntentProtocol.createRegisterIntent(account, objectSources,
+ objectNames);
+ registerIntent.setClass(mContext, InvalidationService.class);
+ mContext.startService(registerIntent);
+ }
+
+ /**
* Starts the invalidation client.
*/
public void start() {
@@ -143,6 +204,7 @@ public class InvalidationController implements ActivityStatus.StateListener {
*
* Calling this method will create the instance if it does not yet exist.
*/
+ @CalledByNative
public static InvalidationController get(Context context) {
synchronized (LOCK) {
if (sInstance == null) {

Powered by Google App Engine
This is Rietveld 408576698