OLD | NEW |
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 { |
11 namespace android { | 11 namespace android { |
| 12 namespace { |
| 13 |
| 14 const int kDefaultLocalFrameCapacity = 16; |
| 15 |
| 16 } // namespace |
| 17 |
| 18 ScopedJavaLocalFrame::ScopedJavaLocalFrame(JNIEnv* env) : env_(env) { |
| 19 int failed = env_->PushLocalFrame(kDefaultLocalFrameCapacity); |
| 20 DCHECK(!failed); |
| 21 } |
| 22 |
| 23 ScopedJavaLocalFrame::ScopedJavaLocalFrame(JNIEnv* env, int capacity) |
| 24 : env_(env) { |
| 25 int failed = env_->PushLocalFrame(capacity); |
| 26 DCHECK(!failed); |
| 27 } |
| 28 |
| 29 ScopedJavaLocalFrame::~ScopedJavaLocalFrame() { env_->PopLocalFrame(NULL); } |
12 | 30 |
13 JavaRef<jobject>::JavaRef() : obj_(NULL) {} | 31 JavaRef<jobject>::JavaRef() : obj_(NULL) {} |
14 | 32 |
15 JavaRef<jobject>::JavaRef(JNIEnv* env, jobject obj) : obj_(obj) { | 33 JavaRef<jobject>::JavaRef(JNIEnv* env, jobject obj) : obj_(obj) { |
16 if (obj) { | 34 if (obj) { |
17 DCHECK(env && env->GetObjectRefType(obj) == JNILocalRefType); | 35 DCHECK(env && env->GetObjectRefType(obj) == JNILocalRefType); |
18 } | 36 } |
19 } | 37 } |
20 | 38 |
21 JavaRef<jobject>::~JavaRef() { | 39 JavaRef<jobject>::~JavaRef() { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 } | 82 } |
65 | 83 |
66 jobject JavaRef<jobject>::ReleaseInternal() { | 84 jobject JavaRef<jobject>::ReleaseInternal() { |
67 jobject obj = obj_; | 85 jobject obj = obj_; |
68 obj_ = NULL; | 86 obj_ = NULL; |
69 return obj; | 87 return obj; |
70 } | 88 } |
71 | 89 |
72 } // namespace android | 90 } // namespace android |
73 } // namespace base | 91 } // namespace base |
OLD | NEW |