Chromium Code Reviews| Index: chrome/browser/android/ntp_snippets_controller.cc |
| diff --git a/chrome/browser/android/ntp_snippets_controller.cc b/chrome/browser/android/ntp_snippets_controller.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ae7f5b13e0cde75349448ceaf99414912ed0bd0a |
| --- /dev/null |
| +++ b/chrome/browser/android/ntp_snippets_controller.cc |
| @@ -0,0 +1,44 @@ |
| +// 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_controller.h" |
| + |
| +#include <jni.h> |
| + |
| +#include "base/android/jni_android.h" |
| +#include "base/android/scoped_java_ref.h" |
| +#include "chrome/browser/ntp_snippets/ntp_snippets_service_factory.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/profiles/profile_android.h" |
| +#include "components/ntp_snippets/ntp_snippets_service.h" |
| +#include "jni/SnippetsController_jni.h" |
| + |
| +static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
|
Marc Treib
2016/02/10 10:44:43
Put the functions in an anonymous namespace instea
Bernhard Bauer
2016/02/10 10:48:44
You don't need Init() or Destroy() anymore either
Bernhard Bauer
2016/02/10 10:51:42
That does not work for JNI bridge methods (because
Marc Treib
2016/02/10 10:58:09
Today I learned! Alright, carry on then :)
May
2016/02/10 18:16:47
Done.
|
| + NTPSnippetsController* snippets_bridge = new NTPSnippetsController(); |
| + return reinterpret_cast<intptr_t>(snippets_bridge); |
| +} |
| + |
| +static void FetchSnippets(JNIEnv* env, |
| + const JavaParamRef<jobject>& obj, |
| + const JavaParamRef<jobject>& jprofile, |
| + jboolean overwrite) { |
| + Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile); |
| + if (profile) { |
| + ntp_snippets::NTPSnippetsService* ntp_snippets_service = |
| + NTPSnippetsServiceFactory::GetForProfile(profile); |
| + ntp_snippets_service->FetchSnippets(overwrite); |
| + } |
| +} |
| + |
| +NTPSnippetsController::NTPSnippetsController() {} |
| + |
| +void NTPSnippetsController::Destroy(JNIEnv* env, |
| + const JavaParamRef<jobject>& obj) { |
| + delete this; |
| +} |
| + |
| +// static |
| +bool NTPSnippetsController::RegisterNTPSnippetsController(JNIEnv* env) { |
| + return RegisterNativesImpl(env); |
| +} |