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

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..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);
+}

Powered by Google App Engine
This is Rietveld 408576698