OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef BASE_ANDROID_AUTO_JOBJECT_H_ |
| 6 #define BASE_ANDROID_AUTO_JOBJECT_H_ |
| 7 |
| 8 #include <jni.h> |
| 9 |
| 10 namespace base { |
| 11 namespace android { |
| 12 |
| 13 // A helper class that automatically deletes the local reference to the jobject. |
| 14 class AutoJObject { |
| 15 public: |
| 16 // Takes ownership of |obj|. |
| 17 static AutoJObject FromLocalRef(JNIEnv* env, jobject obj); |
| 18 |
| 19 AutoJObject(const AutoJObject& other); |
| 20 ~AutoJObject(); |
| 21 |
| 22 JNIEnv* env() const; |
| 23 jobject obj() const; |
| 24 // Releases the local reference to the caller. The caller *must* delete the |
| 25 // local reference when it is done with it. |
| 26 jobject Release(); |
| 27 |
| 28 private: |
| 29 AutoJObject(); // Not permitted. |
| 30 AutoJObject(JNIEnv* env, jobject obj); |
| 31 |
| 32 JNIEnv* env_; |
| 33 jobject obj_; |
| 34 }; |
| 35 |
| 36 } // namespace android |
| 37 } // namespace base |
| 38 |
| 39 #endif // BASE_ANDROID_AUTO_JOBJECT_H_ |
OLD | NEW |