| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/android/jni_weak_ref.h" | 5 #include "base/android/jni_weak_ref.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 | 9 |
| 10 using base::android::AttachCurrentThread; | 10 using base::android::AttachCurrentThread; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 } | 40 } |
| 41 | 41 |
| 42 base::android::ScopedJavaLocalRef<jobject> | 42 base::android::ScopedJavaLocalRef<jobject> |
| 43 JavaObjectWeakGlobalRef::get(JNIEnv* env) const { | 43 JavaObjectWeakGlobalRef::get(JNIEnv* env) const { |
| 44 return GetRealObject(env, obj_); | 44 return GetRealObject(env, obj_); |
| 45 } | 45 } |
| 46 | 46 |
| 47 base::android::ScopedJavaLocalRef<jobject> GetRealObject( | 47 base::android::ScopedJavaLocalRef<jobject> GetRealObject( |
| 48 JNIEnv* env, jweak obj) { | 48 JNIEnv* env, jweak obj) { |
| 49 jobject real = NULL; | 49 jobject real = NULL; |
| 50 if (obj) { | 50 if (obj) |
| 51 real = env->NewLocalRef(obj); | 51 real = env->NewLocalRef(obj); |
| 52 if (!real) | |
| 53 DLOG(ERROR) << "The real object has been deleted!"; | |
| 54 } | |
| 55 return base::android::ScopedJavaLocalRef<jobject>(env, real); | 52 return base::android::ScopedJavaLocalRef<jobject>(env, real); |
| 56 } | 53 } |
| 57 | 54 |
| 58 void JavaObjectWeakGlobalRef::Assign(const JavaObjectWeakGlobalRef& other) { | 55 void JavaObjectWeakGlobalRef::Assign(const JavaObjectWeakGlobalRef& other) { |
| 59 if (&other == this) | 56 if (&other == this) |
| 60 return; | 57 return; |
| 61 | 58 |
| 62 JNIEnv* env = AttachCurrentThread(); | 59 JNIEnv* env = AttachCurrentThread(); |
| 63 if (obj_) | 60 if (obj_) |
| 64 env->DeleteWeakGlobalRef(obj_); | 61 env->DeleteWeakGlobalRef(obj_); |
| 65 | 62 |
| 66 obj_ = other.obj_ ? env->NewWeakGlobalRef(other.obj_) : NULL; | 63 obj_ = other.obj_ ? env->NewWeakGlobalRef(other.obj_) : NULL; |
| 67 } | 64 } |
| OLD | NEW |