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