Flutter Engine
The Flutter Engine
jni_weak_ref.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "flutter/fml/platform/android/jni_weak_ref.h"
6
7#include "flutter/fml/logging.h"
8#include "flutter/fml/platform/android/jni_util.h"
9
10namespace fml {
11namespace jni {
12
14
16 const JavaObjectWeakGlobalRef& orig)
17 : obj_(NULL) {
18 Assign(orig);
19}
20
22 : obj_(env->NewWeakGlobalRef(obj)) {
23 FML_DCHECK(obj_);
24}
25
27 reset();
28}
29
31 Assign(rhs);
32}
33
35 if (obj_) {
36 AttachCurrentThread()->DeleteWeakGlobalRef(obj_);
37 obj_ = NULL;
38 }
39}
40
42 return GetRealObject(env, obj_);
43}
44
46 jobject real = NULL;
47 if (obj) {
48 real = env->NewLocalRef(obj);
49 if (!real) {
50 FML_DLOG(ERROR) << "The real object has been deleted!";
51 }
52 }
53 return ScopedJavaLocalRef<jobject>(env, real);
54}
55
56void JavaObjectWeakGlobalRef::Assign(const JavaObjectWeakGlobalRef& other) {
57 if (&other == this) {
58 return;
59 }
60
61 JNIEnv* env = AttachCurrentThread();
62 if (obj_) {
63 env->DeleteWeakGlobalRef(obj_);
64 }
65
66 obj_ = other.obj_ ? env->NewWeakGlobalRef(other.obj_) : NULL;
67}
68
69} // namespace jni
70} // namespace fml
void operator=(const JavaObjectWeakGlobalRef &rhs)
Definition: jni_weak_ref.cc:30
ScopedJavaLocalRef< jobject > get(JNIEnv *env) const
Definition: jni_weak_ref.cc:41
#define FML_DLOG(severity)
Definition: logging.h:102
#define FML_DCHECK(condition)
Definition: logging.h:103
Definition: __init__.py:1
JNIEnv * AttachCurrentThread()
Definition: jni_util.cc:34
ScopedJavaLocalRef< jobject > GetRealObject(JNIEnv *env, jweak obj)
Definition: jni_weak_ref.cc:45
Definition: ascii_trie.cc:9
#define ERROR(message)
Definition: elf_loader.cc:260