Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
platform_message_handler_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_handler_android.h"
6
7namespace flutter {
8
10 const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade)
11 : jni_facade_(jni_facade) {}
12
14 int response_id,
15 std::unique_ptr<fml::Mapping> mapping) {
16 // Called from any thread.
17 if (!response_id) {
18 return;
19 }
20 // TODO(gaaclarke): Move the jump to the ui thread here from
21 // PlatformMessageResponseDart so we won't need to use a mutex anymore.
23 {
24 std::lock_guard lock(pending_responses_mutex_);
25 auto it = pending_responses_.find(response_id);
26 if (it == pending_responses_.end()) {
27 return;
28 }
29 message_response = std::move(it->second);
30 pending_responses_.erase(it);
31 }
32
33 message_response->Complete(std::move(mapping));
34}
35
37 int response_id) {
38 // Called from any thread.
39 if (!response_id) {
40 return;
41 }
43 {
44 std::lock_guard lock(pending_responses_mutex_);
45 auto it = pending_responses_.find(response_id);
46 if (it == pending_responses_.end()) {
47 return;
48 }
49 message_response = std::move(it->second);
50 pending_responses_.erase(it);
51 }
52 message_response->CompleteEmpty();
53}
54
55// |PlatformView|
57 std::unique_ptr<flutter::PlatformMessage> message) {
58 // Called from any thread.
59 int response_id = next_response_id_.fetch_add(1);
60 if (auto response = message->response()) {
61 std::lock_guard lock(pending_responses_mutex_);
62 pending_responses_[response_id] = response;
63 }
64 // This call can re-enter in InvokePlatformMessageXxxResponseCallback.
65 jni_facade_->FlutterViewHandlePlatformMessage(std::move(message),
66 response_id);
67}
68
69} // namespace flutter
void InvokePlatformMessageEmptyResponseCallback(int response_id) override
void InvokePlatformMessageResponseCallback(int response_id, std::unique_ptr< fml::Mapping > mapping) override
PlatformMessageHandlerAndroid(const std::shared_ptr< PlatformViewAndroidJNI > &jni_facade)
void HandlePlatformMessage(std::unique_ptr< PlatformMessage > message) override
Win32Message message