From 374dc4a4e3ecf72a46e44c582aabff9b62db7ecb Mon Sep 17 00:00:00 2001 From: Jenn Magder Date: Wed, 1 May 2024 14:07:07 -0700 Subject: [PATCH] Migrate PlatformMessageHandlerIos to ARC (flutter/engine#52226) Smart pointers support ARC as of https://github.com/flutter/engine/pull/47612, and the unit tests were migrated in https://github.com/flutter/engine/pull/48162. Migrate `PlatformMessageHandlerIos` from MRC to ARC. Clean up the `#include`s. Part of https://github.com/flutter/flutter/issues/137801. --- .../shell/platform/darwin/ios/BUILD.gn | 4 ++-- .../darwin/ios/platform_message_handler_ios.h | 5 +--- .../ios/platform_message_handler_ios.mm | 23 ++++++++----------- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/engine/src/flutter/shell/platform/darwin/ios/BUILD.gn b/engine/src/flutter/shell/platform/darwin/ios/BUILD.gn index 0664940544a..2ddfd93ab10 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/BUILD.gn +++ b/engine/src/flutter/shell/platform/darwin/ios/BUILD.gn @@ -117,6 +117,8 @@ source_set("flutter_framework_source_arc") { "ios_surface_metal_skia.mm", "ios_surface_software.h", "ios_surface_software.mm", + "platform_message_handler_ios.h", + "platform_message_handler_ios.mm", "rendering_api_selection.h", "rendering_api_selection.mm", ] @@ -180,8 +182,6 @@ source_set("flutter_framework_source") { "framework/Source/accessibility_text_entry.mm", "ios_external_view_embedder.h", "ios_external_view_embedder.mm", - "platform_message_handler_ios.h", - "platform_message_handler_ios.mm", "platform_view_ios.h", "platform_view_ios.mm", ] diff --git a/engine/src/flutter/shell/platform/darwin/ios/platform_message_handler_ios.h b/engine/src/flutter/shell/platform/darwin/ios/platform_message_handler_ios.h index 6d49ae506f4..b212e222307 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/platform_message_handler_ios.h +++ b/engine/src/flutter/shell/platform/darwin/ios/platform_message_handler_ios.h @@ -5,13 +5,10 @@ #ifndef FLUTTER_SHELL_PLATFORM_DARWIN_IOS_PLATFORM_MESSAGE_HANDLER_IOS_H_ #define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_PLATFORM_MESSAGE_HANDLER_IOS_H_ -#include - -#include "flutter/common/task_runners.h" #include "flutter/fml/platform/darwin/scoped_block.h" #include "flutter/fml/platform/darwin/scoped_nsobject.h" +#include "flutter/fml/task_runner.h" #include "flutter/shell/common/platform_message_handler.h" -#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterBinaryMessenger.h" #import "flutter/shell/platform/darwin/ios/flutter_task_queue_dispatch.h" namespace flutter { diff --git a/engine/src/flutter/shell/platform/darwin/ios/platform_message_handler_ios.mm b/engine/src/flutter/shell/platform/darwin/ios/platform_message_handler_ios.mm index 38706459e00..e1257b56ffb 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/platform_message_handler_ios.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/platform_message_handler_ios.mm @@ -4,15 +4,17 @@ #import "flutter/shell/platform/darwin/ios/platform_message_handler_ios.h" -#import "flutter/fml/trace_event.h" -#import "flutter/lib/ui/window/platform_message.h" -#import "flutter/shell/platform/darwin/common/buffer_conversions.h" -#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterBinaryMessenger.h" +#include "flutter/fml/trace_event.h" +#include "flutter/lib/ui/window/platform_message.h" +#include "flutter/lib/ui/window/platform_message_response.h" +#include "flutter/shell/platform/darwin/common/buffer_conversions.h" + +FLUTTER_ASSERT_ARC static uint64_t platform_message_counter = 1; @interface FLTSerialTaskQueue : NSObject -@property(nonatomic, strong) dispatch_queue_t queue; +@property(nonatomic, readonly) dispatch_queue_t queue; @end @implementation FLTSerialTaskQueue @@ -24,11 +26,6 @@ static uint64_t platform_message_counter = 1; return self; } -- (void)dealloc { - dispatch_release(_queue); - [super dealloc]; -} - - (void)dispatch:(dispatch_block_t)block { dispatch_async(self.queue, block); } @@ -37,7 +34,7 @@ static uint64_t platform_message_counter = 1; namespace flutter { NSObject* PlatformMessageHandlerIos::MakeBackgroundTaskQueue() { - return [[[FLTSerialTaskQueue alloc] init] autorelease]; + return [[FLTSerialTaskQueue alloc] init]; } PlatformMessageHandlerIos::PlatformMessageHandlerIos( @@ -127,8 +124,8 @@ void PlatformMessageHandlerIos::SetMessageHandler(const std::string& channel, message_handlers_.erase(channel); if (handler) { message_handlers_[channel] = { - .task_queue = fml::scoped_nsprotocol( - [static_cast*>(task_queue) retain]), + .task_queue = + fml::scoped_nsprotocol(static_cast*>(task_queue)), .handler = fml::ScopedBlock{ handler, fml::scoped_policy::OwnershipPolicy::kRetain},