Chromium Code Reviews| Index: base/android/scoped_java_ref.h |
| diff --git a/base/android/scoped_java_ref.h b/base/android/scoped_java_ref.h |
| index e5339ee59671e3e1bfc60bf7df50adbe304e31ff..579452e21a442967b22ed21768c7c493a8406a08 100644 |
| --- a/base/android/scoped_java_ref.h |
| +++ b/base/android/scoped_java_ref.h |
| @@ -42,6 +42,15 @@ template<typename T> class JavaRef; |
| template<> |
| class BASE_EXPORT JavaRef<jobject> { |
| public: |
| + // ALlow nullptr to be converted to JavaRef. This avoids having to declare an |
|
Yaron
2015/12/02 19:42:10
Allow
|
| + // empty ScopedJavaLocalRef just to pass null to a function with a JavaRef |
| + // parameter, and makes C++ "nullptr" and Java "null" equivalent. |
| + JavaRef(std::nullptr_t) : JavaRef() {} |
| + |
| + // Public to allow destruction of temporary JavaRef objects created by the |
| + // nullptr conversion. Don't add anything else here; it's inlined. |
| + ~JavaRef() {} |
| + |
| jobject obj() const { return obj_; } |
| bool is_null() const { return obj_ == NULL; } |
| @@ -60,9 +69,6 @@ class BASE_EXPORT JavaRef<jobject> { |
| JavaRef(JNIEnv* env, jobject obj) : obj_(obj) {} |
| #endif |
| - // Don't add anything else here; it's inlined. |
| - ~JavaRef() {} |
| - |
| // The following are implementation detail convenience methods, for |
| // use by the sub-classes. |
| JNIEnv* SetNewLocalRef(JNIEnv* env, jobject obj); |
| @@ -83,11 +89,13 @@ class BASE_EXPORT JavaRef<jobject> { |
| template<typename T> |
| class JavaRef : public JavaRef<jobject> { |
| public: |
| + JavaRef(std::nullptr_t) : JavaRef<jobject>(nullptr) {} |
| + ~JavaRef() {} |
| + |
| T obj() const { return static_cast<T>(JavaRef<jobject>::obj()); } |
| protected: |
| JavaRef() {} |
| - ~JavaRef() {} |
| JavaRef(JNIEnv* env, T obj) : JavaRef<jobject>(env, obj) {} |
| @@ -110,7 +118,7 @@ class JavaParamRef : public JavaRef<T> { |
| // methods directly from C++ and pass null for objects which are not actually |
| // used by the implementation (e.g. the caller object); allow this to keep |
| // working. |
| - JavaParamRef(std::nullptr_t) : JavaRef<T>() {} |
| + JavaParamRef(std::nullptr_t) : JavaRef<T>(nullptr) {} |
| ~JavaParamRef() {} |