Commit 164c7fa5 authored by Eric Stevenson's avatar Eric Stevenson Committed by Commit Bot

JNI refactor: @NativeMethods conversion (//chrome/android/feed).

This CL was generated by
//base/android/jni_generator/jni_refactorer.py.

Bug: 929661
Change-Id: I8da45e352eb54662a5debedbfb394fd7687ac1f1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1808552
Commit-Queue: Sky Malice <skym@chromium.org>
Auto-Submit: Eric Stevenson <estevenson@chromium.org>
Reviewed-by: default avatarSky Malice <skym@chromium.org>
Cr-Commit-Position: refs/heads/master@{#697290}
parent 6de8ef17
...@@ -15,6 +15,7 @@ import org.chromium.base.Callback; ...@@ -15,6 +15,7 @@ import org.chromium.base.Callback;
import org.chromium.base.VisibleForTesting; import org.chromium.base.VisibleForTesting;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.profiles.Profile;
import java.util.HashMap; import java.util.HashMap;
...@@ -35,7 +36,7 @@ public class FeedContentBridge { ...@@ -35,7 +36,7 @@ public class FeedContentBridge {
* @param profile {@link Profile} of the user we are rendering the Feed for. * @param profile {@link Profile} of the user we are rendering the Feed for.
*/ */
public FeedContentBridge(Profile profile) { public FeedContentBridge(Profile profile) {
mNativeFeedContentBridge = nativeInit(profile); mNativeFeedContentBridge = FeedContentBridgeJni.get().init(FeedContentBridge.this, profile);
} }
/** /**
...@@ -48,7 +49,7 @@ public class FeedContentBridge { ...@@ -48,7 +49,7 @@ public class FeedContentBridge {
/** Cleans up native half of this bridge. */ /** Cleans up native half of this bridge. */
public void destroy() { public void destroy() {
assert mNativeFeedContentBridge != 0; assert mNativeFeedContentBridge != 0;
nativeDestroy(mNativeFeedContentBridge); FeedContentBridgeJni.get().destroy(mNativeFeedContentBridge, FeedContentBridge.this);
mNativeFeedContentBridge = 0; mNativeFeedContentBridge = 0;
} }
...@@ -56,54 +57,62 @@ public class FeedContentBridge { ...@@ -56,54 +57,62 @@ public class FeedContentBridge {
Callback<Void> failureCallback) { Callback<Void> failureCallback) {
assert mNativeFeedContentBridge != 0; assert mNativeFeedContentBridge != 0;
String[] keysArray = keys.toArray(new String[keys.size()]); String[] keysArray = keys.toArray(new String[keys.size()]);
nativeLoadContent(mNativeFeedContentBridge, keysArray, successCallback, failureCallback); FeedContentBridgeJni.get().loadContent(mNativeFeedContentBridge, FeedContentBridge.this,
keysArray, successCallback, failureCallback);
} }
public void loadContentByPrefix(String prefix, Callback<Map<String, byte[]>> successCallback, public void loadContentByPrefix(String prefix, Callback<Map<String, byte[]>> successCallback,
Callback<Void> failureCallback) { Callback<Void> failureCallback) {
assert mNativeFeedContentBridge != 0; assert mNativeFeedContentBridge != 0;
nativeLoadContentByPrefix( FeedContentBridgeJni.get().loadContentByPrefix(mNativeFeedContentBridge,
mNativeFeedContentBridge, prefix, successCallback, failureCallback); FeedContentBridge.this, prefix, successCallback, failureCallback);
} }
public void loadAllContentKeys( public void loadAllContentKeys(
Callback<String[]> successCallback, Callback<Void> failureCallback) { Callback<String[]> successCallback, Callback<Void> failureCallback) {
assert mNativeFeedContentBridge != 0; assert mNativeFeedContentBridge != 0;
nativeLoadAllContentKeys(mNativeFeedContentBridge, successCallback, failureCallback); FeedContentBridgeJni.get().loadAllContentKeys(
mNativeFeedContentBridge, FeedContentBridge.this, successCallback, failureCallback);
} }
public void commitContentMutation(ContentMutation contentMutation, Callback<Boolean> callback) { public void commitContentMutation(ContentMutation contentMutation, Callback<Boolean> callback) {
assert mNativeFeedContentBridge != 0; assert mNativeFeedContentBridge != 0;
nativeCreateContentMutation(mNativeFeedContentBridge); FeedContentBridgeJni.get().createContentMutation(
mNativeFeedContentBridge, FeedContentBridge.this);
for (ContentOperation operation : contentMutation.getOperations()) { for (ContentOperation operation : contentMutation.getOperations()) {
switch (operation.getType()) { switch (operation.getType()) {
case Type.UPSERT: case Type.UPSERT:
Upsert upsert = (Upsert) operation; Upsert upsert = (Upsert) operation;
nativeAppendUpsertOperation( FeedContentBridgeJni.get().appendUpsertOperation(mNativeFeedContentBridge,
mNativeFeedContentBridge, upsert.getKey(), upsert.getValue()); FeedContentBridge.this, upsert.getKey(), upsert.getValue());
break; break;
case Type.DELETE: case Type.DELETE:
Delete delete = (Delete) operation; Delete delete = (Delete) operation;
nativeAppendDeleteOperation(mNativeFeedContentBridge, delete.getKey()); FeedContentBridgeJni.get().appendDeleteOperation(
mNativeFeedContentBridge, FeedContentBridge.this, delete.getKey());
break; break;
case Type.DELETE_BY_PREFIX: case Type.DELETE_BY_PREFIX:
DeleteByPrefix deleteByPrefix = (DeleteByPrefix) operation; DeleteByPrefix deleteByPrefix = (DeleteByPrefix) operation;
nativeAppendDeleteByPrefixOperation( FeedContentBridgeJni.get().appendDeleteByPrefixOperation(
mNativeFeedContentBridge, deleteByPrefix.getPrefix()); mNativeFeedContentBridge, FeedContentBridge.this,
deleteByPrefix.getPrefix());
break; break;
case Type.DELETE_ALL: case Type.DELETE_ALL:
nativeAppendDeleteAllOperation(mNativeFeedContentBridge); FeedContentBridgeJni.get().appendDeleteAllOperation(
mNativeFeedContentBridge, FeedContentBridge.this);
break; break;
default: default:
// Operation type is not supported, therefore failing immediately. // Operation type is not supported, therefore failing immediately.
assert false : "Unsupported type of operation."; assert false : "Unsupported type of operation.";
nativeDeleteContentMutation(mNativeFeedContentBridge); FeedContentBridgeJni.get().deleteContentMutation(
mNativeFeedContentBridge, FeedContentBridge.this);
callback.onResult(false); callback.onResult(false);
return; return;
} }
} }
nativeCommitContentMutation(mNativeFeedContentBridge, callback); FeedContentBridgeJni.get().commitContentMutation(
mNativeFeedContentBridge, FeedContentBridge.this, callback);
} }
@CalledByNative @CalledByNative
...@@ -116,22 +125,27 @@ public class FeedContentBridge { ...@@ -116,22 +125,27 @@ public class FeedContentBridge {
return valueMap; return valueMap;
} }
private native long nativeInit(Profile profile); @NativeMethods
private native void nativeDestroy(long nativeFeedContentBridge); interface Natives {
private native void nativeLoadContent(long nativeFeedContentBridge, String[] keys, long init(FeedContentBridge caller, Profile profile);
Callback<Map<String, byte[]>> successCallback, Callback<Void> failureCallback); void destroy(long nativeFeedContentBridge, FeedContentBridge caller);
private native void nativeLoadContentByPrefix(long nativeFeedContentBridge, String prefix, void loadContent(long nativeFeedContentBridge, FeedContentBridge caller, String[] keys,
Callback<Map<String, byte[]>> successCallback, Callback<Void> failureCallback); Callback<Map<String, byte[]>> successCallback, Callback<Void> failureCallback);
private native void nativeLoadAllContentKeys(long nativeFeedContentBridge, void loadContentByPrefix(long nativeFeedContentBridge, FeedContentBridge caller,
Callback<String[]> successCallback, Callback<Void> failureCallback); String prefix, Callback<Map<String, byte[]>> successCallback,
private native void nativeCommitContentMutation( Callback<Void> failureCallback);
long nativeFeedContentBridge, Callback<Boolean> callback); void loadAllContentKeys(long nativeFeedContentBridge, FeedContentBridge caller,
private native void nativeCreateContentMutation(long nativeFeedContentBridge); Callback<String[]> successCallback, Callback<Void> failureCallback);
private native void nativeDeleteContentMutation(long nativeFeedContentBridge); void commitContentMutation(
private native void nativeAppendDeleteOperation(long nativeFeedContentBridge, String key); long nativeFeedContentBridge, FeedContentBridge caller, Callback<Boolean> callback);
private native void nativeAppendDeleteByPrefixOperation( void createContentMutation(long nativeFeedContentBridge, FeedContentBridge caller);
long nativeFeedContentBridge, String prefix); void deleteContentMutation(long nativeFeedContentBridge, FeedContentBridge caller);
private native void nativeAppendUpsertOperation( void appendDeleteOperation(
long nativeFeedContentBridge, String key, byte[] data); long nativeFeedContentBridge, FeedContentBridge caller, String key);
private native void nativeAppendDeleteAllOperation(long nativeFeedContentBridge); void appendDeleteByPrefixOperation(
long nativeFeedContentBridge, FeedContentBridge caller, String prefix);
void appendUpsertOperation(
long nativeFeedContentBridge, FeedContentBridge caller, String key, byte[] data);
void appendDeleteAllOperation(long nativeFeedContentBridge, FeedContentBridge caller);
}
} }
...@@ -13,6 +13,7 @@ import com.google.android.libraries.feed.api.host.storage.JournalOperation.Type; ...@@ -13,6 +13,7 @@ import com.google.android.libraries.feed.api.host.storage.JournalOperation.Type;
import org.chromium.base.Callback; import org.chromium.base.Callback;
import org.chromium.base.VisibleForTesting; import org.chromium.base.VisibleForTesting;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.profiles.Profile;
/** /**
...@@ -30,7 +31,7 @@ public class FeedJournalBridge { ...@@ -30,7 +31,7 @@ public class FeedJournalBridge {
*/ */
public FeedJournalBridge(Profile profile) { public FeedJournalBridge(Profile profile) {
mNativeFeedJournalBridge = nativeInit(profile); mNativeFeedJournalBridge = FeedJournalBridgeJni.get().init(FeedJournalBridge.this, profile);
} }
/** /**
...@@ -42,7 +43,7 @@ public class FeedJournalBridge { ...@@ -42,7 +43,7 @@ public class FeedJournalBridge {
/** Cleans up native half of this bridge. */ /** Cleans up native half of this bridge. */
public void destroy() { public void destroy() {
assert mNativeFeedJournalBridge != 0; assert mNativeFeedJournalBridge != 0;
nativeDestroy(mNativeFeedJournalBridge); FeedJournalBridgeJni.get().destroy(mNativeFeedJournalBridge, FeedJournalBridge.this);
mNativeFeedJournalBridge = 0; mNativeFeedJournalBridge = 0;
} }
...@@ -50,7 +51,8 @@ public class FeedJournalBridge { ...@@ -50,7 +51,8 @@ public class FeedJournalBridge {
public void loadJournal(String journalName, Callback<byte[][]> successCallback, public void loadJournal(String journalName, Callback<byte[][]> successCallback,
Callback<Void> failureCallback) { Callback<Void> failureCallback) {
assert mNativeFeedJournalBridge != 0; assert mNativeFeedJournalBridge != 0;
nativeLoadJournal(mNativeFeedJournalBridge, journalName, successCallback, failureCallback); FeedJournalBridgeJni.get().loadJournal(mNativeFeedJournalBridge, FeedJournalBridge.this,
journalName, successCallback, failureCallback);
} }
/** /**
...@@ -62,68 +64,82 @@ public class FeedJournalBridge { ...@@ -62,68 +64,82 @@ public class FeedJournalBridge {
public void commitJournalMutation(JournalMutation mutation, Callback<Boolean> callback) { public void commitJournalMutation(JournalMutation mutation, Callback<Boolean> callback) {
assert mNativeFeedJournalBridge != 0; assert mNativeFeedJournalBridge != 0;
nativeStartJournalMutation(mNativeFeedJournalBridge, mutation.getJournalName()); FeedJournalBridgeJni.get().startJournalMutation(
mNativeFeedJournalBridge, FeedJournalBridge.this, mutation.getJournalName());
for (JournalOperation operation : mutation.getOperations()) { for (JournalOperation operation : mutation.getOperations()) {
switch (operation.getType()) { switch (operation.getType()) {
case Type.APPEND: case Type.APPEND:
Append append = (Append) operation; Append append = (Append) operation;
nativeAddAppendOperation(mNativeFeedJournalBridge, append.getValue()); FeedJournalBridgeJni.get().addAppendOperation(
mNativeFeedJournalBridge, FeedJournalBridge.this, append.getValue());
break; break;
case Type.COPY: case Type.COPY:
Copy copy = (Copy) operation; Copy copy = (Copy) operation;
nativeAddCopyOperation(mNativeFeedJournalBridge, copy.getToJournalName()); FeedJournalBridgeJni.get().addCopyOperation(mNativeFeedJournalBridge,
FeedJournalBridge.this, copy.getToJournalName());
break; break;
case Type.DELETE: case Type.DELETE:
nativeAddDeleteOperation(mNativeFeedJournalBridge); FeedJournalBridgeJni.get().addDeleteOperation(
mNativeFeedJournalBridge, FeedJournalBridge.this);
break; break;
default: default:
// Operation type is not supported, therefore failing immediately. // Operation type is not supported, therefore failing immediately.
assert false : "Unsupported type of operation."; assert false : "Unsupported type of operation.";
nativeDeleteJournalMutation(mNativeFeedJournalBridge); FeedJournalBridgeJni.get().deleteJournalMutation(
mNativeFeedJournalBridge, FeedJournalBridge.this);
callback.onResult(false); callback.onResult(false);
return; return;
} }
} }
nativeCommitJournalMutation(mNativeFeedJournalBridge, callback); FeedJournalBridgeJni.get().commitJournalMutation(
mNativeFeedJournalBridge, FeedJournalBridge.this, callback);
} }
/** Determines whether a journal exists and asynchronously responds. */ /** Determines whether a journal exists and asynchronously responds. */
public void doesJournalExist( public void doesJournalExist(
String journalName, Callback<Boolean> successCallback, Callback<Void> failureCallback) { String journalName, Callback<Boolean> successCallback, Callback<Void> failureCallback) {
assert mNativeFeedJournalBridge != 0; assert mNativeFeedJournalBridge != 0;
nativeDoesJournalExist( FeedJournalBridgeJni.get().doesJournalExist(mNativeFeedJournalBridge,
mNativeFeedJournalBridge, journalName, successCallback, failureCallback); FeedJournalBridge.this, journalName, successCallback, failureCallback);
} }
/** Asynchronously retrieve a list of all current journals' name. */ /** Asynchronously retrieve a list of all current journals' name. */
public void loadAllJournalKeys( public void loadAllJournalKeys(
Callback<String[]> successCallback, Callback<Void> failureCallback) { Callback<String[]> successCallback, Callback<Void> failureCallback) {
assert mNativeFeedJournalBridge != 0; assert mNativeFeedJournalBridge != 0;
nativeLoadAllJournalKeys(mNativeFeedJournalBridge, successCallback, failureCallback); FeedJournalBridgeJni.get().loadAllJournalKeys(
mNativeFeedJournalBridge, FeedJournalBridge.this, successCallback, failureCallback);
} }
/** Delete all journals. Reports success or failure. */ /** Delete all journals. Reports success or failure. */
public void deleteAllJournals(Callback<Boolean> callback) { public void deleteAllJournals(Callback<Boolean> callback) {
assert mNativeFeedJournalBridge != 0; assert mNativeFeedJournalBridge != 0;
nativeDeleteAllJournals(mNativeFeedJournalBridge, callback); FeedJournalBridgeJni.get().deleteAllJournals(
mNativeFeedJournalBridge, FeedJournalBridge.this, callback);
} }
private native long nativeInit(Profile profile); @NativeMethods
private native void nativeDestroy(long nativeFeedJournalBridge); interface Natives {
private native void nativeLoadJournal(long nativeFeedJournalBridge, String journalName, long init(FeedJournalBridge caller, Profile profile);
Callback<byte[][]> successCallback, Callback<Void> failureCallback); void destroy(long nativeFeedJournalBridge, FeedJournalBridge caller);
private native void nativeCommitJournalMutation( void loadJournal(long nativeFeedJournalBridge, FeedJournalBridge caller, String journalName,
long nativeFeedJournalBridge, Callback<Boolean> callback); Callback<byte[][]> successCallback, Callback<Void> failureCallback);
private native void nativeStartJournalMutation( void commitJournalMutation(
long nativeFeedJournalBridge, String journalName); long nativeFeedJournalBridge, FeedJournalBridge caller, Callback<Boolean> callback);
private native void nativeDeleteJournalMutation(long nativeFeedJournalBridge); void startJournalMutation(
private native void nativeAddAppendOperation(long nativeFeedJournalBridge, byte[] value); long nativeFeedJournalBridge, FeedJournalBridge caller, String journalName);
private native void nativeAddCopyOperation(long nativeFeedJournalBridge, String toJournalName); void deleteJournalMutation(long nativeFeedJournalBridge, FeedJournalBridge caller);
private native void nativeAddDeleteOperation(long nativeFeedJournalBridge); void addAppendOperation(
private native void nativeDoesJournalExist(long nativeFeedJournalBridge, String journalName, long nativeFeedJournalBridge, FeedJournalBridge caller, byte[] value);
Callback<Boolean> successCallback, Callback<Void> failureCallback); void addCopyOperation(
private native void nativeLoadAllJournalKeys(long nativeFeedJournalBridge, long nativeFeedJournalBridge, FeedJournalBridge caller, String toJournalName);
Callback<String[]> successCallback, Callback<Void> failureCallback); void addDeleteOperation(long nativeFeedJournalBridge, FeedJournalBridge caller);
private native void nativeDeleteAllJournals( void doesJournalExist(long nativeFeedJournalBridge, FeedJournalBridge caller,
long nativeFeedJournalBridge, Callback<Boolean> callback); String journalName, Callback<Boolean> successCallback,
Callback<Void> failureCallback);
void loadAllJournalKeys(long nativeFeedJournalBridge, FeedJournalBridge caller,
Callback<String[]> successCallback, Callback<Void> failureCallback);
void deleteAllJournals(
long nativeFeedJournalBridge, FeedJournalBridge caller, Callback<Boolean> callback);
}
} }
...@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.feed; ...@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.feed;
import org.chromium.base.VisibleForTesting; import org.chromium.base.VisibleForTesting;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.profiles.Profile;
/** /**
...@@ -23,7 +24,7 @@ public class FeedLifecycleBridge { ...@@ -23,7 +24,7 @@ public class FeedLifecycleBridge {
* @param profile Profile of the user whose lifecycle events we care about. * @param profile Profile of the user whose lifecycle events we care about.
*/ */
public FeedLifecycleBridge(Profile profile) { public FeedLifecycleBridge(Profile profile) {
mNativeBridge = nativeInit(profile); mNativeBridge = FeedLifecycleBridgeJni.get().init(FeedLifecycleBridge.this, profile);
} }
/* /*
...@@ -31,7 +32,7 @@ public class FeedLifecycleBridge { ...@@ -31,7 +32,7 @@ public class FeedLifecycleBridge {
*/ */
public void destroy() { public void destroy() {
assert mNativeBridge != 0; assert mNativeBridge != 0;
nativeDestroy(mNativeBridge); FeedLifecycleBridgeJni.get().destroy(mNativeBridge, FeedLifecycleBridge.this);
mNativeBridge = 0; mNativeBridge = 0;
} }
...@@ -53,6 +54,9 @@ public class FeedLifecycleBridge { ...@@ -53,6 +54,9 @@ public class FeedLifecycleBridge {
} }
} }
private native long nativeInit(Profile profile); @NativeMethods
private native void nativeDestroy(long nativeFeedLifecycleBridge); interface Natives {
long init(FeedLifecycleBridge caller, Profile profile);
void destroy(long nativeFeedLifecycleBridge, FeedLifecycleBridge caller);
}
} }
\ No newline at end of file
...@@ -12,6 +12,7 @@ import com.google.android.libraries.feed.common.functional.Consumer; ...@@ -12,6 +12,7 @@ import com.google.android.libraries.feed.common.functional.Consumer;
import org.chromium.base.Callback; import org.chromium.base.Callback;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.profiles.Profile;
/** /**
...@@ -28,7 +29,7 @@ public class FeedNetworkBridge implements NetworkClient { ...@@ -28,7 +29,7 @@ public class FeedNetworkBridge implements NetworkClient {
* @param profile Profile of the user we are rendering the Feed for. * @param profile Profile of the user we are rendering the Feed for.
*/ */
public FeedNetworkBridge(Profile profile) { public FeedNetworkBridge(Profile profile) {
mNativeBridge = nativeInit(profile); mNativeBridge = FeedNetworkBridgeJni.get().init(FeedNetworkBridge.this, profile);
} }
/* /*
...@@ -36,7 +37,7 @@ public class FeedNetworkBridge implements NetworkClient { ...@@ -36,7 +37,7 @@ public class FeedNetworkBridge implements NetworkClient {
*/ */
public void destroy() { public void destroy() {
assert mNativeBridge != 0; assert mNativeBridge != 0;
nativeDestroy(mNativeBridge); FeedNetworkBridgeJni.get().destroy(mNativeBridge, FeedNetworkBridge.this);
mNativeBridge = 0; mNativeBridge = 0;
} }
...@@ -45,8 +46,8 @@ public class FeedNetworkBridge implements NetworkClient { ...@@ -45,8 +46,8 @@ public class FeedNetworkBridge implements NetworkClient {
if (mNativeBridge == 0) { if (mNativeBridge == 0) {
responseConsumer.accept(createHttpResponse(500, new byte[0])); responseConsumer.accept(createHttpResponse(500, new byte[0]));
} else { } else {
nativeSendNetworkRequest(mNativeBridge, request.getUri().toString(), FeedNetworkBridgeJni.get().sendNetworkRequest(mNativeBridge, FeedNetworkBridge.this,
request.getMethod(), request.getBody(), request.getUri().toString(), request.getMethod(), request.getBody(),
result -> responseConsumer.accept(result)); result -> responseConsumer.accept(result));
} }
} }
...@@ -57,7 +58,7 @@ public class FeedNetworkBridge implements NetworkClient { ...@@ -57,7 +58,7 @@ public class FeedNetworkBridge implements NetworkClient {
// See https://crbug.com/901414. // See https://crbug.com/901414.
if (mNativeBridge == 0) return; if (mNativeBridge == 0) return;
nativeCancelRequests(mNativeBridge); FeedNetworkBridgeJni.get().cancelRequests(mNativeBridge, FeedNetworkBridge.this);
} }
@CalledByNative @CalledByNative
...@@ -65,9 +66,12 @@ public class FeedNetworkBridge implements NetworkClient { ...@@ -65,9 +66,12 @@ public class FeedNetworkBridge implements NetworkClient {
return new HttpResponse(code, body); return new HttpResponse(code, body);
} }
private native long nativeInit(Profile profile); @NativeMethods
private native void nativeDestroy(long nativeFeedNetworkBridge); interface Natives {
private native void nativeSendNetworkRequest(long nativeFeedNetworkBridge, String url, long init(FeedNetworkBridge caller, Profile profile);
String requestType, byte[] body, Callback<HttpResponse> resultCallback); void destroy(long nativeFeedNetworkBridge, FeedNetworkBridge caller);
private native void nativeCancelRequests(long nativeFeedNetworkBridge); void sendNetworkRequest(long nativeFeedNetworkBridge, FeedNetworkBridge caller, String url,
String requestType, byte[] body, Callback<HttpResponse> resultCallback);
void cancelRequests(long nativeFeedNetworkBridge, FeedNetworkBridge caller);
}
} }
...@@ -13,6 +13,7 @@ import org.chromium.base.Callback; ...@@ -13,6 +13,7 @@ import org.chromium.base.Callback;
import org.chromium.base.VisibleForTesting; import org.chromium.base.VisibleForTesting;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.profiles.Profile;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -42,7 +43,7 @@ public class FeedOfflineBridge implements FeedOfflineIndicator, KnownContent.Lis ...@@ -42,7 +43,7 @@ public class FeedOfflineBridge implements FeedOfflineIndicator, KnownContent.Lis
* @param knownContent Interface to access information about the Feed's articles. * @param knownContent Interface to access information about the Feed's articles.
*/ */
public FeedOfflineBridge(Profile profile, KnownContent knownContent) { public FeedOfflineBridge(Profile profile, KnownContent knownContent) {
mNativeBridge = nativeInit(profile); mNativeBridge = FeedOfflineBridgeJni.get().init(FeedOfflineBridge.this, profile);
mKnownContentApi = knownContent; mKnownContentApi = knownContent;
mKnownContentApi.addListener(this); mKnownContentApi.addListener(this);
} }
...@@ -50,7 +51,7 @@ public class FeedOfflineBridge implements FeedOfflineIndicator, KnownContent.Lis ...@@ -50,7 +51,7 @@ public class FeedOfflineBridge implements FeedOfflineIndicator, KnownContent.Lis
@Override @Override
public void destroy() { public void destroy() {
assert mNativeBridge != 0; assert mNativeBridge != 0;
nativeDestroy(mNativeBridge); FeedOfflineBridgeJni.get().destroy(mNativeBridge, FeedOfflineBridge.this);
mNativeBridge = 0; mNativeBridge = 0;
mKnownContentApi.removeListener(this); mKnownContentApi.removeListener(this);
} }
...@@ -60,7 +61,8 @@ public class FeedOfflineBridge implements FeedOfflineIndicator, KnownContent.Lis ...@@ -60,7 +61,8 @@ public class FeedOfflineBridge implements FeedOfflineIndicator, KnownContent.Lis
if (mNativeBridge == 0) { if (mNativeBridge == 0) {
return 0L; return 0L;
} else { } else {
return (Long) nativeGetOfflineId(mNativeBridge, url); return (Long) FeedOfflineBridgeJni.get().getOfflineId(
mNativeBridge, FeedOfflineBridge.this, url);
} }
} }
...@@ -71,7 +73,8 @@ public class FeedOfflineBridge implements FeedOfflineIndicator, KnownContent.Lis ...@@ -71,7 +73,8 @@ public class FeedOfflineBridge implements FeedOfflineIndicator, KnownContent.Lis
urlListConsumer.accept(Collections.emptyList()); urlListConsumer.accept(Collections.emptyList());
} else { } else {
String[] urlsArray = urlsToRetrieve.toArray(new String[urlsToRetrieve.size()]); String[] urlsArray = urlsToRetrieve.toArray(new String[urlsToRetrieve.size()]);
nativeGetOfflineStatus(mNativeBridge, urlsArray, FeedOfflineBridgeJni.get().getOfflineStatus(mNativeBridge, FeedOfflineBridge.this,
urlsArray,
(String[] urlsAsArray) -> urlListConsumer.accept(Arrays.asList(urlsAsArray))); (String[] urlsAsArray) -> urlListConsumer.accept(Arrays.asList(urlsAsArray)));
} }
} }
...@@ -88,7 +91,7 @@ public class FeedOfflineBridge implements FeedOfflineIndicator, KnownContent.Lis ...@@ -88,7 +91,7 @@ public class FeedOfflineBridge implements FeedOfflineIndicator, KnownContent.Lis
if (mNativeBridge != 0) { if (mNativeBridge != 0) {
mListeners.remove(offlineStatusListener); mListeners.remove(offlineStatusListener);
if (mListeners.isEmpty()) { if (mListeners.isEmpty()) {
nativeOnNoListeners(mNativeBridge); FeedOfflineBridgeJni.get().onNoListeners(mNativeBridge, FeedOfflineBridge.this);
} }
} }
} }
...@@ -98,7 +101,7 @@ public class FeedOfflineBridge implements FeedOfflineIndicator, KnownContent.Lis ...@@ -98,7 +101,7 @@ public class FeedOfflineBridge implements FeedOfflineIndicator, KnownContent.Lis
if (mNativeBridge != 0) { if (mNativeBridge != 0) {
List<String> userDrivenRemovals = takeUserDriveRemovalsOnly(contentRemoved); List<String> userDrivenRemovals = takeUserDriveRemovalsOnly(contentRemoved);
if (!userDrivenRemovals.isEmpty()) { if (!userDrivenRemovals.isEmpty()) {
nativeOnContentRemoved(mNativeBridge, FeedOfflineBridgeJni.get().onContentRemoved(mNativeBridge, FeedOfflineBridge.this,
userDrivenRemovals.toArray(new String[userDrivenRemovals.size()])); userDrivenRemovals.toArray(new String[userDrivenRemovals.size()]));
} }
} }
...@@ -107,7 +110,7 @@ public class FeedOfflineBridge implements FeedOfflineIndicator, KnownContent.Lis ...@@ -107,7 +110,7 @@ public class FeedOfflineBridge implements FeedOfflineIndicator, KnownContent.Lis
@Override @Override
public void onNewContentReceived(boolean isNewRefresh, long contentCreationDateTimeMs) { public void onNewContentReceived(boolean isNewRefresh, long contentCreationDateTimeMs) {
if (mNativeBridge != 0) { if (mNativeBridge != 0) {
nativeOnNewContentReceived(mNativeBridge); FeedOfflineBridgeJni.get().onNewContentReceived(mNativeBridge, FeedOfflineBridge.this);
} }
} }
...@@ -141,11 +144,12 @@ public class FeedOfflineBridge implements FeedOfflineIndicator, KnownContent.Lis ...@@ -141,11 +144,12 @@ public class FeedOfflineBridge implements FeedOfflineIndicator, KnownContent.Lis
for (ContentMetadata metadata : metadataList) { for (ContentMetadata metadata : metadataList) {
long time_published_ms = TimeUnit.SECONDS.toMillis(metadata.getTimePublished()); long time_published_ms = TimeUnit.SECONDS.toMillis(metadata.getTimePublished());
nativeAppendContentMetadata(mNativeBridge, metadata.getUrl(), metadata.getTitle(), FeedOfflineBridgeJni.get().appendContentMetadata(mNativeBridge,
FeedOfflineBridge.this, metadata.getUrl(), metadata.getTitle(),
time_published_ms, metadata.getImageUrl(), metadata.getPublisher(), time_published_ms, metadata.getImageUrl(), metadata.getPublisher(),
metadata.getFaviconUrl(), metadata.getSnippet()); metadata.getFaviconUrl(), metadata.getSnippet());
} }
nativeOnGetKnownContentDone(mNativeBridge); FeedOfflineBridgeJni.get().onGetKnownContentDone(mNativeBridge, FeedOfflineBridge.this);
}); });
} }
...@@ -156,16 +160,20 @@ public class FeedOfflineBridge implements FeedOfflineIndicator, KnownContent.Lis ...@@ -156,16 +160,20 @@ public class FeedOfflineBridge implements FeedOfflineIndicator, KnownContent.Lis
} }
} }
private native long nativeInit(Profile profile); @NativeMethods
private native void nativeDestroy(long nativeFeedOfflineBridge); interface Natives {
private native Object nativeGetOfflineId(long nativeFeedOfflineBridge, String url); long init(FeedOfflineBridge caller, Profile profile);
private native void nativeGetOfflineStatus(long nativeFeedOfflineBridge, void destroy(long nativeFeedOfflineBridge, FeedOfflineBridge caller);
String[] urlsToRetrieve, Callback<String[]> urlListConsumer); Object getOfflineId(long nativeFeedOfflineBridge, FeedOfflineBridge caller, String url);
private native void nativeOnContentRemoved(long nativeFeedOfflineBridge, String[] urlsRemoved); void getOfflineStatus(long nativeFeedOfflineBridge, FeedOfflineBridge caller,
private native void nativeOnNewContentReceived(long nativeFeedOfflineBridge); String[] urlsToRetrieve, Callback<String[]> urlListConsumer);
private native void nativeOnNoListeners(long nativeFeedOfflineBridge); void onContentRemoved(
private native void nativeAppendContentMetadata(long nativeFeedOfflineBridge, String url, long nativeFeedOfflineBridge, FeedOfflineBridge caller, String[] urlsRemoved);
String title, long timePublishedMs, String imageUrl, String publisher, void onNewContentReceived(long nativeFeedOfflineBridge, FeedOfflineBridge caller);
String faviconUrl, String snippet); void onNoListeners(long nativeFeedOfflineBridge, FeedOfflineBridge caller);
private native void nativeOnGetKnownContentDone(long nativeFeedOfflineBridge); void appendContentMetadata(long nativeFeedOfflineBridge, FeedOfflineBridge caller,
String url, String title, long timePublishedMs, String imageUrl, String publisher,
String faviconUrl, String snippet);
void onGetKnownContentDone(long nativeFeedOfflineBridge, FeedOfflineBridge caller);
}
} }
...@@ -11,6 +11,7 @@ import com.google.android.libraries.feed.api.host.scheduler.SchedulerApi; ...@@ -11,6 +11,7 @@ import com.google.android.libraries.feed.api.host.scheduler.SchedulerApi;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.components.feed.NativeRequestBehavior; import org.chromium.components.feed.NativeRequestBehavior;
...@@ -28,13 +29,13 @@ public class FeedSchedulerBridge implements FeedScheduler { ...@@ -28,13 +29,13 @@ public class FeedSchedulerBridge implements FeedScheduler {
* @param profile Profile of the user we are rendering the Feed for. * @param profile Profile of the user we are rendering the Feed for.
*/ */
public FeedSchedulerBridge(Profile profile) { public FeedSchedulerBridge(Profile profile) {
mNativeBridge = nativeInit(profile); mNativeBridge = FeedSchedulerBridgeJni.get().init(FeedSchedulerBridge.this, profile);
} }
@Override @Override
public void destroy() { public void destroy() {
assert mNativeBridge != 0; assert mNativeBridge != 0;
nativeDestroy(mNativeBridge); FeedSchedulerBridgeJni.get().destroy(mNativeBridge, FeedSchedulerBridge.this);
mNativeBridge = 0; mNativeBridge = 0;
} }
...@@ -56,7 +57,8 @@ public class FeedSchedulerBridge implements FeedScheduler { ...@@ -56,7 +57,8 @@ public class FeedSchedulerBridge implements FeedScheduler {
if (mNativeBridge == 0) return SchedulerApi.RequestBehavior.UNKNOWN; if (mNativeBridge == 0) return SchedulerApi.RequestBehavior.UNKNOWN;
@NativeRequestBehavior @NativeRequestBehavior
int nativeBehavior = nativeShouldSessionRequestData(mNativeBridge, sessionState.hasContent, int nativeBehavior = FeedSchedulerBridgeJni.get().shouldSessionRequestData(mNativeBridge,
FeedSchedulerBridge.this, sessionState.hasContent,
sessionState.contentCreationDateTimeMs, sessionState.hasOutstandingRequest); sessionState.contentCreationDateTimeMs, sessionState.hasOutstandingRequest);
// If this breaks, it is because SchedulerApi.RequestBehavior and the NativeRequestBehavior // If this breaks, it is because SchedulerApi.RequestBehavior and the NativeRequestBehavior
// defined in feed_scheduler_host.h have diverged. If this happens during a feed DEPS roll, // defined in feed_scheduler_host.h have diverged. If this happens during a feed DEPS roll,
...@@ -84,39 +86,43 @@ public class FeedSchedulerBridge implements FeedScheduler { ...@@ -84,39 +86,43 @@ public class FeedSchedulerBridge implements FeedScheduler {
@Override @Override
public void onReceiveNewContent(long contentCreationDateTimeMs) { public void onReceiveNewContent(long contentCreationDateTimeMs) {
if (mNativeBridge != 0) { if (mNativeBridge != 0) {
nativeOnReceiveNewContent(mNativeBridge, contentCreationDateTimeMs); FeedSchedulerBridgeJni.get().onReceiveNewContent(
mNativeBridge, FeedSchedulerBridge.this, contentCreationDateTimeMs);
} }
} }
@Override @Override
public void onRequestError(int networkResponseCode) { public void onRequestError(int networkResponseCode) {
if (mNativeBridge != 0) { if (mNativeBridge != 0) {
nativeOnRequestError(mNativeBridge, networkResponseCode); FeedSchedulerBridgeJni.get().onRequestError(
mNativeBridge, FeedSchedulerBridge.this, networkResponseCode);
} }
} }
@Override @Override
public void onForegrounded() { public void onForegrounded() {
assert mNativeBridge != 0; assert mNativeBridge != 0;
nativeOnForegrounded(mNativeBridge); FeedSchedulerBridgeJni.get().onForegrounded(mNativeBridge, FeedSchedulerBridge.this);
} }
@Override @Override
public void onFixedTimer(Runnable onCompletion) { public void onFixedTimer(Runnable onCompletion) {
assert mNativeBridge != 0; assert mNativeBridge != 0;
nativeOnFixedTimer(mNativeBridge, onCompletion); FeedSchedulerBridgeJni.get().onFixedTimer(
mNativeBridge, FeedSchedulerBridge.this, onCompletion);
} }
@Override @Override
public void onSuggestionConsumed() { public void onSuggestionConsumed() {
assert mNativeBridge != 0; assert mNativeBridge != 0;
nativeOnSuggestionConsumed(mNativeBridge); FeedSchedulerBridgeJni.get().onSuggestionConsumed(mNativeBridge, FeedSchedulerBridge.this);
} }
@Override @Override
public boolean onArticlesCleared(boolean suppressRefreshes) { public boolean onArticlesCleared(boolean suppressRefreshes) {
assert mNativeBridge != 0; assert mNativeBridge != 0;
return nativeOnArticlesCleared(mNativeBridge, suppressRefreshes); return FeedSchedulerBridgeJni.get().onArticlesCleared(
mNativeBridge, FeedSchedulerBridge.this, suppressRefreshes);
} }
@CalledByNative @CalledByNative
...@@ -138,17 +144,21 @@ public class FeedSchedulerBridge implements FeedScheduler { ...@@ -138,17 +144,21 @@ public class FeedSchedulerBridge implements FeedScheduler {
FeedRefreshTask.cancelWakeUp(); FeedRefreshTask.cancelWakeUp();
} }
private native long nativeInit(Profile profile); @NativeMethods
private native void nativeDestroy(long nativeFeedSchedulerBridge); interface Natives {
private native int nativeShouldSessionRequestData(long nativeFeedSchedulerBridge, long init(FeedSchedulerBridge caller, Profile profile);
boolean hasContent, long contentCreationDateTimeMs, boolean hasOutstandingRequest); void destroy(long nativeFeedSchedulerBridge, FeedSchedulerBridge caller);
private native void nativeOnReceiveNewContent( int shouldSessionRequestData(long nativeFeedSchedulerBridge, FeedSchedulerBridge caller,
long nativeFeedSchedulerBridge, long contentCreationDateTimeMs); boolean hasContent, long contentCreationDateTimeMs, boolean hasOutstandingRequest);
private native void nativeOnRequestError( void onReceiveNewContent(long nativeFeedSchedulerBridge, FeedSchedulerBridge caller,
long nativeFeedSchedulerBridge, int networkResponseCode); long contentCreationDateTimeMs);
private native void nativeOnForegrounded(long nativeFeedSchedulerBridge); void onRequestError(long nativeFeedSchedulerBridge, FeedSchedulerBridge caller,
private native void nativeOnFixedTimer(long nativeFeedSchedulerBridge, Runnable onCompletion); int networkResponseCode);
private native void nativeOnSuggestionConsumed(long nativeFeedSchedulerBridge); void onForegrounded(long nativeFeedSchedulerBridge, FeedSchedulerBridge caller);
private native boolean nativeOnArticlesCleared( void onFixedTimer(
long nativeFeedSchedulerBridge, boolean suppressRefreshes); long nativeFeedSchedulerBridge, FeedSchedulerBridge caller, Runnable onCompletion);
void onSuggestionConsumed(long nativeFeedSchedulerBridge, FeedSchedulerBridge caller);
boolean onArticlesCleared(long nativeFeedSchedulerBridge, FeedSchedulerBridge caller,
boolean suppressRefreshes);
}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment