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

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: Review 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/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..55dd84cddfe5c06bf900d50b78db2903f04fc62e
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetsController.java
@@ -0,0 +1,59 @@
+// 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.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
+ */
+public class SnippetsController implements SignInStateObserver {
+ private static SnippetsController sInstance;
+
+ private long mNativeSnippetsController;
+
+ public SnippetsController(Context applicationContext) {
+ SigninManager.get(applicationContext).addSignInStateObserver(this);
+ }
+
+ /**
+ * 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(Profile.getLastUsedProfile(), 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 void nativeFetchSnippets(Profile profile, boolean overwrite);
+}

Powered by Google App Engine
This is Rietveld 408576698