Repository navigation
feat: Expose PostPlatformThreadTask and IsPlatformThread to PluginRegistrarWindows - #191140
Conversation
7139599 to
517ef7f
Compare
517ef7f to
562a8d2
Compare
562a8d2 to
643ca13
Compare
There was a problem hiding this comment.
Code Review
This pull request introduces APIs to check if the current thread is the platform thread and to post tasks to the platform thread from the Windows plugin registrar. Feedback suggests adding defensive null checks for the registrar parameter in the newly added C APIs to prevent potential null-pointer dereferences and memory leaks.
| delete static_cast<std::function<void()>*>(user_data); | ||
| }, | ||
| /*user_data=*/new std::function<void()>(std::move(callback))); | ||
| } |
There was a problem hiding this comment.
Copied from flutter_engine.cc
| TEST(PluginRegistrarWindowsTest, IsPlatformThread) { | ||
| auto windows_api = std::make_unique<TestWindowsApi>(); | ||
| EXPECT_CALL(*windows_api, PluginRegistrarGetView) | ||
| .WillRepeatedly(Return(nullptr)); |
There was a problem hiding this comment.
The check for PluginRegistrarGetView is probably irrelevant for this test, I left it in, because the other tests define it, too. But we can also remove it from all thread tests.
| EXPECT_EQ(result, 7); | ||
| } | ||
|
|
||
| TEST(PluginRegistrarWindowsTest, IsPlatformThread) { |
There was a problem hiding this comment.
Could you also add tests on the C APIs directly? See:
There was a problem hiding this comment.
@loic-sharma
Yikes, sorry my tests were sloppy. To be honest I am not that familiar with C(++), as I would wish to be.
I added:
- C API tests for PluginRegistrarIsPlatformThread
- C API tests for PluginRegistrarPostPlatformThreadTaskFromPlatformThread. I purposely did not duplicate all existing tests, as it is basically only a forward
Also I did ensure on existing tests, that
- on_cancel is not called, when task runs successfully
- if on_cancel is called, the callback does not leak into memory
There was a problem hiding this comment.
Thanks for the updates!
And no worries. I'm also not as familiar with C++ as I'd like after almost 15 years 😂
538bf40 to
6e7e232
Compare
loic-sharma
left a comment
There was a problem hiding this comment.
LGTM, thanks for the wonderful contribution!
|
@mattkae can you have a look for the second review? Thx for the time. |
|
autosubmit label was removed for flutter/flutter/191140, because The base commit of the PR is older than 7 days and can not be merged. Please merge the latest changes from the main into this branch and resubmit the PR. |
|
Thank you all! Unfortunately I cannot merge back from master, otherwise my approvals get revoked. |
6e7e232 to
3e37fcf
Compare
|
Sorry I am so chatty today. I think master should be merged before reapplying autosubmit again. The test probably fails due to trying getting an engine build which doesn't exist (from a failed mac build?). |
3e37fcf to
5f6b178
Compare
No worries! I will merge up, then retry. Fickle CI 😅 |
…istrarWindows (flutter#191140) Plugins also should be able to post to the platform thread on windows. This is especially important for platform channel event handling, as Windows platform events are mostly emitted by another thread. Closes flutter#190089 Formerly blocked by flutter#193411 For transparency: Claude assisted code ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [AI contribution guidelines]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
Plugins also should be able to post to the platform thread on windows.
This is especially important for platform channel event handling, as Windows platform events are mostly emitted by another thread.
Closes #190089
Formerly blocked by #193411
For transparency: Claude assisted code
Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assistbot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.