Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(357)

Unified Diff: base/android/jni_generator/sample_for_tests.cc

Issue 9384011: Chrome on Android: adds jni_generator. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Patch Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/android/jni_generator/sample_for_tests.cc
diff --git a/base/android/jni_generator/sample_for_tests.cc b/base/android/jni_generator/sample_for_tests.cc
new file mode 100644
index 0000000000000000000000000000000000000000..632de5c75c5b4452f371a362f0707f78bebbd7ee
--- /dev/null
+++ b/base/android/jni_generator/sample_for_tests.cc
@@ -0,0 +1,50 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
joth 2012/02/14 00:46:49 2012
bulach 2012/02/14 02:12:32 Done.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
joth 2012/02/14 00:46:49 maybe comment the main purpose of this is to ensur
bulach 2012/02/14 02:12:32 Done.
+#include "base/android/jni_android.h"
+#include "base/android/scoped_java_ref.h"
+
+using base::android::AttachCurrentThread;
+using base::android::ScopedJavaLocalRef;
+
+class CPPClass {
+ public:
+ void Destroy(JNIEnv* env, jobject obj) {
+ delete this;
+ }
+
+ jint Method(JNIEnv* env, jobject obj) {
+ return 0;
+ }
+
+ ScopedJavaLocalRef<jstring> InnerMethod(JNIEnv* env, jobject obj) {
+ return ScopedJavaLocalRef<jstring>();
+ }
+};
+
+namespace cpp_namespace {
+
+class CPPClass {
+ public:
+ jdouble MethodOtherP0(JNIEnv* env, jobject obj) {
+ return 0.0;
+ }
+};
+
+} // namespace cpp_namespace
+
+#include "jni/sample_for_tests_jni.h"
+
+int main() {
+ // On a regular application, you'd call AttachCurrentThread(). This sample is
+ // not yet linking with all the libraries.
+ JNIEnv* env = /* AttachCurrentThread() */ NULL;
+ // This is how you call a java static method from C++.
+ bool foo = Java_SampleForTests_staticJavaMethod(env);
+ // This is how you call a java method from C++. Note that you must have
+ // obtained the jobject somehow.
+ jobject my_java_object = NULL;
+ int bar = Java_SampleForTests_javaMethod(env, my_java_object, 1, 2);
+ return 0;
+}

Powered by Google App Engine
This is Rietveld 408576698