Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 5c670da

Browse files
committed
Migrate FlutterDartVMServicePublisher to ARC
1 parent 76a270f commit 5c670da

File tree

3 files changed

+19
-23
lines changed

3 files changed

+19
-23
lines changed

shell/platform/darwin/ios/BUILD.gn

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ source_set("flutter_framework_source_arc") {
5959
public_configs = [ "//flutter:config" ]
6060

6161
sources = [
62+
"framework/Source/FlutterDartVMServicePublisher.h",
63+
"framework/Source/FlutterDartVMServicePublisher.mm",
6264
"framework/Source/FlutterMetalLayer.h",
6365
"framework/Source/FlutterMetalLayer.mm",
6466
"framework/Source/FlutterRestorationPlugin.h",
@@ -78,6 +80,8 @@ source_set("flutter_framework_source_arc") {
7880
"UIKit.framework",
7981
"IOSurface.framework",
8082
]
83+
84+
deps += [ "//flutter/runtime" ]
8185
}
8286

8387
source_set("flutter_framework_source") {
@@ -98,8 +102,6 @@ source_set("flutter_framework_source") {
98102
"framework/Source/FlutterChannelKeyResponder.mm",
99103
"framework/Source/FlutterDartProject.mm",
100104
"framework/Source/FlutterDartProject_Internal.h",
101-
"framework/Source/FlutterDartVMServicePublisher.h",
102-
"framework/Source/FlutterDartVMServicePublisher.mm",
103105
"framework/Source/FlutterEmbedderKeyResponder.h",
104106
"framework/Source/FlutterEmbedderKeyResponder.mm",
105107
"framework/Source/FlutterEngine.mm",

shell/platform/darwin/ios/framework/Source/FlutterDartVMServicePublisher.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
- (instancetype)init NS_UNAVAILABLE;
1515
+ (instancetype)new NS_UNAVAILABLE;
1616

17-
@property(nonatomic, retain, readonly) NSURL* url;
17+
@property(nonatomic, strong, readonly) NSURL* url;
1818

1919
@end
2020

shell/platform/darwin/ios/framework/Source/FlutterDartVMServicePublisher.mm

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@ - (instancetype)initWithEnableVMServicePublication:(BOOL)enableVMServicePublicat
4040
#include <net/if.h>
4141

4242
#include "flutter/fml/logging.h"
43-
#include "flutter/fml/memory/weak_ptr.h"
4443
#include "flutter/fml/message_loop.h"
4544
#include "flutter/fml/platform/darwin/scoped_nsobject.h"
4645
#include "flutter/runtime/dart_service_isolate.h"
46+
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"
47+
48+
FLUTTER_ASSERT_ARC
4749

4850
@protocol FlutterDartVMServicePublisherDelegate
4951
- (void)publishServiceProtocolPort:(NSURL*)uri;
@@ -54,7 +56,7 @@ @interface FlutterDartVMServicePublisher ()
5456
+ (NSData*)createTxtData:(NSURL*)url;
5557

5658
@property(readonly, class) NSString* serviceName;
57-
@property(readonly) fml::scoped_nsobject<NSObject<FlutterDartVMServicePublisherDelegate>> delegate;
59+
@property(readonly) NSObject<FlutterDartVMServicePublisherDelegate>* delegate;
5860
@property(nonatomic, readwrite) NSURL* url;
5961
@property(readonly) BOOL enableVMServicePublication;
6062

@@ -139,32 +141,30 @@ static void DNSSD_API RegistrationCallback(DNSServiceRef sdRef,
139141

140142
@implementation FlutterDartVMServicePublisher {
141143
flutter::DartServiceIsolate::CallbackHandle _callbackHandle;
142-
std::unique_ptr<fml::WeakPtrFactory<FlutterDartVMServicePublisher>> _weakFactory;
143144
}
144145

145146
- (instancetype)initWithEnableVMServicePublication:(BOOL)enableVMServicePublication {
146147
self = [super init];
147148
NSAssert(self, @"Super must not return null on init.");
148149

149-
_delegate.reset([[DartVMServiceDNSServiceDelegate alloc] init]);
150+
_delegate = [[DartVMServiceDNSServiceDelegate alloc] init];
150151
_enableVMServicePublication = enableVMServicePublication;
151-
_weakFactory = std::make_unique<fml::WeakPtrFactory<FlutterDartVMServicePublisher>>(self);
152+
__weak __typeof(self) weakSelf = self;
152153

153154
fml::MessageLoop::EnsureInitializedForCurrentThread();
154155

155156
_callbackHandle = flutter::DartServiceIsolate::AddServerStatusCallback(
156-
[weak = _weakFactory->GetWeakPtr(),
157-
runner = fml::MessageLoop::GetCurrent().GetTaskRunner()](const std::string& uri) {
157+
[weakSelf, runner = fml::MessageLoop::GetCurrent().GetTaskRunner()](const std::string& uri) {
158158
if (!uri.empty()) {
159-
runner->PostTask([weak, uri]() {
159+
runner->PostTask([weakSelf, uri]() {
160160
// uri comes in as something like 'http://127.0.0.1:XXXXX/' where XXXXX is the port
161161
// number.
162-
if (weak) {
163-
NSURL* url = [[[NSURL alloc]
164-
initWithString:[NSString stringWithUTF8String:uri.c_str()]] autorelease];
165-
weak.get().url = url;
166-
if (weak.get().enableVMServicePublication) {
167-
[[weak.get() delegate] publishServiceProtocolPort:url];
162+
if (weakSelf) {
163+
NSURL* url =
164+
[[NSURL alloc] initWithString:[NSString stringWithUTF8String:uri.c_str()]];
165+
weakSelf.url = url;
166+
if (weakSelf.enableVMServicePublication) {
167+
[[weakSelf delegate] publishServiceProtocolPort:url];
168168
}
169169
}
170170
});
@@ -190,15 +190,9 @@ + (NSData*)createTxtData:(NSURL*)url {
190190
}
191191

192192
- (void)dealloc {
193-
// It will be destroyed and invalidate its weak pointers
194-
// before any other members are destroyed.
195-
_weakFactory.reset();
196-
197193
[_delegate stopService];
198-
[_url release];
199194

200195
flutter::DartServiceIsolate::RemoveServerStatusCallback(_callbackHandle);
201-
[super dealloc];
202196
}
203197
@end
204198

0 commit comments

Comments
 (0)