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

Unified Diff: base/android/scoped_java_ref.h

Issue 1312153003: jni_generator: Pass object parameters as JavaParamRef. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 3 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
« no previous file with comments | « base/android/record_user_action.cc ('k') | base/android/trace_event_binding.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/android/scoped_java_ref.h
diff --git a/base/android/scoped_java_ref.h b/base/android/scoped_java_ref.h
index 37e7fd3507ca480ee29209df24d3e7e2cf2b7472..d6a81fa637f3b1214593f50d0a5d5e6989c42632 100644
--- a/base/android/scoped_java_ref.h
+++ b/base/android/scoped_java_ref.h
@@ -94,6 +94,27 @@ class JavaRef : public JavaRef<jobject> {
DISALLOW_COPY_AND_ASSIGN(JavaRef);
};
+// Holds a local reference to a JNI method parameter.
+// Method parameters should not be deleted, and so this class exists purely to
+// wrap them as a JavaRef<T> in the JNI binding generator. Do not create
+// instances manually.
+template<typename T>
+class JavaParamRef : public JavaRef<T> {
+ public:
+ // Assumes that |obj| is a parameter passed to a JNI method from Java.
+ // Does not assume ownership as parameters should not be deleted.
+ JavaParamRef(JNIEnv* env, T obj) : JavaRef<T>(env, obj) {}
+
+ ~JavaParamRef() {}
+
+ // TODO(torne): remove this cast once we're using JavaRef consistently.
+ // http://crbug.com/506850
+ operator T() const { return JavaRef<T>::obj(); }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(JavaParamRef);
+};
+
// Holds a local reference to a Java object. The local reference is scoped
// to the lifetime of this object.
// Instances of this class may hold onto any JNIEnv passed into it until
@@ -208,6 +229,11 @@ class ScopedJavaGlobalRef : public JavaRef<T> {
}
template<typename U>
+ void Reset(JNIEnv* env, const JavaParamRef<U>& other) {
+ this->Reset(env, other.obj());
+ }
+
+ template<typename U>
void Reset(JNIEnv* env, U obj) {
implicit_cast<T>(obj); // Ensure U is assignable to T
this->SetNewGlobalRef(env, obj);
« no previous file with comments | « base/android/record_user_action.cc ('k') | base/android/trace_event_binding.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698