OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * libjingle | 3 * libjingle |
4 * Copyright 2015 Google Inc. | 4 * Copyright 2015 Google Inc. |
5 * | 5 * |
6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions are met: | 7 * modification, are permitted provided that the following conditions are met: |
8 * | 8 * |
9 * 1. Redistributions of source code must retain the above copyright notice, | 9 * 1. Redistributions of source code must retain the above copyright notice, |
10 * this list of conditions and the following disclaimer. | 10 * this list of conditions and the following disclaimer. |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 CHECK_EXCEPTION(jni) << "error during NewGlobalRef"; | 266 CHECK_EXCEPTION(jni) << "error during NewGlobalRef"; |
267 CHECK(ret); | 267 CHECK(ret); |
268 return ret; | 268 return ret; |
269 } | 269 } |
270 | 270 |
271 void DeleteGlobalRef(JNIEnv* jni, jobject o) { | 271 void DeleteGlobalRef(JNIEnv* jni, jobject o) { |
272 jni->DeleteGlobalRef(o); | 272 jni->DeleteGlobalRef(o); |
273 CHECK_EXCEPTION(jni) << "error during DeleteGlobalRef"; | 273 CHECK_EXCEPTION(jni) << "error during DeleteGlobalRef"; |
274 } | 274 } |
275 | 275 |
276 WeakRef::WeakRef(JNIEnv* jni, jweak ref) | |
277 : jni_(jni), obj_(jni_->NewLocalRef(ref)) { | |
278 CHECK_EXCEPTION(jni) << "error during NewLocalRef"; | |
279 } | |
280 WeakRef::~WeakRef() { | |
281 if (obj_) { | |
282 jni_->DeleteLocalRef(obj_); | |
283 CHECK_EXCEPTION(jni_) << "error during DeleteLocalRef"; | |
284 } | |
285 } | |
286 | |
287 // Scope Java local references to the lifetime of this object. Use in all C++ | 276 // Scope Java local references to the lifetime of this object. Use in all C++ |
288 // callbacks (i.e. entry points that don't originate in a Java callstack | 277 // callbacks (i.e. entry points that don't originate in a Java callstack |
289 // through a "native" method call). | 278 // through a "native" method call). |
290 ScopedLocalRefFrame::ScopedLocalRefFrame(JNIEnv* jni) : jni_(jni) { | 279 ScopedLocalRefFrame::ScopedLocalRefFrame(JNIEnv* jni) : jni_(jni) { |
291 CHECK(!jni_->PushLocalFrame(0)) << "Failed to PushLocalFrame"; | 280 CHECK(!jni_->PushLocalFrame(0)) << "Failed to PushLocalFrame"; |
292 } | 281 } |
293 ScopedLocalRefFrame::~ScopedLocalRefFrame() { | 282 ScopedLocalRefFrame::~ScopedLocalRefFrame() { |
294 jni_->PopLocalFrame(NULL); | 283 jni_->PopLocalFrame(NULL); |
295 } | 284 } |
296 | 285 |
297 } // namespace webrtc_jni | 286 } // namespace webrtc_jni |
OLD | NEW |