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

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

Issue 1308413003: Inline constructors/destructor for JavaRef. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: also comment .cc file Created 5 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
« no previous file with comments | « base/android/scoped_java_ref.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/scoped_java_ref.h" 5 #include "base/android/scoped_java_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 namespace base { 10 namespace base {
(...skipping 10 matching lines...) Expand all
21 } 21 }
22 22
23 ScopedJavaLocalFrame::ScopedJavaLocalFrame(JNIEnv* env, int capacity) 23 ScopedJavaLocalFrame::ScopedJavaLocalFrame(JNIEnv* env, int capacity)
24 : env_(env) { 24 : env_(env) {
25 int failed = env_->PushLocalFrame(capacity); 25 int failed = env_->PushLocalFrame(capacity);
26 DCHECK(!failed); 26 DCHECK(!failed);
27 } 27 }
28 28
29 ScopedJavaLocalFrame::~ScopedJavaLocalFrame() { env_->PopLocalFrame(NULL); } 29 ScopedJavaLocalFrame::~ScopedJavaLocalFrame() { env_->PopLocalFrame(NULL); }
30 30
31 JavaRef<jobject>::JavaRef() : obj_(NULL) {} 31 #if DCHECK_IS_ON()
32 32 // This constructor is inlined when DCHECKs are disabled; don't add anything
33 // else here.
33 JavaRef<jobject>::JavaRef(JNIEnv* env, jobject obj) : obj_(obj) { 34 JavaRef<jobject>::JavaRef(JNIEnv* env, jobject obj) : obj_(obj) {
34 if (obj) { 35 if (obj) {
35 DCHECK(env && env->GetObjectRefType(obj) == JNILocalRefType); 36 DCHECK(env && env->GetObjectRefType(obj) == JNILocalRefType);
36 } 37 }
37 } 38 }
38 39 #endif
39 JavaRef<jobject>::~JavaRef() {
40 }
41 40
42 JNIEnv* JavaRef<jobject>::SetNewLocalRef(JNIEnv* env, jobject obj) { 41 JNIEnv* JavaRef<jobject>::SetNewLocalRef(JNIEnv* env, jobject obj) {
43 if (!env) { 42 if (!env) {
44 env = AttachCurrentThread(); 43 env = AttachCurrentThread();
45 } else { 44 } else {
46 DCHECK_EQ(env, AttachCurrentThread()); // Is |env| on correct thread. 45 DCHECK_EQ(env, AttachCurrentThread()); // Is |env| on correct thread.
47 } 46 }
48 if (obj) 47 if (obj)
49 obj = env->NewLocalRef(obj); 48 obj = env->NewLocalRef(obj);
50 if (obj_) 49 if (obj_)
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 } 81 }
83 82
84 jobject JavaRef<jobject>::ReleaseInternal() { 83 jobject JavaRef<jobject>::ReleaseInternal() {
85 jobject obj = obj_; 84 jobject obj = obj_;
86 obj_ = NULL; 85 obj_ = NULL;
87 return obj; 86 return obj;
88 } 87 }
89 88
90 } // namespace android 89 } // namespace android
91 } // namespace base 90 } // namespace base
OLDNEW
« no previous file with comments | « base/android/scoped_java_ref.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698