Chromium Code Reviews| 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 |
| 11 #include "base/base_export.h" | 11 #include "base/base_export.h" |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/logging.h" | |
| 13 | 14 |
| 14 namespace base { | 15 namespace base { |
| 15 namespace android { | 16 namespace android { |
| 16 | 17 |
| 17 // Creates a new local reference frame, in which at least a given number of | 18 // Creates a new local reference frame, in which at least a given number of |
| 18 // local references can be created. Note that local references already created | 19 // local references can be created. Note that local references already created |
| 19 // in previous local frames are still valid in the current local frame. | 20 // in previous local frames are still valid in the current local frame. |
| 20 class BASE_EXPORT ScopedJavaLocalFrame { | 21 class BASE_EXPORT ScopedJavaLocalFrame { |
| 21 public: | 22 public: |
| 22 explicit ScopedJavaLocalFrame(JNIEnv* env); | 23 explicit ScopedJavaLocalFrame(JNIEnv* env); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 39 // ScopedJavaLocalRef<jstring> into a function taking const JavaRef<jobject>& | 40 // ScopedJavaLocalRef<jstring> into a function taking const JavaRef<jobject>& |
| 40 template<> | 41 template<> |
| 41 class BASE_EXPORT JavaRef<jobject> { | 42 class BASE_EXPORT JavaRef<jobject> { |
| 42 public: | 43 public: |
| 43 jobject obj() const { return obj_; } | 44 jobject obj() const { return obj_; } |
| 44 | 45 |
| 45 bool is_null() const { return obj_ == NULL; } | 46 bool is_null() const { return obj_ == NULL; } |
| 46 | 47 |
| 47 protected: | 48 protected: |
| 48 // Initializes a NULL reference. | 49 // Initializes a NULL reference. |
| 49 JavaRef(); | 50 JavaRef() : obj_(NULL) {} |
|
rmcilroy
2015/08/24 16:40:19
Could you add a comment here that no other code sh
| |
| 50 | 51 |
| 51 // Takes ownership of the |obj| reference passed; requires it to be a local | 52 // Takes ownership of the |obj| reference passed; requires it to be a local |
| 52 // reference type. | 53 // reference type. |
| 54 #if DCHECK_IS_ON() | |
| 53 JavaRef(JNIEnv* env, jobject obj); | 55 JavaRef(JNIEnv* env, jobject obj); |
| 56 #else | |
| 57 JavaRef(JNIEnv* env, jobject obj) : obj_(obj) {} | |
| 58 #endif | |
| 54 | 59 |
| 55 ~JavaRef(); | 60 ~JavaRef() {} |
| 56 | 61 |
| 57 // The following are implementation detail convenience methods, for | 62 // The following are implementation detail convenience methods, for |
| 58 // use by the sub-classes. | 63 // use by the sub-classes. |
| 59 JNIEnv* SetNewLocalRef(JNIEnv* env, jobject obj); | 64 JNIEnv* SetNewLocalRef(JNIEnv* env, jobject obj); |
| 60 void SetNewGlobalRef(JNIEnv* env, jobject obj); | 65 void SetNewGlobalRef(JNIEnv* env, jobject obj); |
| 61 void ResetLocalRef(JNIEnv* env); | 66 void ResetLocalRef(JNIEnv* env); |
| 62 void ResetGlobalRef(); | 67 void ResetGlobalRef(); |
| 63 jobject ReleaseInternal(); | 68 jobject ReleaseInternal(); |
| 64 | 69 |
| 65 private: | 70 private: |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 208 // global reference when it is done with it. | 213 // global reference when it is done with it. |
| 209 T Release() { | 214 T Release() { |
| 210 return static_cast<T>(this->ReleaseInternal()); | 215 return static_cast<T>(this->ReleaseInternal()); |
| 211 } | 216 } |
| 212 }; | 217 }; |
| 213 | 218 |
| 214 } // namespace android | 219 } // namespace android |
| 215 } // namespace base | 220 } // namespace base |
| 216 | 221 |
| 217 #endif // BASE_ANDROID_SCOPED_JAVA_REF_H_ | 222 #endif // BASE_ANDROID_SCOPED_JAVA_REF_H_ |
| OLD | NEW |