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