Skip to content

Commit

Permalink
iOS: Eliminate ScopedBlock, ScopedTypeRef
Browse files Browse the repository at this point in the history
Eliminates the two remaining uses of ScopedBlock and with it,
ScopedTypeRef which was only used by ScopedBlock. ARC automatically
generates the necessary block copy/retain/release calls, including
moving blocks to the heap during a retain so manual
_Block_copy/_Block_release calls are no longer required.

Issue: flutter/flutter#137801
  • Loading branch information
cbracken committed Nov 6, 2024
1 parent 58ac1da commit e016862
Show file tree
Hide file tree
Showing 9 changed files with 6 additions and 224 deletions.
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_;
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;
};

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

0 comments on commit e016862

Please sign in to comment.