Chromium Code Reviews| Index: base/android/auto_jobject.cc |
| diff --git a/base/android/auto_jobject.cc b/base/android/auto_jobject.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..04acd28377cbf51cd4f77c3d88311865023f60ac |
| --- /dev/null |
| +++ b/base/android/auto_jobject.cc |
| @@ -0,0 +1,47 @@ |
| +// 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. |
| + |
| +#include "base/android/auto_jobject.h" |
| + |
| +#include <stddef.h> |
| + |
| +namespace base { |
| +namespace android { |
| + |
| +AutoJObject AutoJObject::FromLocalRef(JNIEnv* env, jobject obj) { |
| + return AutoJObject(env, obj); |
| +} |
| + |
| +AutoJObject::AutoJObject(const AutoJObject& other) |
| + : env_(other.env_), |
| + obj_(other.obj_ ? other.env_->NewLocalRef(other.obj_) : NULL) { |
| +} |
| + |
| +AutoJObject::AutoJObject(JNIEnv* env, jobject obj) |
| + : env_(env), |
| + obj_(obj) { |
| +} |
| + |
| +AutoJObject::~AutoJObject() { |
| + if (obj_) |
| + env_->DeleteLocalRef(obj_); |
| +} |
| + |
| +JNIEnv* AutoJObject::env() const { |
| + return env_; |
| +} |
| + |
| +jobject AutoJObject::obj() const { |
| + return obj_; |
| +} |
| + |
| +jobject AutoJObject::Release() { |
| + jobject obj = obj_; |
| + obj_ = 0; |
|
bulach
2011/07/26 18:23:04
nit: NULL
|
| + return obj; |
| +} |
| + |
| +} // namespace android |
| +} // namespace base |
| + |
|
bulach
2011/07/26 18:23:04
nit: extra \n
|