Flutter Engine
platform_message_response_dart.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/lib/ui/window/platform_message_response_dart.h"
6 
7 #include <utility>
8 
9 #include "flutter/common/task_runners.h"
10 #include "flutter/fml/make_copyable.h"
14 
15 namespace flutter {
16 
19  fml::RefPtr<fml::TaskRunner> ui_task_runner)
20  : callback_(std::move(callback)),
21  ui_task_runner_(std::move(ui_task_runner)) {}
22 
24  if (!callback_.is_empty()) {
26  [callback = std::move(callback_)]() mutable { callback.Clear(); }));
27  }
28 }
29 
30 void PlatformMessageResponseDart::Complete(std::unique_ptr<fml::Mapping> data) {
31  if (callback_.is_empty()) {
32  return;
33  }
35  is_complete_ = true;
37  [callback = std::move(callback_), data = std::move(data)]() mutable {
38  std::shared_ptr<tonic::DartState> dart_state =
39  callback.dart_state().lock();
40  if (!dart_state) {
41  return;
42  }
43  tonic::DartState::Scope scope(dart_state);
44 
45  Dart_Handle byte_buffer =
46  tonic::DartByteData::Create(data->GetMapping(), data->GetSize());
47  tonic::DartInvoke(callback.Release(), {byte_buffer});
48  }));
49 }
50 
52  if (callback_.is_empty()) {
53  return;
54  }
56  is_complete_ = true;
58  fml::MakeCopyable([callback = std::move(callback_)]() mutable {
59  std::shared_ptr<tonic::DartState> dart_state =
60  callback.dart_state().lock();
61  if (!dart_state) {
62  return;
63  }
64  tonic::DartState::Scope scope(dart_state);
65  tonic::DartInvoke(callback.Release(), {Dart_Null()});
66  }));
67 }
68 
69 } // namespace flutter
#define FML_DCHECK(condition)
Definition: logging.h:86
PlatformMessageResponseDart(tonic::DartPersistentValue callback, fml::RefPtr< fml::TaskRunner > ui_task_runner)
Definition: ref_ptr.h:252
virtual void PostTask(const fml::closure &task)
Definition: task_runner.cc:24
Dart_Handle DartInvoke(Dart_Handle closure, std::initializer_list< Dart_Handle > args)
Definition: dart_invoke.cc:20
internal::CopyableLambda< T > MakeCopyable(T lambda)
Definition: make_copyable.h:57
void Complete(std::unique_ptr< fml::Mapping > data) override
static Dart_Handle Create(const void *data, size_t length)