7 #include "flutter/fml/trace_event.h"
8 #include "flutter/lib/ui/window/platform_message.h"
9 #include "flutter/lib/ui/window/platform_message_response.h"
17 @property(nonatomic, readonly) dispatch_queue_t
queue;
21 - (instancetype)init {
24 _queue = dispatch_queue_create(
"FLTSerialTaskQueue", DISPATCH_QUEUE_SERIAL);
29 - (void)dispatch:(dispatch_block_t)block {
30 dispatch_async(
self.
queue, block);
36 NSObject<FlutterTaskQueue>* PlatformMessageHandlerIos::MakeBackgroundTaskQueue() {
40 PlatformMessageHandlerIos::PlatformMessageHandlerIos(
41 fml::RefPtr<fml::TaskRunner> platform_task_runner)
42 : platform_task_runner_(std::move(platform_task_runner)) {}
47 fml::RefPtr<flutter::PlatformMessageResponse> completer = message->response();
53 std::lock_guard lock(message_handlers_mutex_);
54 auto it = message_handlers_.find(message->channel());
55 if (it != message_handlers_.end()) {
56 handler_info = it->second;
62 if (message->hasData()) {
67 TRACE_EVENT_ASYNC_BEGIN1(
"flutter",
"PlatformChannel ScheduleHandler", platform_message_id,
68 "channel", message->channel().c_str());
69 dispatch_block_t run_handler = ^{
70 handler(data, ^(NSData* reply) {
71 TRACE_EVENT_ASYNC_END0(
"flutter",
"PlatformChannel ScheduleHandler", platform_message_id);
77 completer->CompleteEmpty();
84 [handler_info.task_queue.get() dispatch:run_handler];
86 dispatch_async(dispatch_get_main_queue(), run_handler);
90 completer->CompleteEmpty();
102 std::unique_ptr<fml::Mapping> mapping) {
116 NSObject<FlutterTaskQueue>* task_queue) {
117 FML_CHECK(platform_task_runner_->RunsTasksOnCurrentThread());
121 FML_CHECK(!task_queue || [task_queue respondsToSelector:
@selector(dispatch:)]);
123 std::lock_guard lock(message_handlers_mutex_);
124 message_handlers_.erase(channel);
126 message_handlers_[channel] = {
128 fml::scoped_nsprotocol(
static_cast<NSObject<FlutterTaskQueueDispatch>*
>(task_queue)),
130 fml::ScopedBlock<FlutterBinaryMessageHandler>{
131 handler, fml::scoped_policy::OwnershipPolicy::kRetain},