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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/NTPSnippetsBridge.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: Cleaning up 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/NTPSnippetsBridge.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/NTPSnippetsBridge.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/NTPSnippetsBridge.java
new file mode 100644
index 0000000000000000000000000000000000000000..73314b4aeac7ebc9e6a928dac5b4d6789ebf4334
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/NTPSnippetsBridge.java
@@ -0,0 +1,61 @@
+// 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.base.annotations.JNINamespace;
+import org.chromium.chrome.browser.profiles.Profile;
+
+/**
+ * Provides access to the snippets to display on the NTP using the C++ NTP Snippets Service
+ */
+@JNINamespace("ntp_snippets")
+public class NTPSnippetsBridge {
Bernhard Bauer 2016/02/08 18:19:26 Nit: I think Java code is a bit stricter about usa
Marc Treib 2016/02/09 09:17:54 I'd just remove the "NTP". The SnippetsController
May 2016/02/09 17:38:52 Done.
May 2016/02/09 17:38:52 Done.
+ private static final String TAG = "NTPSnippetsBridge";
+
+ private long mNativeSnippetsBridge;
+
+ /**
+ * An observer for notifying when new snippets are loaded
+ */
+ @JNINamespace("ntp_snippets")
+ public interface SnippetsObserver {
+ @CalledByNative("SnippetsObserver")
+ public void onSnippetAvailable(
Marc Treib 2016/02/09 09:17:54 nit: onSnippet*s*Available
May 2016/02/09 17:38:52 Done.
+ String[] titles, String[] urls, String[] thumbnailUrls, String[] snippets);
+ }
+
+ /**
+ * Creates an NTPSnippetsBridge for getting snippet data for the current user
+ *
+ * @param profile Profile of the user that we will retrieve snippets for.
+ */
+ public NTPSnippetsBridge(Profile profile) {
+ mNativeSnippetsBridge = nativeInit(profile);
+ }
+
+ void destroy() {
+ assert mNativeSnippetsBridge != 0;
+ mNativeSnippetsBridge = 0;
+ }
+
+ void setObserver(final SnippetsObserver snippetsObserver) {
+ SnippetsObserver wrappedObserver = new SnippetsObserver() {
+ @Override
+ public void onSnippetAvailable(
+ String[] titles, String[] urls, String[] thumbnailUrls, String[] snippets) {
+ // Don't notify observer if we've already been destroyed.
+ if (mNativeSnippetsBridge != 0) {
+ snippetsObserver.onSnippetAvailable(titles, urls, thumbnailUrls, snippets);
+ }
+ }
+ };
+ nativeSetSnippetsObserver(mNativeSnippetsBridge, wrappedObserver);
+ }
+
+ private native long nativeInit(Profile profile);
+ private native void nativeSetSnippetsObserver(
+ long nativeNTPSnippetsBridge, SnippetsObserver observer);
+}

Powered by Google App Engine
This is Rietveld 408576698