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

Side by Side 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: Joth's comments 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/android/jni_android.h"
6 #include "base/android/scoped_java_ref.h"
7
8 // The main purpose of this is to ensure sample_for_tests_jni.h
9 // compiles and the functions declared in it as expected.
10
11 using base::android::AttachCurrentThread;
12 using base::android::ScopedJavaLocalRef;
13
14 class CPPClass {
15 public:
16 void Destroy(JNIEnv* env, jobject obj) {
17 delete this;
18 }
19
20 jint Method(JNIEnv* env, jobject obj) {
21 return 0;
22 }
23
24 ScopedJavaLocalRef<jstring> InnerMethod(JNIEnv* env, jobject obj) {
25 return ScopedJavaLocalRef<jstring>();
26 }
27 };
28
29 namespace cpp_namespace {
30
31 class CPPClass {
32 public:
33 jdouble MethodOtherP0(JNIEnv* env, jobject obj) {
34 return 0.0;
35 }
36 };
37
38 } // namespace cpp_namespace
39
40 #include "jni/sample_for_tests_jni.h"
41
42 int main() {
43 // On a regular application, you'd call AttachCurrentThread(). This sample is
44 // not yet linking with all the libraries.
45 JNIEnv* env = /* AttachCurrentThread() */ NULL;
46 // This is how you call a java static method from C++.
Mark Mentovai 2012/02/14 20:00:38 For readability, it’s good to put a blank line bef
bulach 2012/02/14 23:18:11 Done.
47 bool foo = Java_SampleForTests_staticJavaMethod(env);
48 // This is how you call a java method from C++. Note that you must have
49 // obtained the jobject somehow.
50 jobject my_java_object = NULL;
51 int bar = Java_SampleForTests_javaMethod(env, my_java_object, 1, 2);
52 return 0;
Mark Mentovai 2012/02/14 20:00:38 And then you’d want a blank line before this one,
bulach 2012/02/14 23:18:11 Done.
53 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698