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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
141 T Release() { | 141 T Release() { |
142 return static_cast<T>(this->ReleaseInternal()); | 142 return static_cast<T>(this->ReleaseInternal()); |
143 } | 143 } |
144 | 144 |
145 private: | 145 private: |
146 // This class is only good for use on the thread it was created on so | 146 // This class is only good for use on the thread it was created on so |
147 // it's safe to cache the non-threadsafe JNIEnv* inside this object. | 147 // it's safe to cache the non-threadsafe JNIEnv* inside this object. |
148 JNIEnv* env_; | 148 JNIEnv* env_; |
149 }; | 149 }; |
150 | 150 |
151 // Creates a new local reference frame, in which at least a given number of | |
152 // local references can be created. Note that local references already created | |
153 // in previous local frames are still valid in the current local frame. | |
154 class ScopedJavaLocalFrame { | |
155 public: | |
156 explicit ScopedJavaLocalFrame(JNIEnv* env); | |
157 ScopedJavaLocalFrame(JNIEnv* env, int capacity); | |
158 ~ScopedJavaLocalFrame(); | |
159 | |
160 private: | |
161 // This class is only good for use on the thread it was created on so | |
162 // it's safe to cache the non-threadsafe JNIEnv* inside this object. | |
163 JNIEnv* env_; | |
no sievers
2014/04/04 20:32:11
DISALLOW_COPY_AND_ASSIGN
reveman
2014/04/04 21:07:08
Done.
| |
164 }; | |
165 | |
151 // Holds a global reference to a Java object. The global reference is scoped | 166 // Holds a global reference to a Java object. The global reference is scoped |
152 // to the lifetime of this object. This class does not hold onto any JNIEnv* | 167 // to the lifetime of this object. This class does not hold onto any JNIEnv* |
153 // passed to it, hence it is safe to use across threads (within the constraints | 168 // passed to it, hence it is safe to use across threads (within the constraints |
154 // imposed by the underlying Java object that it references). | 169 // imposed by the underlying Java object that it references). |
155 template<typename T> | 170 template<typename T> |
156 class ScopedJavaGlobalRef : public JavaRef<T> { | 171 class ScopedJavaGlobalRef : public JavaRef<T> { |
157 public: | 172 public: |
158 ScopedJavaGlobalRef() {} | 173 ScopedJavaGlobalRef() {} |
159 | 174 |
160 explicit ScopedJavaGlobalRef(const ScopedJavaGlobalRef<T>& other) { | 175 explicit ScopedJavaGlobalRef(const ScopedJavaGlobalRef<T>& other) { |
(...skipping 28 matching lines...) Expand all Loading... | |
189 // global reference when it is done with it. | 204 // global reference when it is done with it. |
190 T Release() { | 205 T Release() { |
191 return static_cast<T>(this->ReleaseInternal()); | 206 return static_cast<T>(this->ReleaseInternal()); |
192 } | 207 } |
193 }; | 208 }; |
194 | 209 |
195 } // namespace android | 210 } // namespace android |
196 } // namespace base | 211 } // namespace base |
197 | 212 |
198 #endif // BASE_ANDROID_SCOPED_JAVA_REF_H_ | 213 #endif // BASE_ANDROID_SCOPED_JAVA_REF_H_ |
OLD | NEW |