Chromium Code Reviews| 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..beb0a1eb01defea941a8ce81c0d5188f8ed0e970 |
| --- /dev/null |
| +++ b/components/invalidation/android/java/src/org/chromium/components/invalidation/InvalidationService.java |
| @@ -0,0 +1,90 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// 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.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"; |
|
nyquist
2014/09/10 18:25:04
I don't think this field is ever used.
maxbogue
2014/09/11 20:08:09
Done.
|
| + |
| + 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); |
| + } |
| + |
| + @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 |
| + private void setRegisteredObjectIds(int[] objectSources, String[] objectNames) { |
|
nyquist
2014/09/10 18:25:04
I now realize that this is used in the Invalidatio
maxbogue
2014/09/11 20:08:09
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 |
| + private 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); |
| +} |