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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetsController.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/SnippetsController.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetsController.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetsController.java
new file mode 100644
index 0000000000000000000000000000000000000000..1bd61800a51b6f5cef0c49ebabf61088815f8eab
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetsController.java
@@ -0,0 +1,66 @@
+// 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 android.content.Context;
+
+import org.chromium.base.ThreadUtils;
+import org.chromium.base.annotations.JNINamespace;
+import org.chromium.chrome.browser.profiles.Profile;
+import org.chromium.chrome.browser.signin.SigninManager;
+import org.chromium.chrome.browser.signin.SigninManager.SignInStateObserver;
+
+/**
+ * The main controller for calling into the native snippets component to fetch snippets
+ */
+@JNINamespace("ntp_snippets")
+public class SnippetsController implements SignInStateObserver {
+ private static SnippetsController sInstance;
+
+ private long mNativeSnippetsController;
+
+ public SnippetsController(Context applicationContext) {
+ mNativeSnippetsController = nativeInit(Profile.getLastUsedProfile());
+
+ SigninManager.get(applicationContext).addSignInStateObserver(this);
+
+ fetchSnippets(false);
+ }
+
+ /**
+ * Fetches new snippets
+ *
+ * @param overwrite true if an update to the current snippets should be forced, and false if
+ * snippets should be downloaded only if there are no existing ones.
+ */
+ public void fetchSnippets(boolean overwrite) {
+ nativeFetchSnippets(mNativeSnippetsController, overwrite);
+ }
+
+ /**
+ * Retrieve the singleton instance of this class.
+ *
+ * @param context the current context.
+ * @return the singleton instance.
+ */
+ public static SnippetsController get(Context context) {
+ ThreadUtils.assertOnUiThread();
+ if (sInstance == null) {
+ sInstance = new SnippetsController(context.getApplicationContext());
+ }
+ return sInstance;
+ }
+
+ @Override
+ public void onSignedIn() {
+ fetchSnippets(true);
+ }
+
+ @Override
+ public void onSignedOut() {}
+
+ private native long nativeInit(Profile profile);
+ private native void nativeFetchSnippets(long nativeNTPSnippetsController, boolean overwrite);
+}

Powered by Google App Engine
This is Rietveld 408576698