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

Unified Diff: chrome/browser/android/ntp_snippets_launcher.cc

Issue 1699143002: [NTP Snippets] Schedule periodic fetching (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@snippets_feature
Patch Set: fix bots 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/browser/android/ntp_snippets_launcher.cc
diff --git a/chrome/browser/android/ntp_snippets_launcher.cc b/chrome/browser/android/ntp_snippets_launcher.cc
new file mode 100644
index 0000000000000000000000000000000000000000..3b054657a56e84d30fd30c9ff48e5635acbd79b4
--- /dev/null
+++ b/chrome/browser/android/ntp_snippets_launcher.cc
@@ -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.
+
+#include "chrome/browser/android/ntp_snippets_launcher.h"
+
+#include "base/android/context_utils.h"
+#include "content/public/browser/browser_thread.h"
+#include "jni/SnippetsLauncher_jni.h"
+
+using content::BrowserThread;
+
+namespace {
+
+base::LazyInstance<NTPSnippetsLauncher> g_snippets_launcher =
+ LAZY_INSTANCE_INITIALIZER;
+
+} // namespace
+
+// static
+NTPSnippetsLauncher* NTPSnippetsLauncher::Get() {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ return g_snippets_launcher.Pointer();
+}
+
+// static
+bool NTPSnippetsLauncher::Register(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
+
+bool NTPSnippetsLauncher::Schedule(int period_seconds) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+
+ JNIEnv* env = base::android::AttachCurrentThread();
+ return Java_SnippetsLauncher_schedule(
+ env, java_launcher_.obj(), period_seconds);
+}
+
+bool NTPSnippetsLauncher::Unschedule() {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+
+ JNIEnv* env = base::android::AttachCurrentThread();
+ return Java_SnippetsLauncher_unschedule(env, java_launcher_.obj());
+}
+
+NTPSnippetsLauncher::NTPSnippetsLauncher() {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+
+ JNIEnv* env = base::android::AttachCurrentThread();
+ java_launcher_.Reset(Java_SnippetsLauncher_create(
+ env, base::android::GetApplicationContext()));
+}
+
+NTPSnippetsLauncher::~NTPSnippetsLauncher() {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+
+ JNIEnv* env = base::android::AttachCurrentThread();
+ Java_SnippetsLauncher_destroy(env, java_launcher_.obj());
+ java_launcher_.Reset();
+}
« no previous file with comments | « chrome/browser/android/ntp_snippets_launcher.h ('k') | chrome/browser/ntp_snippets/ntp_snippets_service_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698