| 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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 // local reference when it is done with it. Note that calling a Java method | 186 // local reference when it is done with it. Note that calling a Java method |
| 187 // is *not* a transfer of ownership and Release() should not be used. | 187 // is *not* a transfer of ownership and Release() should not be used. |
| 188 T Release() { | 188 T Release() { |
| 189 return static_cast<T>(this->ReleaseInternal()); | 189 return static_cast<T>(this->ReleaseInternal()); |
| 190 } | 190 } |
| 191 | 191 |
| 192 private: | 192 private: |
| 193 // This class is only good for use on the thread it was created on so | 193 // This class is only good for use on the thread it was created on so |
| 194 // it's safe to cache the non-threadsafe JNIEnv* inside this object. | 194 // it's safe to cache the non-threadsafe JNIEnv* inside this object. |
| 195 JNIEnv* env_; | 195 JNIEnv* env_; |
| 196 |
| 197 // Prevent ScopedJavaLocalRef(JNIEnv*, T obj) from being used to take |
| 198 // ownership of a JavaParamRef's underlying object - parameters are not |
| 199 // allowed to be deleted and so should not be owned by ScopedJavaLocalRef. |
| 200 // TODO(torne): this can be removed once JavaParamRef no longer has an |
| 201 // implicit conversion back to T. |
| 202 ScopedJavaLocalRef(JNIEnv* env, const JavaParamRef<T>& other); |
| 196 }; | 203 }; |
| 197 | 204 |
| 198 // Holds a global reference to a Java object. The global reference is scoped | 205 // Holds a global reference to a Java object. The global reference is scoped |
| 199 // to the lifetime of this object. This class does not hold onto any JNIEnv* | 206 // to the lifetime of this object. This class does not hold onto any JNIEnv* |
| 200 // passed to it, hence it is safe to use across threads (within the constraints | 207 // passed to it, hence it is safe to use across threads (within the constraints |
| 201 // imposed by the underlying Java object that it references). | 208 // imposed by the underlying Java object that it references). |
| 202 template<typename T> | 209 template<typename T> |
| 203 class ScopedJavaGlobalRef : public JavaRef<T> { | 210 class ScopedJavaGlobalRef : public JavaRef<T> { |
| 204 public: | 211 public: |
| 205 ScopedJavaGlobalRef() {} | 212 ScopedJavaGlobalRef() {} |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 // is *not* a transfer of ownership and Release() should not be used. | 251 // is *not* a transfer of ownership and Release() should not be used. |
| 245 T Release() { | 252 T Release() { |
| 246 return static_cast<T>(this->ReleaseInternal()); | 253 return static_cast<T>(this->ReleaseInternal()); |
| 247 } | 254 } |
| 248 }; | 255 }; |
| 249 | 256 |
| 250 } // namespace android | 257 } // namespace android |
| 251 } // namespace base | 258 } // namespace base |
| 252 | 259 |
| 253 #endif // BASE_ANDROID_SCOPED_JAVA_REF_H_ | 260 #endif // BASE_ANDROID_SCOPED_JAVA_REF_H_ |
| OLD | NEW |