Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS: Eliminate ScopedBlock, ScopedTypeRef, ScopedPolicy #56410

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -42729,12 +42729,9 @@ ORIGIN: ../../../flutter/fml/platform/darwin/message_loop_darwin.mm + ../../../f
ORIGIN: ../../../flutter/fml/platform/darwin/paths_darwin.mm + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/fml/platform/darwin/platform_version.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/fml/platform/darwin/platform_version.mm + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/fml/platform/darwin/scoped_block.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/fml/platform/darwin/scoped_block.mm + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/fml/platform/darwin/scoped_nsautorelease_pool.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/fml/platform/darwin/scoped_nsautorelease_pool.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/fml/platform/darwin/scoped_policy.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/fml/platform/darwin/scoped_typeref.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/fml/platform/darwin/string_range_sanitization.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/fml/platform/darwin/string_range_sanitization.mm + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/fml/platform/fuchsia/log_interest_listener.cc + ../../../flutter/LICENSE
Expand Down Expand Up @@ -45591,12 +45588,9 @@ FILE: ../../../flutter/fml/platform/darwin/message_loop_darwin.mm
FILE: ../../../flutter/fml/platform/darwin/paths_darwin.mm
FILE: ../../../flutter/fml/platform/darwin/platform_version.h
FILE: ../../../flutter/fml/platform/darwin/platform_version.mm
FILE: ../../../flutter/fml/platform/darwin/scoped_block.h
FILE: ../../../flutter/fml/platform/darwin/scoped_block.mm
FILE: ../../../flutter/fml/platform/darwin/scoped_nsautorelease_pool.cc
FILE: ../../../flutter/fml/platform/darwin/scoped_nsautorelease_pool.h
FILE: ../../../flutter/fml/platform/darwin/scoped_policy.h
FILE: ../../../flutter/fml/platform/darwin/scoped_typeref.h
FILE: ../../../flutter/fml/platform/darwin/string_range_sanitization.h
FILE: ../../../flutter/fml/platform/darwin/string_range_sanitization.mm
FILE: ../../../flutter/fml/platform/fuchsia/log_interest_listener.cc
Expand Down
3 changes: 0 additions & 3 deletions fml/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,9 @@ source_set("fml") {
"platform/darwin/paths_darwin.mm",
"platform/darwin/platform_version.h",
"platform/darwin/platform_version.mm",
"platform/darwin/scoped_block.h",
"platform/darwin/scoped_block.mm",
"platform/darwin/scoped_nsautorelease_pool.cc",
"platform/darwin/scoped_nsautorelease_pool.h",
"platform/darwin/scoped_policy.h",
"platform/darwin/scoped_typeref.h",
"platform/darwin/string_range_sanitization.h",
"platform/darwin/string_range_sanitization.mm",
]
Expand Down
46 changes: 0 additions & 46 deletions fml/platform/darwin/scoped_block.h

This file was deleted.

11 changes: 0 additions & 11 deletions fml/platform/darwin/scoped_block.mm

This file was deleted.

146 changes: 0 additions & 146 deletions fml/platform/darwin/scoped_typeref.h

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

#include "flutter/fml/macros.h"
#include "flutter/fml/make_copyable.h"
#include "flutter/fml/platform/darwin/scoped_block.h"
#include "flutter/fml/task_runner.h"
#include "flutter/lib/ui/window/platform_message_response.h"
#import "flutter/shell/platform/darwin/common/buffer_conversions.h"
Expand All @@ -30,7 +29,7 @@ class PlatformMessageResponseDarwin : public flutter::PlatformMessageResponse {

~PlatformMessageResponseDarwin() override;

fml::ScopedBlock<PlatformMessageResponseCallback> callback_;
PlatformMessageResponseCallback callback_;
Copy link
Member Author

@cbracken cbracken Nov 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference, the typedef is here:

typedef void (^PlatformMessageResponseCallback)(NSData*);

fml::RefPtr<fml::TaskRunner> platform_task_runner_;

FML_FRIEND_MAKE_REF_COUNTED(PlatformMessageResponseDarwin);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,20 @@
PlatformMessageResponseDarwin::PlatformMessageResponseDarwin(
PlatformMessageResponseCallback callback,
fml::RefPtr<fml::TaskRunner> platform_task_runner)
: callback_(callback, fml::scoped_policy::OwnershipPolicy::kRetain),
platform_task_runner_(std::move(platform_task_runner)) {}
: callback_(callback), platform_task_runner_(std::move(platform_task_runner)) {}

PlatformMessageResponseDarwin::~PlatformMessageResponseDarwin() = default;

void PlatformMessageResponseDarwin::Complete(std::unique_ptr<fml::Mapping> data) {
fml::RefPtr<PlatformMessageResponseDarwin> self(this);
platform_task_runner_->PostTask(fml::MakeCopyable([self, data = std::move(data)]() mutable {
self->callback_.get()(CopyMappingPtrToNSData(std::move(data)));
self->callback_(CopyMappingPtrToNSData(std::move(data)));
}));
}

void PlatformMessageResponseDarwin::CompleteEmpty() {
fml::RefPtr<PlatformMessageResponseDarwin> self(this);
platform_task_runner_->PostTask(
fml::MakeCopyable([self]() mutable { self->callback_.get()(nil); }));
platform_task_runner_->PostTask(fml::MakeCopyable([self]() mutable { self->callback_(nil); }));
}

} // namespace flutter
3 changes: 1 addition & 2 deletions shell/platform/darwin/ios/platform_message_handler_ios.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#ifndef FLUTTER_SHELL_PLATFORM_DARWIN_IOS_PLATFORM_MESSAGE_HANDLER_IOS_H_
#define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_PLATFORM_MESSAGE_HANDLER_IOS_H_

#include "flutter/fml/platform/darwin/scoped_block.h"
#include "flutter/fml/task_runner.h"
#include "flutter/shell/common/platform_message_handler.h"
#import "flutter/shell/platform/darwin/ios/flutter_task_queue_dispatch.h"
Expand Down Expand Up @@ -33,7 +32,7 @@ class PlatformMessageHandlerIos : public PlatformMessageHandler {

struct HandlerInfo {
NSObject<FlutterTaskQueueDispatch>* task_queue;
fml::ScopedBlock<FlutterBinaryMessageHandler> handler;
FlutterBinaryMessageHandler handler;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typedef is here:

typedef void (^FlutterBinaryMessageHandler)(NSData* _Nullable message, FlutterBinaryReply reply);

};

private:
Expand Down
4 changes: 1 addition & 3 deletions shell/platform/darwin/ios/platform_message_handler_ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,7 @@ - (void)dispatch:(dispatch_block_t)block {
if (handler) {
message_handlers_[channel] = {
.task_queue = (NSObject<FlutterTaskQueueDispatch>*)task_queue,
.handler =
fml::ScopedBlock<FlutterBinaryMessageHandler>{
handler, fml::scoped_policy::OwnershipPolicy::kRetain},
.handler = handler,
};
}
}
Expand Down