Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(263)

Side by Side Diff: base/android/jni_helper.cc

Issue 10827125: Use JavaObjectWeakGlobalRef in ContentViewCore. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/android/jni_helper.h ('k') | content/browser/android/content_view_core_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_helper.h" 5 #include "base/android/jni_helper.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;
11 11
12 JavaObjectWeakGlobalRef::JavaObjectWeakGlobalRef(JNIEnv* env, jobject obj) 12 JavaObjectWeakGlobalRef::JavaObjectWeakGlobalRef(JNIEnv* env, jobject obj)
13 : obj_(env->NewWeakGlobalRef(obj)) { 13 : obj_(env->NewWeakGlobalRef(obj)) {
14 DCHECK(obj_); 14 DCHECK(obj_);
15 } 15 }
16 16
17 JavaObjectWeakGlobalRef::~JavaObjectWeakGlobalRef() { 17 JavaObjectWeakGlobalRef::~JavaObjectWeakGlobalRef() {
18 DCHECK(obj_); 18 reset();
19 AttachCurrentThread()->DeleteWeakGlobalRef(obj_); 19 }
20
21 void JavaObjectWeakGlobalRef::reset() {
22 if (obj_) {
23 AttachCurrentThread()->DeleteWeakGlobalRef(obj_);
24 obj_ = NULL;
25 }
20 } 26 }
21 27
22 base::android::ScopedJavaLocalRef<jobject> 28 base::android::ScopedJavaLocalRef<jobject>
23 JavaObjectWeakGlobalRef::get(JNIEnv* env) const { 29 JavaObjectWeakGlobalRef::get(JNIEnv* env) const {
24 return GetRealObject(env, obj_); 30 return GetRealObject(env, obj_);
25 } 31 }
26 32
27 base::android::ScopedJavaLocalRef<jobject> GetRealObject( 33 base::android::ScopedJavaLocalRef<jobject> GetRealObject(
28 JNIEnv* env, jobject obj) { 34 JNIEnv* env, jweak obj) {
29 jobject real = env->NewLocalRef(obj); 35 jobject real = NULL;
30 if (!real) 36 if (obj) {
31 DLOG(ERROR) << "The real object has been deleted!"; 37 real = env->NewLocalRef(obj);
38 if (!real)
39 DLOG(ERROR) << "The real object has been deleted!";
40 }
32 return base::android::ScopedJavaLocalRef<jobject>(env, real); 41 return base::android::ScopedJavaLocalRef<jobject>(env, real);
33 } 42 }
OLDNEW
« no previous file with comments | « base/android/jni_helper.h ('k') | content/browser/android/content_view_core_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698