| 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_bridge.h" | 5 #include "chrome/browser/android/ntp/ntp_snippets_bridge.h" |
| 6 | 6 |
| 7 #include <jni.h> | 7 #include <jni.h> |
| 8 | 8 |
| 9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 NTPSnippetsBridge* snippets_bridge = new NTPSnippetsBridge(env, j_profile); | 29 NTPSnippetsBridge* snippets_bridge = new NTPSnippetsBridge(env, j_profile); |
| 30 return reinterpret_cast<intptr_t>(snippets_bridge); | 30 return reinterpret_cast<intptr_t>(snippets_bridge); |
| 31 } | 31 } |
| 32 | 32 |
| 33 static void FetchSnippets(JNIEnv* env, | 33 static void FetchSnippets(JNIEnv* env, |
| 34 const JavaParamRef<jclass>& caller) { | 34 const JavaParamRef<jclass>& caller) { |
| 35 Profile* profile = ProfileManager::GetLastUsedProfile(); | 35 Profile* profile = ProfileManager::GetLastUsedProfile(); |
| 36 NTPSnippetsServiceFactory::GetForProfile(profile)->FetchSnippets(); | 36 NTPSnippetsServiceFactory::GetForProfile(profile)->FetchSnippets(); |
| 37 } | 37 } |
| 38 | 38 |
| 39 // Reschedules the fetching of snippets. Used to support different fetching |
| 40 // intervals for different times of day. |
| 41 static void RescheduleFetching(JNIEnv* env, |
| 42 const JavaParamRef<jclass>& caller) { |
| 43 Profile* profile = ProfileManager::GetLastUsedProfile(); |
| 44 NTPSnippetsServiceFactory::GetForProfile(profile)->RescheduleFetching(); |
| 45 } |
| 46 |
| 39 NTPSnippetsBridge::NTPSnippetsBridge(JNIEnv* env, | 47 NTPSnippetsBridge::NTPSnippetsBridge(JNIEnv* env, |
| 40 const JavaParamRef<jobject>& j_profile) | 48 const JavaParamRef<jobject>& j_profile) |
| 41 : snippet_service_observer_(this) { | 49 : snippet_service_observer_(this) { |
| 42 Profile* profile = ProfileAndroid::FromProfileAndroid(j_profile); | 50 Profile* profile = ProfileAndroid::FromProfileAndroid(j_profile); |
| 43 ntp_snippets_service_ = NTPSnippetsServiceFactory::GetForProfile(profile); | 51 ntp_snippets_service_ = NTPSnippetsServiceFactory::GetForProfile(profile); |
| 44 } | 52 } |
| 45 | 53 |
| 46 void NTPSnippetsBridge::SetObserver(JNIEnv* env, | 54 void NTPSnippetsBridge::SetObserver(JNIEnv* env, |
| 47 const JavaParamRef<jobject>& obj, | 55 const JavaParamRef<jobject>& obj, |
| 48 const JavaParamRef<jobject>& j_observer) { | 56 const JavaParamRef<jobject>& j_observer) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 | 99 |
| 92 void NTPSnippetsBridge::NTPSnippetsServiceShutdown() { | 100 void NTPSnippetsBridge::NTPSnippetsServiceShutdown() { |
| 93 observer_.Reset(); | 101 observer_.Reset(); |
| 94 snippet_service_observer_.Remove(ntp_snippets_service_); | 102 snippet_service_observer_.Remove(ntp_snippets_service_); |
| 95 } | 103 } |
| 96 | 104 |
| 97 // static | 105 // static |
| 98 bool NTPSnippetsBridge::Register(JNIEnv* env) { | 106 bool NTPSnippetsBridge::Register(JNIEnv* env) { |
| 99 return RegisterNativesImpl(env); | 107 return RegisterNativesImpl(env); |
| 100 } | 108 } |
| OLD | NEW |