Chromium Code Reviews| Index: content/browser/android/jni_helper.cc |
| diff --git a/content/browser/android/jni_helper.cc b/content/browser/android/jni_helper.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2f1664fe82f5895dc392fd724688059ea35bad68 |
| --- /dev/null |
| +++ b/content/browser/android/jni_helper.cc |
| @@ -0,0 +1,33 @@ |
| +// Copyright (c) 2012 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 "content/browser/android/jni_helper.h" |
| + |
| +#include "base/android/jni_android.h" |
| +#include "base/logging.h" |
| + |
| +using base::android::AttachCurrentThread; |
| + |
| +JavaObjectWeakGlobalRef::JavaObjectWeakGlobalRef(JNIEnv* env, jobject obj) |
| + : obj_(env->NewWeakGlobalRef(obj)) { |
| + DCHECK(obj_); |
| +} |
| + |
| +JavaObjectWeakGlobalRef::~JavaObjectWeakGlobalRef() { |
| + DCHECK(obj_); |
| + AttachCurrentThread()->DeleteWeakGlobalRef(obj_); |
| +} |
| + |
| +base::android::ScopedJavaLocalRef<jobject> |
| + JavaObjectWeakGlobalRef::get(JNIEnv* env) const { |
| + return GetRealObject(env, obj_); |
| +} |
| + |
| +base::android::ScopedJavaLocalRef<jobject> GetRealObject( |
| + JNIEnv* env, jobject obj) { |
| + jobject real = env->NewLocalRef(obj); |
| + if (!real) |
| + DLOG(ERROR) << "The real object has been deleted!"; |
|
John Grabowski
2012/04/19 18:55:27
CHECK()?
Ted C
2012/04/19 23:21:07
As this is a weak reference, the underlying object
|
| + return base::android::ScopedJavaLocalRef<jobject>(env, real); |
| +} |