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: Migrate FlutterEngineGroup to ARC #55503

Merged
merged 5 commits into from
Sep 30, 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
2 changes: 1 addition & 1 deletion shell/platform/darwin/ios/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ source_set("flutter_framework_source_arc") {
"framework/Source/FlutterDartVMServicePublisher.mm",
"framework/Source/FlutterEmbedderKeyResponder.h",
"framework/Source/FlutterEmbedderKeyResponder.mm",
"framework/Source/FlutterEngineGroup.mm",
"framework/Source/FlutterHeadlessDartRunner.mm",
"framework/Source/FlutterKeyPrimaryResponder.h",
"framework/Source/FlutterKeySecondaryResponder.h",
Expand Down Expand Up @@ -182,7 +183,6 @@ source_set("flutter_framework_source") {
# New files are highly encouraged to be in ARC.
# To add new files in ARC, add them to the `flutter_framework_source_arc` target.
"framework/Source/FlutterEngine.mm",
"framework/Source/FlutterEngineGroup.mm",
"framework/Source/FlutterEngine_Internal.h",
"framework/Source/FlutterPlatformPlugin.h",
"framework/Source/FlutterPlatformPlugin.mm",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ FLUTTER_DARWIN_EXPORT
/**
* Arguments passed as a list of string to Dart's entrypoint function.
*/
@property(nonatomic, retain, nullable) NSArray<NSString*>* entrypointArgs;
@property(nonatomic, copy, nullable) NSArray<NSString*>* entrypointArgs;
@end

/**
Expand Down
43 changes: 15 additions & 28 deletions shell/platform/darwin/ios/framework/Source/FlutterEngineGroup.mm
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,30 @@
#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterEngineGroup.h"
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine_Internal.h"

@implementation FlutterEngineGroupOptions

- (void)dealloc {
[_entrypoint release];
[_libraryURI release];
[_initialRoute release];
[_entrypointArgs release];
[super dealloc];
}
FLUTTER_ASSERT_ARC

@implementation FlutterEngineGroupOptions
@end

@interface FlutterEngineGroup ()
@property(nonatomic, copy) NSString* name;
@property(nonatomic, retain) NSMutableArray<NSValue*>* engines;
@property(nonatomic, retain) FlutterDartProject* project;
@property(nonatomic, strong) NSMutableArray<NSValue*>* engines;
@property(nonatomic, copy) FlutterDartProject* project;
@property(nonatomic, assign) NSUInteger enginesCreatedCount;
@end

@implementation FlutterEngineGroup {
int _enginesCreatedCount;
}
@implementation FlutterEngineGroup

- (instancetype)initWithName:(NSString*)name project:(nullable FlutterDartProject*)project {
self = [super init];
if (self) {
_name = [name copy];
_engines = [[NSMutableArray<NSValue*> alloc] init];
_project = [project retain];
_project = project;
}
return self;
}

- (void)dealloc {
[_name release];
[_engines release];
[_project release];
[super dealloc];
}

- (FlutterEngine*)makeEngineWithEntrypoint:(nullable NSString*)entrypoint
libraryURI:(nullable NSString*)libraryURI {
return [self makeEngineWithEntrypoint:entrypoint libraryURI:libraryURI initialRoute:nil];
Expand All @@ -52,7 +37,7 @@ - (FlutterEngine*)makeEngineWithEntrypoint:(nullable NSString*)entrypoint
- (FlutterEngine*)makeEngineWithEntrypoint:(nullable NSString*)entrypoint
libraryURI:(nullable NSString*)libraryURI
initialRoute:(nullable NSString*)initialRoute {
FlutterEngineGroupOptions* options = [[[FlutterEngineGroupOptions alloc] init] autorelease];
FlutterEngineGroupOptions* options = [[FlutterEngineGroupOptions alloc] init];
options.entrypoint = entrypoint;
options.libraryURI = libraryURI;
options.initialRoute = initialRoute;
Expand All @@ -79,7 +64,8 @@ - (FlutterEngine*)makeEngineWithOptions:(nullable FlutterEngineGroupOptions*)opt
initialRoute:initialRoute
entrypointArgs:entrypointArgs];
}
[_engines addObject:[NSValue valueWithPointer:engine]];
// TODO(cbracken): https://github.com/flutter/flutter/issues/155943
[self.engines addObject:[NSValue valueWithPointer:(__bridge void*)engine]];
cbracken marked this conversation as resolved.
Show resolved Hide resolved
cbracken marked this conversation as resolved.
Show resolved Hide resolved

NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
[center addObserver:self
Expand All @@ -91,13 +77,14 @@ - (FlutterEngine*)makeEngineWithOptions:(nullable FlutterEngineGroupOptions*)opt
}

- (FlutterEngine*)makeEngine {
NSString* engineName = [NSString stringWithFormat:@"%@.%d", self.name, ++_enginesCreatedCount];
FlutterEngine* result = [[FlutterEngine alloc] initWithName:engineName project:self.project];
return [result autorelease];
NSString* engineName =
[NSString stringWithFormat:@"%@.%lu", self.name, ++self.enginesCreatedCount];
return [[FlutterEngine alloc] initWithName:engineName project:self.project];
}

- (void)onEngineWillBeDealloced:(NSNotification*)notification {
[_engines removeObject:[NSValue valueWithPointer:notification.object]];
// TODO(cbracken): https://github.com/flutter/flutter/issues/155943
[self.engines removeObject:[NSValue valueWithPointer:(__bridge void*)notification.object]];
}

@end