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

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

Issue 459513002: Massive refactor of the Android invalidation code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 6 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: components/invalidation/android/java/src/org/chromium/components/invalidation/InvalidationService.java
diff --git a/components/invalidation/android/java/src/org/chromium/components/invalidation/InvalidationService.java b/components/invalidation/android/java/src/org/chromium/components/invalidation/InvalidationService.java
new file mode 100644
index 0000000000000000000000000000000000000000..05f7c1da7df68ecabeb6b140217a8177d6571517
--- /dev/null
+++ b/components/invalidation/android/java/src/org/chromium/components/invalidation/InvalidationService.java
@@ -0,0 +1,99 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
nyquist 2014/09/04 09:01:56 2014 for non-move-detected files?
maxbogue 2014/09/05 16:42:46 Done.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.components.invalidation;
+
+import android.accounts.Account;
+import android.content.Context;
+import android.content.Intent;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Preconditions;
+
+import org.chromium.base.CalledByNative;
+import org.chromium.base.JNINamespace;
+import org.chromium.base.ThreadUtils;
+import org.chromium.sync.notifier.InvalidationClientNameProvider;
+import org.chromium.sync.notifier.InvalidationIntentProtocol;
+import org.chromium.sync.notifier.InvalidationPreferences;
+
+/**
+ * Wrapper for invalidations::InvalidationServiceAndroid.
+ *
+ * Serves as the bridge between Java and C++ for the invalidations component.
+ */
+@JNINamespace("invalidation")
+public class InvalidationService {
+ private static final String TAG = "InvalidationService";
+
+ private final Context mContext;
+
+ private final long mNativeInvalidationServiceAndroid;
+
+ private InvalidationService(Context context, long nativeInvalidationServiceAndroid) {
+ mContext = Preconditions.checkNotNull(context.getApplicationContext());
+ mNativeInvalidationServiceAndroid = nativeInvalidationServiceAndroid;
+ }
+
+ public void requestSyncFromNativeChrome(
+ int objectSource, String objectId, long version, String payload) {
+ ThreadUtils.assertOnUiThread();
+ nativeRequestSync(
+ mNativeInvalidationServiceAndroid, objectSource, objectId, version, payload);
+ }
+
+ public void requestSyncFromNativeChromeForAllTypes() {
+ ThreadUtils.assertOnUiThread();
+ nativeRequestSyncForAllTypes(mNativeInvalidationServiceAndroid);
+ }
+
+ /**
+ * Nudge the syncer to start a new sync cycle.
+ */
+ @VisibleForTesting
+ public void requestSyncCycleForTest() {
nyquist 2014/09/04 09:01:56 Why is this needed? Couldn't you just call request
maxbogue 2014/09/05 16:42:46 Done.
+ requestSyncFromNativeChromeForAllTypes();
+ }
+
+ @CalledByNative
+ private static InvalidationService create(
+ Context context, long nativeInvalidationServiceAndroid) {
+ ThreadUtils.assertOnUiThread();
+ return new InvalidationService(context, nativeInvalidationServiceAndroid);
+ }
+
+ /**
+ * 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) {
nyquist 2014/09/04 09:01:56 Does this method and the one below need to be publ
maxbogue 2014/09/05 16:42:46 Done.
+ InvalidationPreferences invalidationPreferences = new InvalidationPreferences(mContext);
+ Account account = invalidationPreferences.getSavedSyncedAccount();
+ Intent registerIntent =
+ InvalidationIntentProtocol.createRegisterIntent(
+ account, objectSources, objectNames);
+ registerIntent.setClass(mContext, InvalidationClientService.class);
+ mContext.startService(registerIntent);
+ }
+
+ /**
+ * Fetches the Invalidator client name.
+ *
+ * Note that there is a naming discrepancy here. In C++, we refer to the invalidation client
+ * identifier that is unique for every invalidation client instance in an account as the client
+ * ID. In Java, we call it the client name.
+ */
+ @CalledByNative
+ public byte[] getInvalidatorClientId() {
+ return InvalidationClientNameProvider.get().getInvalidatorClientName();
+ }
+
+ private native void nativeRequestSync(long nativeInvalidationServiceAndroid,
+ int objectSource, String objectId, long version, String payload);
+ private native void nativeRequestSyncForAllTypes(long nativeInvalidationServiceAndroid);
+}

Powered by Google App Engine
This is Rietveld 408576698