| Index: chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetsBridge.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetsBridge.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetsBridge.java
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..db0b5ad6a0c7b36af7ea2ecdc65e58d344de0bc0
|
| --- /dev/null
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetsBridge.java
|
| @@ -0,0 +1,54 @@
|
| +// Copyright 2016 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.chrome.browser.ntp.snippets;
|
| +
|
| +import org.chromium.base.annotations.CalledByNative;
|
| +import org.chromium.chrome.browser.profiles.Profile;
|
| +
|
| +/**
|
| + * Provides access to the snippets to display on the NTP using the C++ NTP Snippets Service
|
| + */
|
| +public class SnippetsBridge {
|
| + private static final String TAG = "SnippetsBridge";
|
| +
|
| + private long mNativeSnippetsBridge;
|
| +
|
| + /**
|
| + * An observer for notifying when new snippets are loaded
|
| + */
|
| + public interface SnippetsObserver {
|
| + @CalledByNative("SnippetsObserver")
|
| + public void onSnippetsAvailable(
|
| + String[] titles, String[] urls, String[] thumbnailUrls, String[] previewText);
|
| + }
|
| +
|
| + /**
|
| + * Creates a SnippetsBridge for getting snippet data for the current user
|
| + *
|
| + * @param profile Profile of the user that we will retrieve snippets for.
|
| + */
|
| + public SnippetsBridge(Profile profile, final SnippetsObserver observer) {
|
| + SnippetsObserver wrappedObserver = new SnippetsObserver() {
|
| + @Override
|
| + public void onSnippetsAvailable(
|
| + String[] titles, String[] urls, String[] thumbnailUrls, String[] previewText) {
|
| + // Don't notify observer if we've already been destroyed.
|
| + if (mNativeSnippetsBridge != 0) {
|
| + observer.onSnippetsAvailable(titles, urls, thumbnailUrls, previewText);
|
| + }
|
| + }
|
| + };
|
| + mNativeSnippetsBridge = nativeInit(profile, wrappedObserver);
|
| + }
|
| +
|
| + void destroy() {
|
| + assert mNativeSnippetsBridge != 0;
|
| + nativeDestroy(mNativeSnippetsBridge);
|
| + mNativeSnippetsBridge = 0;
|
| + }
|
| +
|
| + private native long nativeInit(Profile profile, SnippetsObserver observer);
|
| + private native void nativeDestroy(long nativeNTPSnippetsBridge);
|
| +}
|
|
|