Chromium Code Reviews| 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..1a877a6f0216f9690d84fc7d3dc3af7ebe236499 |
| --- /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[] snippets); |
|
Marc Treib
2016/02/11 09:23:21
Optional nit: "snippets" is overloaded to mean bot
May
2016/02/11 15:25:23
Done.
|
| + } |
| + |
| + /** |
| + * 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[] snippets) { |
| + // Don't notify observer if we've already been destroyed. |
| + if (mNativeSnippetsBridge != 0) { |
| + observer.onSnippetsAvailable(titles, urls, thumbnailUrls, snippets); |
| + } |
| + } |
| + }; |
| + 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); |
| +} |