Chromium Code Reviews| Index: base/android/auto_global_jobject.h |
| diff --git a/base/android/auto_global_jobject.h b/base/android/auto_global_jobject.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..35c9a860f9a4e7a4167db020a7c236743f80c869 |
| --- /dev/null |
| +++ b/base/android/auto_global_jobject.h |
| @@ -0,0 +1,41 @@ |
| +// 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_GLOBAL_JOBJECT_H_ |
| +#define BASE_ANDROID_AUTO_GLOBAL_JOBJECT_H_ |
| + |
| +#include <jni.h> |
| + |
| +#include "base/android/auto_jobject.h" |
| +#include "base/basictypes.h" |
| + |
| +namespace base { |
| +namespace android { |
| + |
| +// Holds a global reference to a Java object. The global reference is scoped |
| +// to the lifetime of this object. |
| +class AutoGlobalJObject { |
| + public: |
| + // Holds a NULL reference. |
| + AutoGlobalJObject(); |
| + // Takes a new global reference to the Java object held by obj. The global |
| + // reference is deleted when this object goes out of scope. |
| + explicit AutoGlobalJObject(const AutoJObject& obj); |
| + ~AutoGlobalJObject(); |
| + |
| + void Reset(); |
| + void Reset(const AutoGlobalJObject& other); |
| + inline jobject obj() const { return obj_; } |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(AutoGlobalJObject); |
|
brettw
2011/08/02 15:55:39
This should be last.
|
| + |
| + JNIEnv* env_; |
| + jobject obj_; |
| +}; |
| + |
| +} // namespace android |
| +} // namespace base |
| + |
| +#endif // BASE_ANDROID_AUTO_GLOBAL_JOBJECT_H_ |