1 /* 2 * Copyright 2019 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #include "sdk/android/src/jni/scoped_java_ref_counted.h" 12 13 #include "sdk/android/generated_base_jni/RefCounted_jni.h" 14 15 namespace webrtc { 16 namespace jni { 17 18 // static Retain(JNIEnv * jni,const JavaRef<jobject> & j_object)19ScopedJavaRefCounted ScopedJavaRefCounted::Retain( 20 JNIEnv* jni, 21 const JavaRef<jobject>& j_object) { 22 Java_RefCounted_retain(jni, j_object); 23 CHECK_EXCEPTION(jni) 24 << "Unexpected java exception from java JavaRefCounted.retain()"; 25 return Adopt(jni, j_object); 26 } 27 ~ScopedJavaRefCounted()28ScopedJavaRefCounted::~ScopedJavaRefCounted() { 29 if (!j_object_.is_null()) { 30 JNIEnv* jni = AttachCurrentThreadIfNeeded(); 31 Java_RefCounted_release(jni, j_object_); 32 CHECK_EXCEPTION(jni) 33 << "Unexpected java exception from java RefCounted.release()"; 34 } 35 } 36 37 } // namespace jni 38 } // namespace webrtc 39