Chromium Code Reviews| Index: base/android/auto_jobject.h |
| diff --git a/base/android/auto_jobject.h b/base/android/auto_jobject.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..45e4088a73489a522e0fda529bb8d851bced5910 |
| --- /dev/null |
| +++ b/base/android/auto_jobject.h |
| @@ -0,0 +1,39 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef BASE_ANDROID_AUTO_JOBJECT_H_ |
| +#define BASE_ANDROID_AUTO_JOBJECT_H_ |
| + |
| +#include <jni.h> |
| + |
| +namespace base { |
| +namespace android { |
| + |
| +// A helper class that automatically deletes the local reference to the jobject. |
|
brettw
2011/08/01 16:03:54
Basically the same comments from the other class.
|
| +class AutoJObject { |
| + public: |
| + // Takes ownership of |obj|. |
| + static AutoJObject FromLocalRef(JNIEnv* env, jobject obj); |
|
steveblock
2011/08/02 15:05:46
We could simplify the API by removing this method
bulach
2011/08/02 15:18:36
no particular preference, happy to go with the sim
Sami (do not use)
2011/08/02 15:23:49
I'd be fine with having a new constructor for Auto
|
| + |
| + AutoJObject(const AutoJObject& other); |
| + ~AutoJObject(); |
| + |
| + JNIEnv* env() const; |
| + jobject obj() const; |
| + // Releases the local reference to the caller. The caller *must* delete the |
| + // local reference when it is done with it. |
| + jobject Release(); |
| + |
| + private: |
| + AutoJObject(); // Not permitted. |
| + AutoJObject(JNIEnv* env, jobject obj); |
| + |
| + JNIEnv* env_; |
| + jobject obj_; |
| +}; |
| + |
| +} // namespace android |
| +} // namespace base |
| + |
| +#endif // BASE_ANDROID_AUTO_JOBJECT_H_ |