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..2254485ca6208dedd7e76477730b4db955b0340c |
--- /dev/null |
+++ b/chrome/browser/android/ntp_snippets_controller.cc |
@@ -0,0 +1,46 @@ |
+// 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 "jni/SnippetsController_jni.h" |
+ |
+namespace ntp_snippets { |
+static jlong Init(JNIEnv* env, |
+ const JavaParamRef<jobject>& obj, |
+ const JavaParamRef<jobject>& j_profile) { |
+ NTPSnippetsController* snippets_bridge = new NTPSnippetsController(j_profile); |
+ return reinterpret_cast<intptr_t>(snippets_bridge); |
+} |
+ |
+NTPSnippetsController::NTPSnippetsController(jobject j_profile) { |
+ Profile* profile = ProfileAndroid::FromProfileAndroid(j_profile); |
+ if (profile) { |
Bernhard Bauer
2016/02/08 18:19:26
Nit: no braces.
May
2016/02/09 17:38:53
Done.
|
+ ntp_snippets_service_ = NTPSnippetsServiceFactory::GetForProfile(profile); |
+ } |
+} |
+ |
+void NTPSnippetsController::Destroy(JNIEnv* env, |
+ const JavaParamRef<jobject>& obj) { |
+ delete this; |
+} |
+ |
+void NTPSnippetsController::FetchSnippets(JNIEnv* env, |
Bernhard Bauer
2016/02/08 18:19:26
You could make this a static method that just take
May
2016/02/09 17:38:53
Made it static. Later (depending on how we impleme
|
+ const JavaParamRef<jobject>& obj, |
+ jboolean overwrite) { |
+ ntp_snippets_service_->FetchSnippets(overwrite); |
+} |
+ |
+// static |
+bool RegisterNTPSnippetsController(JNIEnv* env) { |
+ return RegisterNativesImpl(env); |
+} |
+} // namespace ntp_snippets |