-
Notifications
You must be signed in to change notification settings - Fork 6k
Implemented threadsafe platform channel replies on windows #36909
Changes from 1 commit
e64a9ae
cf133e7
e689f0a
c7a5376
77a85e9
06d1b05
da83222
cd82e4d
5781f32
e18fafc
3f519f4
81da72e
1794f65
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,17 +36,30 @@ void ForwardToHandler(FlutterDesktopMessengerRef messenger, | |
| const FlutterDesktopMessage* message, | ||
| void* user_data) { | ||
| auto* response_handle = message->response_handle; | ||
| BinaryReply reply_handler = [messenger, response_handle]( | ||
| auto messenger_ptr = std::shared_ptr<FlutterDesktopMessenger>( | ||
| FlutterDesktopMessengerAddRef(messenger), | ||
| &FlutterDesktopMessengerRelease); | ||
| BinaryReply reply_handler = [messenger_ptr, response_handle]( | ||
| const uint8_t* reply, | ||
| size_t reply_size) mutable { | ||
| auto lock = std::unique_ptr<FlutterDesktopMessenger, | ||
| decltype(&FlutterDesktopMessengerUnlock)>( | ||
| FlutterDesktopMessengerLock(messenger_ptr.get()), | ||
| &FlutterDesktopMessengerUnlock); | ||
| if (!FlutterDesktopMessengerIsAvailable(messenger_ptr.get())) { | ||
| std::cerr << "Error: Responding to platform channel after the engine has" | ||
| "been deleted." | ||
gaaclarke marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| << std::endl; | ||
| return; | ||
| } | ||
| if (!response_handle) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional nit: this block is entirely local, so could be done before acquiring the lock instead.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IsAvailable has to happen inside the safety of the lock.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My comment was on this code: which doesn't have any calls to IsAvailable. |
||
| std::cerr << "Error: Response can be set only once. Ignoring " | ||
| "duplicate response." | ||
| << std::endl; | ||
| return; | ||
| } | ||
| FlutterDesktopMessengerSendResponse(messenger, response_handle, reply, | ||
| reply_size); | ||
| FlutterDesktopMessengerSendResponse(messenger_ptr.get(), response_handle, | ||
| reply, reply_size); | ||
| // The engine frees the response handle once | ||
| // FlutterDesktopSendMessageResponse is called. | ||
| response_handle = nullptr; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,8 @@ | |
|
|
||
| #include "flutter/shell/platform/common/client_wrapper/testing/stub_flutter_api.h" | ||
|
|
||
| #include <cassert> | ||
|
|
||
| static flutter::testing::StubFlutterApi* s_stub_implementation; | ||
|
|
||
| namespace flutter { | ||
|
|
@@ -93,6 +95,31 @@ void FlutterDesktopMessengerSetCallback(FlutterDesktopMessengerRef messenger, | |
| } | ||
| } | ||
|
|
||
| FlutterDesktopMessengerRef FlutterDesktopMessengerAddRef( | ||
| FlutterDesktopMessengerRef messenger) { | ||
| assert(false); // not implemented | ||
| return nullptr; | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No existing tests for the client_wrapper actually hit this code. In terms of code coverage it isn't strictly needed since I have coverage in the windows unit tests. |
||
| } | ||
|
|
||
| void FlutterDesktopMessengerRelease(FlutterDesktopMessengerRef messenger) { | ||
| assert(false); // not implemented | ||
| } | ||
|
|
||
| bool FlutterDesktopMessengerIsAvailable(FlutterDesktopMessengerRef messenger) { | ||
| assert(false); // not implemented | ||
| return false; | ||
| } | ||
|
|
||
| FlutterDesktopMessengerRef FlutterDesktopMessengerLock( | ||
| FlutterDesktopMessengerRef messenger) { | ||
| assert(false); // not implemented | ||
| return nullptr; | ||
| } | ||
|
|
||
| void FlutterDesktopMessengerUnlock(FlutterDesktopMessengerRef messenger) { | ||
| assert(false); // not implemented | ||
| } | ||
|
|
||
| FlutterDesktopTextureRegistrarRef FlutterDesktopRegistrarGetTextureRegistrar( | ||
| FlutterDesktopPluginRegistrarRef registrar) { | ||
| return reinterpret_cast<FlutterDesktopTextureRegistrarRef>(1); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.