OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_ANDROID_SCOPED_JAVA_REF_H_ | 5 #ifndef BASE_ANDROID_SCOPED_JAVA_REF_H_ |
6 #define BASE_ANDROID_SCOPED_JAVA_REF_H_ | 6 #define BASE_ANDROID_SCOPED_JAVA_REF_H_ |
7 | 7 |
8 #include <jni.h> | 8 #include <jni.h> |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 | 10 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 // Method parameters should not be deleted, and so this class exists purely to | 99 // Method parameters should not be deleted, and so this class exists purely to |
100 // wrap them as a JavaRef<T> in the JNI binding generator. Do not create | 100 // wrap them as a JavaRef<T> in the JNI binding generator. Do not create |
101 // instances manually. | 101 // instances manually. |
102 template<typename T> | 102 template<typename T> |
103 class JavaParamRef : public JavaRef<T> { | 103 class JavaParamRef : public JavaRef<T> { |
104 public: | 104 public: |
105 // Assumes that |obj| is a parameter passed to a JNI method from Java. | 105 // Assumes that |obj| is a parameter passed to a JNI method from Java. |
106 // Does not assume ownership as parameters should not be deleted. | 106 // Does not assume ownership as parameters should not be deleted. |
107 JavaParamRef(JNIEnv* env, T obj) : JavaRef<T>(env, obj) {} | 107 JavaParamRef(JNIEnv* env, T obj) : JavaRef<T>(env, obj) {} |
108 | 108 |
| 109 // Allow nullptr to be converted to JavaParamRef. Some unit tests call JNI |
| 110 // methods directly from C++ and pass null for objects which are not actually |
| 111 // used by the implementation (e.g. the caller object); allow this to keep |
| 112 // working. |
| 113 JavaParamRef(std::nullptr_t) : JavaRef<T>() {} |
| 114 |
109 ~JavaParamRef() {} | 115 ~JavaParamRef() {} |
110 | 116 |
111 // TODO(torne): remove this cast once we're using JavaRef consistently. | 117 // TODO(torne): remove this cast once we're using JavaRef consistently. |
112 // http://crbug.com/506850 | 118 // http://crbug.com/506850 |
113 operator T() const { return JavaRef<T>::obj(); } | 119 operator T() const { return JavaRef<T>::obj(); } |
114 | 120 |
115 private: | 121 private: |
116 DISALLOW_COPY_AND_ASSIGN(JavaParamRef); | 122 DISALLOW_COPY_AND_ASSIGN(JavaParamRef); |
117 }; | 123 }; |
118 | 124 |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 // is *not* a transfer of ownership and Release() should not be used. | 260 // is *not* a transfer of ownership and Release() should not be used. |
255 T Release() { | 261 T Release() { |
256 return static_cast<T>(this->ReleaseInternal()); | 262 return static_cast<T>(this->ReleaseInternal()); |
257 } | 263 } |
258 }; | 264 }; |
259 | 265 |
260 } // namespace android | 266 } // namespace android |
261 } // namespace base | 267 } // namespace base |
262 | 268 |
263 #endif // BASE_ANDROID_SCOPED_JAVA_REF_H_ | 269 #endif // BASE_ANDROID_SCOPED_JAVA_REF_H_ |
OLD | NEW |