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..e4ea5ecd91f0e0094b31efdd0adba5e37daf9429 |
| --- /dev/null |
| +++ b/base/android/auto_global_jobject.h |
| @@ -0,0 +1,42 @@ |
| +// 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" |
| + |
| +namespace base { |
| +namespace android { |
| + |
| +// A global reference to a Java object which is cleaned up automatically when |
| +// this object gets deleted. |
| +class AutoGlobalJObject { |
| + public: |
| + // Takes ownership of |obj|. |
| + static AutoGlobalJObject FromLocalRef(JNIEnv* env, jobject obj); |
|
brettw
2011/08/01 16:03:54
There's not a defined place for this in the header
steveblock
2011/08/02 15:05:46
Done.
|
| + |
| + AutoGlobalJObject(); |
| + AutoGlobalJObject(const AutoGlobalJObject& other); |
|
brettw
2011/08/01 16:03:54
Do you need an implicit copy constructor? These ar
steveblock
2011/08/02 15:05:46
We don't need one for AutoGlobalJObject (other tha
brettw
2011/08/02 15:55:39
If you're going to be returning these by value, it
|
| + explicit AutoGlobalJObject(const AutoJObject& obj); |
| + ~AutoGlobalJObject(); |
| + |
| + void Reset(); |
| + void Reset(const AutoGlobalJObject& other); |
| + jobject obj() const; |
|
brettw
2011/08/01 16:03:54
This should be inline. If it can't be, it should b
steveblock
2011/08/02 15:05:46
Done.
|
| + |
| + private: |
| + // Not permitted. |
| + AutoGlobalJObject& operator=(const AutoGlobalJObject& other); |
| + |
| + JNIEnv* env_; |
| + jobject obj_; |
| +}; |
| + |
| +} // namespace android |
| +} // namespace base |
| + |
| +#endif // BASE_ANDROID_AUTO_GLOBAL_JOBJECT_H_ |