Chromium Code Reviews| 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 // Holds a local reference to a Java object. The global reference is scoped | |
| 14 // to the lifetime of this object. | |
| 15 class AutoJObject { | |
| 16 public: | |
| 17 // Assumes that obj is a local reference to a Java object and takes ownership | |
| 18 // of this local reference. The local /reference is deleted when this object | |
| 19 // goes out of scope. | |
| 20 AutoJObject(JNIEnv* env, jobject obj); | |
| 21 // Takes a new local reference to the Java object held by other. The local | |
| 22 // reference is deleted when this object goes out of scope. | |
| 23 AutoJObject(const AutoJObject& other); | |
| 24 ~AutoJObject(); | |
| 25 | |
| 26 inline JNIEnv* env() const { return env_; } | |
|
brettw
2011/08/02 15:55:39
We wouldn't normally write "inline" here. C++ says
| |
| 27 inline jobject obj() const { return obj_; } | |
| 28 // Releases the local reference to the caller. The caller *must* delete the | |
| 29 // local reference when it is done with it. | |
| 30 jobject Release(); | |
| 31 | |
| 32 private: | |
| 33 AutoJObject(); // Not permitted. | |
|
brettw
2011/08/02 15:55:39
If you're returning by value, not permitting the d
| |
| 34 void operator=(const AutoJObject&); // DISALLOW_ASSIGN | |
| 35 | |
| 36 JNIEnv* env_; | |
| 37 jobject obj_; | |
| 38 }; | |
| 39 | |
| 40 } // namespace android | |
| 41 } // namespace base | |
| 42 | |
| 43 #endif // BASE_ANDROID_AUTO_JOBJECT_H_ | |
| OLD | NEW |