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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetsBridge.java

Issue 1677073002: Fetch snippets from ChromeReader and show them on the NTP (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing comments Created 4 years, 10 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: 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..559ee229420f23321e849695a466a15aeda07c8a
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetsBridge.java
@@ -0,0 +1,60 @@
+// 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);
+ }
+
+ /**
+ * Creates an NTPSnippetsBridge for getting snippet data for the current user
Marc Treib 2016/02/10 10:44:43 nit: -NTP
May 2016/02/10 18:16:46 Done.
+ *
+ * @param profile Profile of the user that we will retrieve snippets for.
+ */
+ public SnippetsBridge(Profile profile) {
+ mNativeSnippetsBridge = nativeInit(profile);
+ }
+
+ void destroy() {
+ assert mNativeSnippetsBridge != 0;
+ nativeDestroy(mNativeSnippetsBridge);
+ mNativeSnippetsBridge = 0;
+ }
+
+ void setObserver(final SnippetsObserver snippetsObserver) {
+ 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) {
+ snippetsObserver.onSnippetsAvailable(titles, urls, thumbnailUrls, snippets);
+ }
+ }
+ };
+ nativeSetSnippetsObserver(mNativeSnippetsBridge, wrappedObserver);
+ }
+
+ private native long nativeInit(Profile profile);
+ private native void nativeSetSnippetsObserver(
+ long nativeNTPSnippetsBridge, SnippetsObserver observer);
+ private native void nativeDestroy(long nativeNTPSnippetsBridge);
+}

Powered by Google App Engine
This is Rietveld 408576698