Flutter Engine
platform_message_response_android.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/android/platform_message_response_android.h"
6 
7 #include "flutter/fml/make_copyable.h"
8 #include "flutter/shell/platform/android/jni/platform_view_android_jni.h"
9 
10 namespace flutter {
11 
12 PlatformMessageResponseAndroid::PlatformMessageResponseAndroid(
13  int response_id,
14  std::shared_ptr<PlatformViewAndroidJNI> jni_facade,
15  fml::RefPtr<fml::TaskRunner> platform_task_runner)
16  : response_id_(response_id),
17  jni_facade_(jni_facade),
18  platform_task_runner_(std::move(platform_task_runner)) {}
19 
20 PlatformMessageResponseAndroid::~PlatformMessageResponseAndroid() = default;
21 
22 // |flutter::PlatformMessageResponse|
23 void PlatformMessageResponseAndroid::Complete(
24  std::unique_ptr<fml::Mapping> data) {
25  platform_task_runner_->PostTask(
26  fml::MakeCopyable([response_id = response_id_, //
27  data = std::move(data), //
28  jni_facade = jni_facade_]() mutable {
29  jni_facade->FlutterViewHandlePlatformMessageResponse(response_id,
30  std::move(data));
31  }));
32 }
33 
34 // |flutter::PlatformMessageResponse|
35 void PlatformMessageResponseAndroid::CompleteEmpty() {
36  platform_task_runner_->PostTask(
37  fml::MakeCopyable([response_id = response_id_, //
38  jni_facade = jni_facade_ //
39  ]() {
40  // Make the response call into Java.
41  jni_facade->FlutterViewHandlePlatformMessageResponse(response_id,
42  nullptr);
43  }));
44 }
45 } // namespace flutter
Definition: ref_ptr.h:252
internal::CopyableLambda< T > MakeCopyable(T lambda)
Definition: make_copyable.h:57