Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
dart_weak_persistent_value.h
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#ifndef LIB_TONIC_DART_WEAK_PERSISTENT_VALUE_H_
6#define LIB_TONIC_DART_WEAK_PERSISTENT_VALUE_H_
7
8#include <memory>
9
10#include "third_party/dart/runtime/include/dart_api.h"
11#include "tonic/common/macros.h"
12
13namespace tonic {
14class DartState;
15
16// DartWeakPersistentValue is a bookkeeping class to help pair calls to
17// Dart_NewWeakPersistentHandle with Dart_DeleteWeakPersistentHandle even in
18// the case if IsolateGroup shutdown. Consider using this class instead of
19// holding a Dart_PersistentHandle directly so that you don't leak the
20// Dart_WeakPersistentHandle.
22 public:
25
26 Dart_WeakPersistentHandle value() const { return handle_; }
27 bool is_empty() const { return handle_ == nullptr; }
28
29 void Set(DartState* dart_state,
30 Dart_Handle object,
31 void* peer,
32 intptr_t external_allocation_size,
34 void Clear();
36
37 const std::weak_ptr<DartState>& dart_state() const { return dart_state_; }
38
39 private:
40 std::weak_ptr<DartState> dart_state_;
42
44};
45
46} // namespace tonic
47
48#endif // LIB_TONIC_DART_WEAK_PERSISTENT_VALUE_H_
const std::weak_ptr< DartState > & dart_state() const
Dart_WeakPersistentHandle value() const
struct _Dart_Handle * Dart_Handle
Definition dart_api.h:258
void(* Dart_HandleFinalizer)(void *isolate_callback_data, void *peer)
Definition dart_api.h:265
struct _Dart_WeakPersistentHandle * Dart_WeakPersistentHandle
Definition dart_api.h:260
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
#define TONIC_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition macros.h:19