OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/android/ntp_snippets_launcher.h" |
| 6 |
| 7 #include "base/android/context_utils.h" |
| 8 #include "content/public/browser/browser_thread.h" |
| 9 #include "jni/SnippetsLauncher_jni.h" |
| 10 |
| 11 using content::BrowserThread; |
| 12 |
| 13 namespace { |
| 14 |
| 15 base::LazyInstance<NTPSnippetsLauncher> g_snippets_launcher = |
| 16 LAZY_INSTANCE_INITIALIZER; |
| 17 |
| 18 } // namespace |
| 19 |
| 20 // static |
| 21 NTPSnippetsLauncher* NTPSnippetsLauncher::Get() { |
| 22 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 23 return g_snippets_launcher.Pointer(); |
| 24 } |
| 25 |
| 26 // static |
| 27 bool NTPSnippetsLauncher::Register(JNIEnv* env) { |
| 28 return RegisterNativesImpl(env); |
| 29 } |
| 30 |
| 31 bool NTPSnippetsLauncher::Schedule(int period_seconds) { |
| 32 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 33 |
| 34 JNIEnv* env = base::android::AttachCurrentThread(); |
| 35 return Java_SnippetsLauncher_schedule( |
| 36 env, java_launcher_.obj(), period_seconds); |
| 37 } |
| 38 |
| 39 bool NTPSnippetsLauncher::Unschedule() { |
| 40 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 41 |
| 42 JNIEnv* env = base::android::AttachCurrentThread(); |
| 43 return Java_SnippetsLauncher_unschedule(env, java_launcher_.obj()); |
| 44 } |
| 45 |
| 46 NTPSnippetsLauncher::NTPSnippetsLauncher() { |
| 47 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 48 |
| 49 JNIEnv* env = base::android::AttachCurrentThread(); |
| 50 java_launcher_.Reset(Java_SnippetsLauncher_create( |
| 51 env, base::android::GetApplicationContext())); |
| 52 } |
| 53 |
| 54 NTPSnippetsLauncher::~NTPSnippetsLauncher() { |
| 55 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 56 |
| 57 JNIEnv* env = base::android::AttachCurrentThread(); |
| 58 Java_SnippetsLauncher_destroy(env, java_launcher_.obj()); |
| 59 java_launcher_.Reset(); |
| 60 } |
OLD | NEW |