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

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

Issue 10702083: Add ContentViewDelegate (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix typo Created 8 years, 3 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') | no next file » | 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()
13 : obj_(NULL) {
14 }
15
16 JavaObjectWeakGlobalRef::JavaObjectWeakGlobalRef(
17 const JavaObjectWeakGlobalRef& orig) {
18 Assign(orig);
19 }
20
12 JavaObjectWeakGlobalRef::JavaObjectWeakGlobalRef(JNIEnv* env, jobject obj) 21 JavaObjectWeakGlobalRef::JavaObjectWeakGlobalRef(JNIEnv* env, jobject obj)
13 : obj_(env->NewWeakGlobalRef(obj)) { 22 : obj_(env->NewWeakGlobalRef(obj)) {
14 DCHECK(obj_); 23 DCHECK(obj_);
15 } 24 }
16 25
17 JavaObjectWeakGlobalRef::~JavaObjectWeakGlobalRef() { 26 JavaObjectWeakGlobalRef::~JavaObjectWeakGlobalRef() {
18 reset(); 27 reset();
19 } 28 }
20 29
30 void JavaObjectWeakGlobalRef::operator=(const JavaObjectWeakGlobalRef& rhs) {
31 Assign(rhs);
32 }
33
21 void JavaObjectWeakGlobalRef::reset() { 34 void JavaObjectWeakGlobalRef::reset() {
22 if (obj_) { 35 if (obj_) {
23 AttachCurrentThread()->DeleteWeakGlobalRef(obj_); 36 AttachCurrentThread()->DeleteWeakGlobalRef(obj_);
24 obj_ = NULL; 37 obj_ = NULL;
25 } 38 }
26 } 39 }
27 40
28 base::android::ScopedJavaLocalRef<jobject> 41 base::android::ScopedJavaLocalRef<jobject>
29 JavaObjectWeakGlobalRef::get(JNIEnv* env) const { 42 JavaObjectWeakGlobalRef::get(JNIEnv* env) const {
30 return GetRealObject(env, obj_); 43 return GetRealObject(env, obj_);
31 } 44 }
32 45
33 base::android::ScopedJavaLocalRef<jobject> GetRealObject( 46 base::android::ScopedJavaLocalRef<jobject> GetRealObject(
34 JNIEnv* env, jweak obj) { 47 JNIEnv* env, jweak obj) {
35 jobject real = NULL; 48 jobject real = NULL;
36 if (obj) { 49 if (obj) {
37 real = env->NewLocalRef(obj); 50 real = env->NewLocalRef(obj);
38 if (!real) 51 if (!real)
39 DLOG(ERROR) << "The real object has been deleted!"; 52 DLOG(ERROR) << "The real object has been deleted!";
40 } 53 }
41 return base::android::ScopedJavaLocalRef<jobject>(env, real); 54 return base::android::ScopedJavaLocalRef<jobject>(env, real);
42 } 55 }
56
57 void JavaObjectWeakGlobalRef::Assign(const JavaObjectWeakGlobalRef& other) {
58 JNIEnv* env = AttachCurrentThread();
59 obj_ = env->NewWeakGlobalRef(other.obj_);
60 }
OLDNEW
« no previous file with comments | « base/android/jni_helper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698