| 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);
|
|
|