Flutter Engine
embedder_platform_message_response.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/shell/platform/embedder/embedder_platform_message_response.h"
6 
7 #include "flutter/fml/make_copyable.h"
8 
9 namespace flutter {
10 
13  const Callback& callback)
14  : runner_(std::move(runner)), callback_(callback) {}
15 
17 
18 // |PlatformMessageResponse|
19 void EmbedderPlatformMessageResponse::Complete(
20  std::unique_ptr<fml::Mapping> data) {
21  if (!data) {
22  CompleteEmpty();
23  return;
24  }
25 
26  runner_->PostTask(
27  fml::MakeCopyable([data = std::move(data), callback = callback_]() {
28  callback(data->GetMapping(), data->GetSize());
29  }));
30 }
31 
32 // |PlatformMessageResponse|
33 void EmbedderPlatformMessageResponse::CompleteEmpty() {
34  Complete(std::make_unique<fml::NonOwnedMapping>(nullptr, 0u));
35 }
36 
37 } // namespace flutter
std::function< void(const uint8_t *data, size_t size)> Callback
Definition: ref_ptr.h:252
virtual void PostTask(const fml::closure &task)
Definition: task_runner.cc:24
internal::CopyableLambda< T > MakeCopyable(T lambda)
Definition: make_copyable.h:57
EmbedderPlatformMessageResponse(fml::RefPtr< fml::TaskRunner > runner, const Callback &callback)
~EmbedderPlatformMessageResponse() override
Destroys the message response. Can be called on any thread. Does not execute unfulfilled callbacks...