diff --git a/shell/platform/darwin/ios/BUILD.gn b/shell/platform/darwin/ios/BUILD.gn index 39e17b1d84648..ca9dfb7453cd1 100644 --- a/shell/platform/darwin/ios/BUILD.gn +++ b/shell/platform/darwin/ios/BUILD.gn @@ -61,6 +61,8 @@ source_set("flutter_framework_source_arc") { sources = [ "framework/Source/FlutterCallbackCache.mm", "framework/Source/FlutterCallbackCache_Internal.h", + "framework/Source/FlutterDartVMServicePublisher.h", + "framework/Source/FlutterDartVMServicePublisher.mm", "framework/Source/FlutterEmbedderKeyResponder.h", "framework/Source/FlutterEmbedderKeyResponder.mm", "framework/Source/FlutterKeyPrimaryResponder.h", @@ -89,6 +91,7 @@ source_set("flutter_framework_source_arc") { deps += [ "//flutter/lib/ui", + "//flutter/runtime", "//flutter/shell/platform/embedder:embedder_as_internal_library", ] } @@ -109,8 +112,6 @@ source_set("flutter_framework_source") { "framework/Source/FlutterChannelKeyResponder.mm", "framework/Source/FlutterDartProject.mm", "framework/Source/FlutterDartProject_Internal.h", - "framework/Source/FlutterDartVMServicePublisher.h", - "framework/Source/FlutterDartVMServicePublisher.mm", "framework/Source/FlutterEngine.mm", "framework/Source/FlutterEngineGroup.mm", "framework/Source/FlutterEngine_Internal.h", diff --git a/shell/platform/darwin/ios/framework/Source/FlutterDartVMServicePublisher.h b/shell/platform/darwin/ios/framework/Source/FlutterDartVMServicePublisher.h index 4feda093f5edc..7870ef8079187 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterDartVMServicePublisher.h +++ b/shell/platform/darwin/ios/framework/Source/FlutterDartVMServicePublisher.h @@ -14,7 +14,7 @@ - (instancetype)init NS_UNAVAILABLE; + (instancetype)new NS_UNAVAILABLE; -@property(nonatomic, retain, readonly) NSURL* url; +@property(nonatomic, readonly) NSURL* url; @end diff --git a/shell/platform/darwin/ios/framework/Source/FlutterDartVMServicePublisher.mm b/shell/platform/darwin/ios/framework/Source/FlutterDartVMServicePublisher.mm index 38288a1f247e2..597bc5b8056c6 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterDartVMServicePublisher.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterDartVMServicePublisher.mm @@ -40,10 +40,12 @@ - (instancetype)initWithEnableVMServicePublication:(BOOL)enableVMServicePublicat #include #include "flutter/fml/logging.h" -#include "flutter/fml/memory/weak_ptr.h" #include "flutter/fml/message_loop.h" #include "flutter/fml/platform/darwin/scoped_nsobject.h" #include "flutter/runtime/dart_service_isolate.h" +#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h" + +FLUTTER_ASSERT_ARC @protocol FlutterDartVMServicePublisherDelegate - (void)publishServiceProtocolPort:(NSURL*)uri; @@ -54,7 +56,7 @@ @interface FlutterDartVMServicePublisher () + (NSData*)createTxtData:(NSURL*)url; @property(readonly, class) NSString* serviceName; -@property(readonly) fml::scoped_nsobject> delegate; +@property(readonly) NSObject* delegate; @property(nonatomic, readwrite) NSURL* url; @property(readonly) BOOL enableVMServicePublication; @@ -139,32 +141,31 @@ static void DNSSD_API RegistrationCallback(DNSServiceRef sdRef, @implementation FlutterDartVMServicePublisher { flutter::DartServiceIsolate::CallbackHandle _callbackHandle; - std::unique_ptr> _weakFactory; } - (instancetype)initWithEnableVMServicePublication:(BOOL)enableVMServicePublication { self = [super init]; NSAssert(self, @"Super must not return null on init."); - _delegate.reset([[DartVMServiceDNSServiceDelegate alloc] init]); + _delegate = [[DartVMServiceDNSServiceDelegate alloc] init]; _enableVMServicePublication = enableVMServicePublication; - _weakFactory = std::make_unique>(self); + __weak __typeof(self) weakSelf = self; fml::MessageLoop::EnsureInitializedForCurrentThread(); _callbackHandle = flutter::DartServiceIsolate::AddServerStatusCallback( - [weak = _weakFactory->GetWeakPtr(), - runner = fml::MessageLoop::GetCurrent().GetTaskRunner()](const std::string& uri) { + [weakSelf, runner = fml::MessageLoop::GetCurrent().GetTaskRunner()](const std::string& uri) { if (!uri.empty()) { - runner->PostTask([weak, uri]() { + runner->PostTask([weakSelf, uri]() { + FlutterDartVMServicePublisher* strongSelf = weakSelf; // uri comes in as something like 'http://127.0.0.1:XXXXX/' where XXXXX is the port // number. - if (weak) { - NSURL* url = [[[NSURL alloc] - initWithString:[NSString stringWithUTF8String:uri.c_str()]] autorelease]; - weak.get().url = url; - if (weak.get().enableVMServicePublication) { - [[weak.get() delegate] publishServiceProtocolPort:url]; + if (strongSelf) { + NSURL* url = + [[NSURL alloc] initWithString:[NSString stringWithUTF8String:uri.c_str()]]; + strongSelf.url = url; + if (strongSelf.enableVMServicePublication) { + [[strongSelf delegate] publishServiceProtocolPort:url]; } } }); @@ -190,15 +191,9 @@ + (NSData*)createTxtData:(NSURL*)url { } - (void)dealloc { - // It will be destroyed and invalidate its weak pointers - // before any other members are destroyed. - _weakFactory.reset(); - [_delegate stopService]; - [_url release]; flutter::DartServiceIsolate::RemoveServerStatusCallback(_callbackHandle); - [super dealloc]; } @end