From 0295e2edbbbb0b1791105321ad3adf092051208d Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Wed, 24 Apr 2019 16:43:47 -0700 Subject: [PATCH 01/12] Start of perf iOS --- .../ios/Classes/FLTFirebasePerformance.m | 55 +++++++++++++++++++ .../ios/Classes/FirebasePerformancePlugin.h | 13 +++++ .../ios/Classes/FirebasePerformancePlugin.m | 8 +-- 3 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 packages/firebase_performance/ios/Classes/FLTFirebasePerformance.m diff --git a/packages/firebase_performance/ios/Classes/FLTFirebasePerformance.m b/packages/firebase_performance/ios/Classes/FLTFirebasePerformance.m new file mode 100644 index 000000000000..53f7bf3989c9 --- /dev/null +++ b/packages/firebase_performance/ios/Classes/FLTFirebasePerformance.m @@ -0,0 +1,55 @@ +// Copyright 2018 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#import "FirebasePerformancePlugin.h" + +@interface FLTFirebasePerformance () +@property id binaryMessenger; +@end + +@implementation FLTFirebasePerformance ++ (void)registerWithRegistrar:(nonnull NSObject *)registrar {} + +- (instancetype _Nonnull)initWithMessenger:(NSObject *_Nonnull)messenger { + self = [self init]; + if (self) { + _binaryMessenger = messenger; + } + + return self; +} + +- (instancetype)init { + self = [super init]; + if (self) { + if (![FIRApp appNamed:@"__FIRAPP_DEFAULT"]) { + NSLog(@"Configuring the default Firebase app..."); + [FIRApp configure]; + NSLog(@"Configured the default Firebase app %@.", [FIRApp defaultApp].name); + } + } + + return self; +} + +- (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result { + if ([@"FirebasePerformance#isPerformanceCollectionEnabled" isEqualToString:call.method]) { + result(@([[FIRPerformance sharedInstance] isDataCollectionEnabled])); + } else if ([@"FirebasePerformance#setPerformanceCollectionEnabled" isEqualToString:call.method]) { + NSNumber *enable = call.arguments; + [[FIRPerformance sharedInstance] setDataCollectionEnabled:[enable boolValue]]; + result(nil); + } else if ([@"Trace#start" isEqualToString:call.method]) { + [self handleTraceStart:call result:result]; + } else if ([@"Trace#stop" isEqualToString:call.method]) { + [self handleTraceStop:call result:result]; + } else if ([@"HttpMetric#start" isEqualToString:call.method]) { + [self handleHttpMetricStart:call result:result]; + } else if ([@"HttpMetric#stop" isEqualToString:call.method]) { + [self handleHttpMetricStop:call result:result]; + } else { + result(FlutterMethodNotImplemented); + } +} +@end diff --git a/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.h b/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.h index d71c5351ac8d..ddc56dc80188 100644 --- a/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.h +++ b/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.h @@ -1,4 +1,17 @@ +#import #import @interface FLTFirebasePerformancePlugin : NSObject @end + +@interface FLTFirebasePerformance : NSObject +- (instancetype _Nonnull)initWithMessenger:(NSObject *_Nonnull)messenger; +@end + +@interface FLTTrace : NSObject +- (instancetype _Nonnull)initWithTrace:(FIRTrace *_Nonnull)trace; +@end + +@interface FLTHttpMetric : NSObject +- (instancetype _Nonnull)initWithHttpMetric:(FIRHTTPMetric *_Nonnull)metric; +@end diff --git a/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.m b/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.m index 25073643815e..4a635b771ea9 100644 --- a/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.m +++ b/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.m @@ -4,8 +4,6 @@ #import "FirebasePerformancePlugin.h" -#import - @interface FLTFirebasePerformancePlugin () @property(nonatomic, retain) NSMutableDictionary *traces; @property(nonatomic, retain) NSMutableDictionary *httpMetrics; @@ -37,6 +35,7 @@ - (instancetype)init { } - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result { + /* if ([@"FirebasePerformance#isPerformanceCollectionEnabled" isEqualToString:call.method]) { result(@([[FIRPerformance sharedInstance] isDataCollectionEnabled])); } else if ([@"FirebasePerformance#setPerformanceCollectionEnabled" isEqualToString:call.method]) { @@ -54,8 +53,9 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result } else { result(FlutterMethodNotImplemented); } + */ } - +/* - (void)handleTraceStart:(FlutterMethodCall *)call result:(FlutterResult)result { NSNumber *handle = call.arguments[@"handle"]; NSString *name = call.arguments[@"name"]; @@ -156,5 +156,5 @@ - (void)handleHttpMetricStop:(FlutterMethodCall *)call result:(FlutterResult)res [_httpMetrics removeObjectForKey:handle]; result(nil); } - +*/ @end From f581dd91b9aff0a3ea84a8d96d3c09c72eab3f90 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Thu, 25 Apr 2019 14:55:39 -0700 Subject: [PATCH 02/12] Firebase Performance iOS finish --- .../ios/Classes/FLTFirebasePerformance.m | 98 ++++++++++-- .../ios/Classes/FLTHttpMetric.m | 116 ++++++++++++++ .../ios/Classes/FLTTrace.m | 103 ++++++++++++ .../ios/Classes/FirebasePerformancePlugin.h | 10 +- .../ios/Classes/FirebasePerformancePlugin.m | 148 +----------------- 5 files changed, 311 insertions(+), 164 deletions(-) create mode 100644 packages/firebase_performance/ios/Classes/FLTHttpMetric.m create mode 100644 packages/firebase_performance/ios/Classes/FLTTrace.m diff --git a/packages/firebase_performance/ios/Classes/FLTFirebasePerformance.m b/packages/firebase_performance/ios/Classes/FLTFirebasePerformance.m index 53f7bf3989c9..62879def378f 100644 --- a/packages/firebase_performance/ios/Classes/FLTFirebasePerformance.m +++ b/packages/firebase_performance/ios/Classes/FLTFirebasePerformance.m @@ -1,20 +1,22 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #import "FirebasePerformancePlugin.h" @interface FLTFirebasePerformance () -@property id binaryMessenger; +@property id registrar; +@property FIRPerformance *performance; @end @implementation FLTFirebasePerformance + (void)registerWithRegistrar:(nonnull NSObject *)registrar {} -- (instancetype _Nonnull)initWithMessenger:(NSObject *_Nonnull)messenger { +- (instancetype _Nonnull)initWithRegistrar:(NSObject *_Nonnull)registrar { self = [self init]; if (self) { - _binaryMessenger = messenger; + _performance = [FIRPerformance sharedInstance]; + _registrar = registrar; } return self; @@ -35,21 +37,85 @@ - (instancetype)init { - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result { if ([@"FirebasePerformance#isPerformanceCollectionEnabled" isEqualToString:call.method]) { - result(@([[FIRPerformance sharedInstance] isDataCollectionEnabled])); + [self isPerformanceCollectionEnabled:result]; } else if ([@"FirebasePerformance#setPerformanceCollectionEnabled" isEqualToString:call.method]) { - NSNumber *enable = call.arguments; - [[FIRPerformance sharedInstance] setDataCollectionEnabled:[enable boolValue]]; - result(nil); - } else if ([@"Trace#start" isEqualToString:call.method]) { - [self handleTraceStart:call result:result]; - } else if ([@"Trace#stop" isEqualToString:call.method]) { - [self handleTraceStop:call result:result]; - } else if ([@"HttpMetric#start" isEqualToString:call.method]) { - [self handleHttpMetricStart:call result:result]; - } else if ([@"HttpMetric#stop" isEqualToString:call.method]) { - [self handleHttpMetricStop:call result:result]; + [self setPerformanceCollectionEnabled:call result:result]; + } else if ([@"FirebasePerformance#newTrace" isEqualToString:call.method]) { + [self newTrace:call result:result]; + } else if ([@"FirebasePerformance#newHttpMetric" isEqualToString:call.method]) { + [self newHttpMetric:call result:result]; } else { result(FlutterMethodNotImplemented); } } + +- (void)isPerformanceCollectionEnabled:(FlutterResult)result { + result(@([_performance isDataCollectionEnabled])); +} + +- (void)setPerformanceCollectionEnabled:(FlutterMethodCall *)call result:(FlutterResult)result { + NSNumber *enable = call.arguments; + [_performance setDataCollectionEnabled:[enable boolValue]]; + result(nil); +} + +- (void)newTrace:(FlutterMethodCall *)call result:(FlutterResult)result { + NSString *traceName = call.arguments[@"traceName"]; + FIRTrace *trace = [_performance traceWithName:traceName]; + + NSString *channelName = call.arguments[@"channelName"]; + FlutterMethodChannel* channel = [FlutterMethodChannel + methodChannelWithName:channelName + binaryMessenger:[_registrar messenger]]; + + FLTTrace *delegate = [[FLTTrace alloc] initWithTrace:trace registrar:_registrar channel:channel]; + [_registrar addMethodCallDelegate:delegate channel:channel]; + result(nil); +} + +- (void)newHttpMetric:(FlutterMethodCall *)call result:(FlutterResult)result { + NSString *httpMethod = call.arguments[@"httpMethod"]; + FIRHTTPMethod method = [FLTFirebasePerformance parseHttpMethod:httpMethod]; + + NSString *urlString = call.arguments[@"url"]; + NSURL *url = [NSURL URLWithString:urlString]; + + FIRHTTPMetric *metric = [[FIRHTTPMetric alloc] initWithURL:url HTTPMethod:method]; + + NSString *channelName = call.arguments[@"channelName"]; + FlutterMethodChannel *channel = [FlutterMethodChannel + methodChannelWithName:channelName + binaryMessenger:[_registrar messenger]]; + + FLTHttpMetric *delegate = [[FLTHttpMetric alloc] initWithHTTPMetric:metric + registrar:_registrar + channel:channel]; + [_registrar addMethodCallDelegate:delegate channel:channel]; + result(nil); +} + ++ (FIRHTTPMethod)parseHttpMethod:(NSString *)method { + if ([@"HttpMethod.Connect" isEqualToString:method]) { + return FIRHTTPMethodCONNECT; + } else if ([@"HttpMethod.Delete" isEqualToString:method]) { + return FIRHTTPMethodDELETE; + } else if ([@"HttpMethod.Get" isEqualToString:method]) { + return FIRHTTPMethodGET; + } else if ([@"HttpMethod.Head" isEqualToString:method]) { + return FIRHTTPMethodHEAD; + } else if ([@"HttpMethod.Options" isEqualToString:method]) { + return FIRHTTPMethodOPTIONS; + } else if ([@"HttpMethod.Patch" isEqualToString:method]) { + return FIRHTTPMethodPATCH; + } else if ([@"HttpMethod.Post" isEqualToString:method]) { + return FIRHTTPMethodPOST; + } else if ([@"HttpMethod.Put" isEqualToString:method]) { + return FIRHTTPMethodPUT; + } else if ([@"HttpMethod.Trace" isEqualToString:method]) { + return FIRHTTPMethodTRACE; + } + + NSString *reason = [NSString stringWithFormat:@"Invalid HttpMethod: %@", method]; + @throw [[NSException alloc] initWithName:NSInvalidArgumentException reason:reason userInfo:nil]; +} @end diff --git a/packages/firebase_performance/ios/Classes/FLTHttpMetric.m b/packages/firebase_performance/ios/Classes/FLTHttpMetric.m new file mode 100644 index 000000000000..5d6ca4df6552 --- /dev/null +++ b/packages/firebase_performance/ios/Classes/FLTHttpMetric.m @@ -0,0 +1,116 @@ +// Copyright 2019 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#import "FirebasePerformancePlugin.h" + +@interface FLTHttpMetric () +@property FIRHTTPMetric *metric; +@property id registrar; +@property FlutterMethodChannel *channel; +@end + +@implementation FLTHttpMetric ++ (void)registerWithRegistrar:(nonnull NSObject *)registrar {} + +- (instancetype _Nonnull)initWithHTTPMetric:(FIRHTTPMetric *)metric + registrar:(NSObject *_Nonnull)registrar + channel:(FlutterMethodChannel *)channel { + self = [self init]; + if (self) { + _metric = metric; + _registrar = registrar; + _channel = channel; + } + + return self; +} + +- (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result { + if ([@"HttpMetric#start" isEqualToString:call.method]) { + [self start:result]; + } else if ([@"HttpMetric#stop" isEqualToString:call.method]) { + [self stop:result]; + } else if ([@"HttpMetric#httpResponseCode" isEqualToString:call.method]) { + [self setHttpResponseCode:call result:result]; + } else if ([@"HttpMetric#requestPayloadSize" isEqualToString:call.method]) { + [self requestPayloadSize:call result:result]; + } else if ([@"HttpMetric#responseContentType" isEqualToString:call.method]) { + [self responseContentType:call result:result]; + } else if ([@"HttpMetric#responsePayloadSize" isEqualToString:call.method]) { + [self responsePayloadSize:call result:result]; + } else if ([@"HttpMetric#putAttribute" isEqualToString:call.method]) { + [self putAttribute:call result:result]; + } else if ([@"HttpMetric#removeAttribute" isEqualToString:call.method]) { + [self removeAttribute:call result:result]; + } else if ([@"HttpMetric#getAttributes" isEqualToString:call.method]) { + [self getAttributes:result]; + } else { + result(FlutterMethodNotImplemented); + } +} + +- (void)start:(FlutterResult)result { + [_metric start]; + result(nil); +} + +- (void)stop:(FlutterResult)result { + [_metric stop]; + [_registrar addMethodCallDelegate:nil channel:nil]; + result(nil); +} + +- (void)setHttpResponseCode:(FlutterMethodCall *)call result:(FlutterResult)result { + NSNumber *responseCode = call.arguments[@"httpResponseCode"]; + + if (![responseCode isEqual:[NSNull null]]) _metric.responseCode = [responseCode integerValue]; + result(nil); +} + +- (void)requestPayloadSize:(FlutterMethodCall *)call result:(FlutterResult)result { + NSNumber *requestPayloadSize = call.arguments[@"requestPayloadSize"]; + + if (![requestPayloadSize isEqual:[NSNull null]]) { + _metric.requestPayloadSize = [requestPayloadSize longValue]; + } + result(nil); +} + +- (void)responseContentType:(FlutterMethodCall *)call result:(FlutterResult)result { + NSString *responseContentType = call.arguments[@"responseContentType"]; + + if (![responseContentType isEqual:[NSNull null]]) { + _metric.responseContentType = responseContentType; + } + result(nil); +} + +- (void)responsePayloadSize:(FlutterMethodCall *)call result:(FlutterResult)result { + NSNumber *responsePayloadSize = call.arguments[@"responsePayloadSize"]; + + if (![responsePayloadSize isEqual:[NSNull null]]) { + _metric.responsePayloadSize = [responsePayloadSize longValue]; + } + result(nil); +} + +- (void)putAttribute:(FlutterMethodCall *)call result:(FlutterResult)result { + NSString *name = call.arguments[@"name"]; + NSString *value = call.arguments[@"value"]; + + [_metric setValue:value forAttribute:name]; + result(nil); +} + +- (void)removeAttribute:(FlutterMethodCall *)call result:(FlutterResult)result { + NSString *name = call.arguments[@"name"]; + + [_metric removeAttribute:name]; + result(nil); +} + +- (void)getAttributes:(FlutterResult)result { + result(_metric.attributes); +} +@end diff --git a/packages/firebase_performance/ios/Classes/FLTTrace.m b/packages/firebase_performance/ios/Classes/FLTTrace.m new file mode 100644 index 000000000000..72e94a17638c --- /dev/null +++ b/packages/firebase_performance/ios/Classes/FLTTrace.m @@ -0,0 +1,103 @@ +// Copyright 2019 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#import "FirebasePerformancePlugin.h" + +@interface FLTTrace () +@property FIRTrace *trace; +@property id registrar; +@property FlutterMethodChannel *channel; +@end + +@implementation FLTTrace ++ (void)registerWithRegistrar:(nonnull NSObject *)registrar {} + +- (instancetype _Nonnull)initWithTrace:(FIRTrace *)trace + registrar:(NSObject *_Nonnull)registrar + channel:(FlutterMethodChannel *)channel { + self = [self init]; + if (self) { + _registrar = registrar; + _channel = channel; + _trace = trace; + } + + return self; +} + +- (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result { + if ([@"Trace#start" isEqualToString:call.method]) { + [self start:result]; + } else if ([@"Trace#stop" isEqualToString:call.method]) { + [self stop:result]; + } else if ([@"Trace#setMetric" isEqualToString:call.method]) { + [self setMetric:call result:result]; + } else if ([@"Trace#incrementMetric" isEqualToString:call.method]) { + [self incrementMetric:call result:result]; + } else if ([@"Trace#getMetric" isEqualToString:call.method]) { + [self getMetric:call result:result]; + } else if ([@"Trace#putAttribute" isEqualToString:call.method]) { + [self putAttribute:call result:result]; + } else if ([@"Trace#removeAttribute" isEqualToString:call.method]) { + [self removeAttribute:call result:result]; + } else if ([@"Trace#getAttributes" isEqualToString:call.method]) { + [self getAttributes:result]; + } else { + result(FlutterMethodNotImplemented); + } +} + +- (void)start:(FlutterResult)result { + [_trace start]; + result(nil); +} + +- (void)stop:(FlutterResult)result { + [_trace stop]; + [_registrar addMethodCallDelegate:nil channel:_channel]; + result(nil); +} + +- (void)setMetric:(FlutterMethodCall *)call result:(FlutterResult)result { + NSString *name = call.arguments[@"name"]; + NSNumber *value = call.arguments[@"value"]; + + [_trace setIntValue:value.longValue forMetric:name]; + result(nil); +} + +- (void)incrementMetric:(FlutterMethodCall *)call result:(FlutterResult)result { + NSString *name = call.arguments[@"name"]; + NSNumber *value = call.arguments[@"value"]; + + [_trace incrementMetric:name byInt:value.longValue]; + result(nil); +} + +- (void)getMetric:(FlutterMethodCall *)call result:(FlutterResult)result { + NSString *name = call.arguments[@"name"]; + + int64_t metric = [_trace valueForIntMetric:name]; + result(@(metric)); +} + +- (void)putAttribute:(FlutterMethodCall *)call result:(FlutterResult)result { + NSString *name = call.arguments[@"name"]; + NSString *value = call.arguments[@"value"]; + + [_trace setValue:value forAttribute:name]; + result(nil); +} + +- (void)removeAttribute:(FlutterMethodCall *)call result:(FlutterResult)result { + NSString *name = call.arguments[@"name"]; + + [_trace removeAttribute:name]; + result(nil); +} + +- (void)getAttributes:(FlutterResult)result { + result(_trace.attributes); +} +@end diff --git a/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.h b/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.h index ddc56dc80188..8eda01fb8dad 100644 --- a/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.h +++ b/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.h @@ -5,13 +5,17 @@ @end @interface FLTFirebasePerformance : NSObject -- (instancetype _Nonnull)initWithMessenger:(NSObject *_Nonnull)messenger; +- (instancetype _Nonnull)initWithRegistrar:(NSObject *_Nonnull)registrar; @end @interface FLTTrace : NSObject -- (instancetype _Nonnull)initWithTrace:(FIRTrace *_Nonnull)trace; +- (instancetype _Nonnull)initWithTrace:(FIRTrace *_Nonnull)trace + registrar:(NSObject *_Nonnull)registrar + channel:(FlutterMethodChannel *_Nonnull)channel; @end @interface FLTHttpMetric : NSObject -- (instancetype _Nonnull)initWithHttpMetric:(FIRHTTPMetric *_Nonnull)metric; +- (instancetype _Nonnull)initWithHTTPMetric:(FIRHTTPMetric *_Nonnull)metric + registrar:(NSObject *_Nonnull)registrar + channel:(FlutterMethodChannel *_Nonnull)channel; @end diff --git a/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.m b/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.m index 4a635b771ea9..e96ef47e288a 100644 --- a/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.m +++ b/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.m @@ -4,157 +4,15 @@ #import "FirebasePerformancePlugin.h" -@interface FLTFirebasePerformancePlugin () -@property(nonatomic, retain) NSMutableDictionary *traces; -@property(nonatomic, retain) NSMutableDictionary *httpMetrics; -@end - @implementation FLTFirebasePerformancePlugin + (void)registerWithRegistrar:(NSObject *)registrar { FlutterMethodChannel *channel = [FlutterMethodChannel methodChannelWithName:@"plugins.flutter.io/firebase_performance" binaryMessenger:[registrar messenger]]; - FLTFirebasePerformancePlugin *instance = [[FLTFirebasePerformancePlugin alloc] init]; - [registrar addMethodCallDelegate:instance channel:channel]; -} - -- (instancetype)init { - self = [super init]; - if (self) { - if (![FIRApp appNamed:@"__FIRAPP_DEFAULT"]) { - NSLog(@"Configuring the default Firebase app..."); - [FIRApp configure]; - NSLog(@"Configured the default Firebase app %@.", [FIRApp defaultApp].name); - } - - _traces = [[NSMutableDictionary alloc] init]; - _httpMetrics = [[NSMutableDictionary alloc] init]; - } - - return self; -} - -- (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result { - /* - if ([@"FirebasePerformance#isPerformanceCollectionEnabled" isEqualToString:call.method]) { - result(@([[FIRPerformance sharedInstance] isDataCollectionEnabled])); - } else if ([@"FirebasePerformance#setPerformanceCollectionEnabled" isEqualToString:call.method]) { - NSNumber *enable = call.arguments; - [[FIRPerformance sharedInstance] setDataCollectionEnabled:[enable boolValue]]; - result(nil); - } else if ([@"Trace#start" isEqualToString:call.method]) { - [self handleTraceStart:call result:result]; - } else if ([@"Trace#stop" isEqualToString:call.method]) { - [self handleTraceStop:call result:result]; - } else if ([@"HttpMetric#start" isEqualToString:call.method]) { - [self handleHttpMetricStart:call result:result]; - } else if ([@"HttpMetric#stop" isEqualToString:call.method]) { - [self handleHttpMetricStop:call result:result]; - } else { - result(FlutterMethodNotImplemented); - } - */ -} -/* -- (void)handleTraceStart:(FlutterMethodCall *)call result:(FlutterResult)result { - NSNumber *handle = call.arguments[@"handle"]; - NSString *name = call.arguments[@"name"]; - - FIRTrace *trace = [[FIRPerformance sharedInstance] traceWithName:name]; - [_traces setObject:trace forKey:handle]; - [trace start]; - result(nil); -} - -- (void)handleTraceStop:(FlutterMethodCall *)call result:(FlutterResult)result { - NSNumber *handle = call.arguments[@"handle"]; - FIRTrace *trace = [_traces objectForKey:handle]; - NSDictionary *metrics = call.arguments[@"metrics"]; - [metrics enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSNumber *value, BOOL *stop) { - [trace setIntValue:[value longLongValue] forMetric:key]; - }]; - - NSDictionary *attributes = call.arguments[@"attributes"]; - [attributes enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString *value, BOOL *stop) { - [trace setValue:value forAttribute:key]; - }]; - - [trace stop]; - [_traces removeObjectForKey:handle]; - result(nil); -} - -- (void)handleHttpMetricStart:(FlutterMethodCall *)call result:(FlutterResult)result { - NSNumber *handle = call.arguments[@"handle"]; - NSURL *url = [NSURL URLWithString:call.arguments[@"url"]]; - - NSNumber *httpMethod = call.arguments[@"httpMethod"]; - FIRHTTPMethod method; - switch ([httpMethod intValue]) { - case 0: - method = FIRHTTPMethodCONNECT; - break; - case 1: - method = FIRHTTPMethodDELETE; - break; - case 2: - method = FIRHTTPMethodGET; - break; - case 3: - method = FIRHTTPMethodHEAD; - break; - case 4: - method = FIRHTTPMethodOPTIONS; - break; - case 5: - method = FIRHTTPMethodPATCH; - break; - case 6: - method = FIRHTTPMethodPOST; - break; - case 7: - method = FIRHTTPMethodPUT; - break; - case 8: - method = FIRHTTPMethodTRACE; - break; - default: - method = [httpMethod intValue]; - break; - } - - FIRHTTPMetric *metric = [[FIRHTTPMetric alloc] initWithURL:url HTTPMethod:method]; - [_httpMetrics setObject:metric forKey:handle]; - [metric start]; - result(nil); + FLTFirebasePerformance *instance = [[FLTFirebasePerformance alloc] initWithRegistrar:registrar]; + [registrar addMethodCallDelegate:instance channel:channel]; } -- (void)handleHttpMetricStop:(FlutterMethodCall *)call result:(FlutterResult)result { - NSNumber *handle = call.arguments[@"handle"]; - FIRHTTPMetric *metric = [_httpMetrics objectForKey:handle]; - - NSNumber *responseCode = call.arguments[@"httpResponseCode"]; - NSNumber *requestPayloadSize = call.arguments[@"requestPayloadSize"]; - NSString *responseContentType = call.arguments[@"responseContentType"]; - NSNumber *responsePayloadSize = call.arguments[@"responsePayloadSize"]; - - if (![responseCode isEqual:[NSNull null]]) metric.responseCode = [responseCode integerValue]; - if (![requestPayloadSize isEqual:[NSNull null]]) - metric.requestPayloadSize = [requestPayloadSize longValue]; - if (![responseContentType isEqual:[NSNull null]]) - metric.responseContentType = responseContentType; - if (![responsePayloadSize isEqual:[NSNull null]]) - metric.responsePayloadSize = [responsePayloadSize longValue]; - - NSDictionary *attributes = call.arguments[@"attributes"]; - [attributes enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString *value, BOOL *stop) { - [metric setValue:value forAttribute:key]; - }]; - - [metric stop]; - [_httpMetrics removeObjectForKey:handle]; - result(nil); -} -*/ +- (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result {} @end From 3e6fe50bc5d2c72019479ab05c1e3c1b36b5dd28 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Wed, 1 May 2019 12:18:27 -0700 Subject: [PATCH 03/12] Redesign for iOS --- .../ios/Classes/FLTFirebasePerformance.m | 51 ++++++------------- .../ios/Classes/FLTHttpMetric.m | 17 +++---- .../ios/Classes/FLTTrace.m | 17 +++---- .../ios/Classes/FirebasePerformancePlugin.h | 12 ++--- .../ios/Classes/FirebasePerformancePlugin.m | 51 +++++++++++++++++-- 5 files changed, 81 insertions(+), 67 deletions(-) diff --git a/packages/firebase_performance/ios/Classes/FLTFirebasePerformance.m b/packages/firebase_performance/ios/Classes/FLTFirebasePerformance.m index 62879def378f..eff5e62672d1 100644 --- a/packages/firebase_performance/ios/Classes/FLTFirebasePerformance.m +++ b/packages/firebase_performance/ios/Classes/FLTFirebasePerformance.m @@ -5,31 +5,21 @@ #import "FirebasePerformancePlugin.h" @interface FLTFirebasePerformance () -@property id registrar; @property FIRPerformance *performance; @end @implementation FLTFirebasePerformance + (void)registerWithRegistrar:(nonnull NSObject *)registrar {} -- (instancetype _Nonnull)initWithRegistrar:(NSObject *_Nonnull)registrar { - self = [self init]; - if (self) { - _performance = [FIRPerformance sharedInstance]; - _registrar = registrar; - } - - return self; ++ (void)sharedInstanceWithCall:(FlutterMethodCall*)call result:(FlutterResult)result { + NSNumber *handle = call.arguments[@"handle"]; + [FLTFirebasePerformancePlugin addMethodHandler:handle methodHandler:[FLTFirebasePerformance new]]; } - (instancetype)init { self = [super init]; if (self) { - if (![FIRApp appNamed:@"__FIRAPP_DEFAULT"]) { - NSLog(@"Configuring the default Firebase app..."); - [FIRApp configure]; - NSLog(@"Configured the default Firebase app %@.", [FIRApp defaultApp].name); - } + _performance = [FIRPerformance sharedInstance]; } return self; @@ -54,43 +44,32 @@ - (void)isPerformanceCollectionEnabled:(FlutterResult)result { } - (void)setPerformanceCollectionEnabled:(FlutterMethodCall *)call result:(FlutterResult)result { - NSNumber *enable = call.arguments; + NSNumber *enable = call.arguments[@"enable"]; [_performance setDataCollectionEnabled:[enable boolValue]]; result(nil); } - (void)newTrace:(FlutterMethodCall *)call result:(FlutterResult)result { - NSString *traceName = call.arguments[@"traceName"]; - FIRTrace *trace = [_performance traceWithName:traceName]; + NSString *name = call.arguments[@"name"]; + FIRTrace *trace = [_performance traceWithName:name]; + FLTTrace *handler = [[FLTTrace alloc] initWithTrace:trace]; - NSString *channelName = call.arguments[@"channelName"]; - FlutterMethodChannel* channel = [FlutterMethodChannel - methodChannelWithName:channelName - binaryMessenger:[_registrar messenger]]; + NSNumber *handle = call.arguments[@"traceHandle"]; + [FLTFirebasePerformancePlugin addMethodHandler:handle methodHandler:handler]; - FLTTrace *delegate = [[FLTTrace alloc] initWithTrace:trace registrar:_registrar channel:channel]; - [_registrar addMethodCallDelegate:delegate channel:channel]; result(nil); } - (void)newHttpMetric:(FlutterMethodCall *)call result:(FlutterResult)result { - NSString *httpMethod = call.arguments[@"httpMethod"]; - FIRHTTPMethod method = [FLTFirebasePerformance parseHttpMethod:httpMethod]; - - NSString *urlString = call.arguments[@"url"]; - NSURL *url = [NSURL URLWithString:urlString]; + FIRHTTPMethod method = [FLTFirebasePerformance parseHttpMethod:call.arguments[@"httpMethod"]]; + NSURL *url = [NSURL URLWithString:call.arguments[@"url"]]; FIRHTTPMetric *metric = [[FIRHTTPMetric alloc] initWithURL:url HTTPMethod:method]; + FLTHttpMetric *handler = [[FLTHttpMetric alloc] initWithHTTPMetric:metric]; - NSString *channelName = call.arguments[@"channelName"]; - FlutterMethodChannel *channel = [FlutterMethodChannel - methodChannelWithName:channelName - binaryMessenger:[_registrar messenger]]; + NSNumber *handle = call.arguments[@"httpMetricHandle"]; + [FLTFirebasePerformancePlugin addMethodHandler:handle methodHandler:handler]; - FLTHttpMetric *delegate = [[FLTHttpMetric alloc] initWithHTTPMetric:metric - registrar:_registrar - channel:channel]; - [_registrar addMethodCallDelegate:delegate channel:channel]; result(nil); } diff --git a/packages/firebase_performance/ios/Classes/FLTHttpMetric.m b/packages/firebase_performance/ios/Classes/FLTHttpMetric.m index 5d6ca4df6552..376c03d7515a 100644 --- a/packages/firebase_performance/ios/Classes/FLTHttpMetric.m +++ b/packages/firebase_performance/ios/Classes/FLTHttpMetric.m @@ -6,21 +6,15 @@ @interface FLTHttpMetric () @property FIRHTTPMetric *metric; -@property id registrar; -@property FlutterMethodChannel *channel; @end @implementation FLTHttpMetric + (void)registerWithRegistrar:(nonnull NSObject *)registrar {} -- (instancetype _Nonnull)initWithHTTPMetric:(FIRHTTPMetric *)metric - registrar:(NSObject *_Nonnull)registrar - channel:(FlutterMethodChannel *)channel { +- (instancetype _Nonnull)initWithHTTPMetric:(FIRHTTPMetric *)metric { self = [self init]; if (self) { _metric = metric; - _registrar = registrar; - _channel = channel; } return self; @@ -30,7 +24,7 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result if ([@"HttpMetric#start" isEqualToString:call.method]) { [self start:result]; } else if ([@"HttpMetric#stop" isEqualToString:call.method]) { - [self stop:result]; + [self stop:call result:result]; } else if ([@"HttpMetric#httpResponseCode" isEqualToString:call.method]) { [self setHttpResponseCode:call result:result]; } else if ([@"HttpMetric#requestPayloadSize" isEqualToString:call.method]) { @@ -55,9 +49,12 @@ - (void)start:(FlutterResult)result { result(nil); } -- (void)stop:(FlutterResult)result { +- (void)stop:(FlutterMethodCall *)call result:(FlutterResult)result { [_metric stop]; - [_registrar addMethodCallDelegate:nil channel:nil]; + + NSNumber *handle = call.arguments[@"handle"]; + [FLTFirebasePerformancePlugin removeMethodHandler:handle]; + result(nil); } diff --git a/packages/firebase_performance/ios/Classes/FLTTrace.m b/packages/firebase_performance/ios/Classes/FLTTrace.m index 72e94a17638c..9cbd9d274234 100644 --- a/packages/firebase_performance/ios/Classes/FLTTrace.m +++ b/packages/firebase_performance/ios/Classes/FLTTrace.m @@ -6,20 +6,14 @@ @interface FLTTrace () @property FIRTrace *trace; -@property id registrar; -@property FlutterMethodChannel *channel; @end @implementation FLTTrace + (void)registerWithRegistrar:(nonnull NSObject *)registrar {} -- (instancetype _Nonnull)initWithTrace:(FIRTrace *)trace - registrar:(NSObject *_Nonnull)registrar - channel:(FlutterMethodChannel *)channel { +- (instancetype _Nonnull)initWithTrace:(FIRTrace *)trace { self = [self init]; if (self) { - _registrar = registrar; - _channel = channel; _trace = trace; } @@ -30,7 +24,7 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result if ([@"Trace#start" isEqualToString:call.method]) { [self start:result]; } else if ([@"Trace#stop" isEqualToString:call.method]) { - [self stop:result]; + [self stop:call result:result]; } else if ([@"Trace#setMetric" isEqualToString:call.method]) { [self setMetric:call result:result]; } else if ([@"Trace#incrementMetric" isEqualToString:call.method]) { @@ -53,9 +47,12 @@ - (void)start:(FlutterResult)result { result(nil); } -- (void)stop:(FlutterResult)result { +- (void)stop:(FlutterMethodCall *)call result:(FlutterResult)result { [_trace stop]; - [_registrar addMethodCallDelegate:nil channel:_channel]; + + NSNumber *handle = call.arguments[@"handle"]; + [FLTFirebasePerformancePlugin removeMethodHandler:handle]; + result(nil); } diff --git a/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.h b/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.h index 8eda01fb8dad..cc5de2523517 100644 --- a/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.h +++ b/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.h @@ -2,20 +2,18 @@ #import @interface FLTFirebasePerformancePlugin : NSObject ++ (void)addMethodHandler:(NSNumber *_Nonnull)handle methodHandler:(id_Nonnull)handler; ++ (void)removeMethodHandler:(NSNumber *_Nonnull)handle; @end @interface FLTFirebasePerformance : NSObject -- (instancetype _Nonnull)initWithRegistrar:(NSObject *_Nonnull)registrar; ++ (void)sharedInstanceWithCall:(FlutterMethodCall *_Nonnull)call result:(FlutterResult _Nonnull)result; @end @interface FLTTrace : NSObject -- (instancetype _Nonnull)initWithTrace:(FIRTrace *_Nonnull)trace - registrar:(NSObject *_Nonnull)registrar - channel:(FlutterMethodChannel *_Nonnull)channel; +- (instancetype _Nonnull)initWithTrace:(FIRTrace *_Nonnull)trace; @end @interface FLTHttpMetric : NSObject -- (instancetype _Nonnull)initWithHTTPMetric:(FIRHTTPMetric *_Nonnull)metric - registrar:(NSObject *_Nonnull)registrar - channel:(FlutterMethodChannel *_Nonnull)channel; +- (instancetype _Nonnull)initWithHTTPMetric:(FIRHTTPMetric *_Nonnull)metric; @end diff --git a/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.m b/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.m index e96ef47e288a..80703623a1fc 100644 --- a/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.m +++ b/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.m @@ -5,14 +5,57 @@ #import "FirebasePerformancePlugin.h" @implementation FLTFirebasePerformancePlugin +static NSMutableDictionary> *methodHandlers; + + (void)registerWithRegistrar:(NSObject *)registrar { + methodHandlers = [NSMutableDictionary new]; + FlutterMethodChannel *channel = - [FlutterMethodChannel methodChannelWithName:@"plugins.flutter.io/firebase_performance" - binaryMessenger:[registrar messenger]]; + [FlutterMethodChannel methodChannelWithName:@"plugins.flutter.io/firebase_performance" + binaryMessenger:[registrar messenger]]; - FLTFirebasePerformance *instance = [[FLTFirebasePerformance alloc] initWithRegistrar:registrar]; + FLTFirebasePerformancePlugin *instance = [FLTFirebasePerformancePlugin new]; [registrar addMethodCallDelegate:instance channel:channel]; } -- (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result {} +- (instancetype)init { + self = [super init]; + if (self) { + if (![FIRApp appNamed:@"__FIRAPP_DEFAULT"]) { + NSLog(@"Configuring the default Firebase app..."); + [FIRApp configure]; + NSLog(@"Configured the default Firebase app %@.", [FIRApp defaultApp].name); + } + } + + return self; +} + +- (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result { + if ([@"FirebasePerformance#instance" isEqualToString:call.method]) { + [FLTFirebasePerformance sharedInstanceWithCall:call result:result]; + result(nil); + } else { + NSNumber *handle = call.arguments[@"handle"]; + + if (![handle isEqual:[NSNull null]]) { + [methodHandlers[handle] handleMethodCall:call result:result]; + } else { + result(FlutterMethodNotImplemented); + } + } +} + ++ (void)addMethodHandler:(NSNumber *)handle methodHandler:(id)handler { + if (methodHandlers[handle]) { + NSString *reason = [[NSString alloc] initWithFormat:@"Object for handle already exists: %d", handle.intValue]; + @throw [[NSException alloc] initWithName:NSInvalidArgumentException reason:reason userInfo:nil]; + } + + methodHandlers[handle] = handler; +} + ++ (void)removeMethodHandler:(NSNumber *)handle { + [methodHandlers removeObjectForKey:handle]; +} @end From 21fd8cbdb6a2b043a6a08ab4c6ad510962216fa8 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Wed, 1 May 2019 12:28:07 -0700 Subject: [PATCH 04/12] Formatting --- .../ios/Classes/FLTFirebasePerformance.m | 5 +++-- .../firebase_performance/ios/Classes/FLTHttpMetric.m | 3 ++- packages/firebase_performance/ios/Classes/FLTTrace.m | 3 ++- .../ios/Classes/FirebasePerformancePlugin.h | 12 +++++++----- .../ios/Classes/FirebasePerformancePlugin.m | 7 ++++--- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/packages/firebase_performance/ios/Classes/FLTFirebasePerformance.m b/packages/firebase_performance/ios/Classes/FLTFirebasePerformance.m index eff5e62672d1..7737df7d67a6 100644 --- a/packages/firebase_performance/ios/Classes/FLTFirebasePerformance.m +++ b/packages/firebase_performance/ios/Classes/FLTFirebasePerformance.m @@ -9,9 +9,10 @@ @interface FLTFirebasePerformance () @end @implementation FLTFirebasePerformance -+ (void)registerWithRegistrar:(nonnull NSObject *)registrar {} ++ (void)registerWithRegistrar:(nonnull NSObject *)registrar { +} -+ (void)sharedInstanceWithCall:(FlutterMethodCall*)call result:(FlutterResult)result { ++ (void)sharedInstanceWithCall:(FlutterMethodCall *)call result:(FlutterResult)result { NSNumber *handle = call.arguments[@"handle"]; [FLTFirebasePerformancePlugin addMethodHandler:handle methodHandler:[FLTFirebasePerformance new]]; } diff --git a/packages/firebase_performance/ios/Classes/FLTHttpMetric.m b/packages/firebase_performance/ios/Classes/FLTHttpMetric.m index 376c03d7515a..8c0bc1f86b35 100644 --- a/packages/firebase_performance/ios/Classes/FLTHttpMetric.m +++ b/packages/firebase_performance/ios/Classes/FLTHttpMetric.m @@ -9,7 +9,8 @@ @interface FLTHttpMetric () @end @implementation FLTHttpMetric -+ (void)registerWithRegistrar:(nonnull NSObject *)registrar {} ++ (void)registerWithRegistrar:(nonnull NSObject *)registrar { +} - (instancetype _Nonnull)initWithHTTPMetric:(FIRHTTPMetric *)metric { self = [self init]; diff --git a/packages/firebase_performance/ios/Classes/FLTTrace.m b/packages/firebase_performance/ios/Classes/FLTTrace.m index 9cbd9d274234..510e8f5fc135 100644 --- a/packages/firebase_performance/ios/Classes/FLTTrace.m +++ b/packages/firebase_performance/ios/Classes/FLTTrace.m @@ -9,7 +9,8 @@ @interface FLTTrace () @end @implementation FLTTrace -+ (void)registerWithRegistrar:(nonnull NSObject *)registrar {} ++ (void)registerWithRegistrar:(nonnull NSObject *)registrar { +} - (instancetype _Nonnull)initWithTrace:(FIRTrace *)trace { self = [self init]; diff --git a/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.h b/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.h index cc5de2523517..f50df538a254 100644 --- a/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.h +++ b/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.h @@ -2,18 +2,20 @@ #import @interface FLTFirebasePerformancePlugin : NSObject -+ (void)addMethodHandler:(NSNumber *_Nonnull)handle methodHandler:(id_Nonnull)handler; ++ (void)addMethodHandler:(NSNumber *_Nonnull)handle + methodHandler:(id_Nonnull)handler; + (void)removeMethodHandler:(NSNumber *_Nonnull)handle; @end -@interface FLTFirebasePerformance : NSObject -+ (void)sharedInstanceWithCall:(FlutterMethodCall *_Nonnull)call result:(FlutterResult _Nonnull)result; +@interface FLTFirebasePerformance : NSObject ++ (void)sharedInstanceWithCall:(FlutterMethodCall *_Nonnull)call + result:(FlutterResult _Nonnull)result; @end -@interface FLTTrace : NSObject +@interface FLTTrace : NSObject - (instancetype _Nonnull)initWithTrace:(FIRTrace *_Nonnull)trace; @end -@interface FLTHttpMetric : NSObject +@interface FLTHttpMetric : NSObject - (instancetype _Nonnull)initWithHTTPMetric:(FIRHTTPMetric *_Nonnull)metric; @end diff --git a/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.m b/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.m index 80703623a1fc..82298f0ae970 100644 --- a/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.m +++ b/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.m @@ -11,8 +11,8 @@ + (void)registerWithRegistrar:(NSObject *)registrar { methodHandlers = [NSMutableDictionary new]; FlutterMethodChannel *channel = - [FlutterMethodChannel methodChannelWithName:@"plugins.flutter.io/firebase_performance" - binaryMessenger:[registrar messenger]]; + [FlutterMethodChannel methodChannelWithName:@"plugins.flutter.io/firebase_performance" + binaryMessenger:[registrar messenger]]; FLTFirebasePerformancePlugin *instance = [FLTFirebasePerformancePlugin new]; [registrar addMethodCallDelegate:instance channel:channel]; @@ -48,7 +48,8 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result + (void)addMethodHandler:(NSNumber *)handle methodHandler:(id)handler { if (methodHandlers[handle]) { - NSString *reason = [[NSString alloc] initWithFormat:@"Object for handle already exists: %d", handle.intValue]; + NSString *reason = + [[NSString alloc] initWithFormat:@"Object for handle already exists: %d", handle.intValue]; @throw [[NSException alloc] initWithName:NSInvalidArgumentException reason:reason userInfo:nil]; } From 83aa1a9313718d7cef2fa924be6e2597525138f4 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Wed, 1 May 2019 12:49:20 -0700 Subject: [PATCH 05/12] formattinn --- .../ios/Classes/FirebasePerformancePlugin.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.h b/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.h index f50df538a254..3c45bd342866 100644 --- a/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.h +++ b/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.h @@ -3,7 +3,7 @@ @interface FLTFirebasePerformancePlugin : NSObject + (void)addMethodHandler:(NSNumber *_Nonnull)handle - methodHandler:(id_Nonnull)handler; + methodHandler:(id _Nonnull)handler; + (void)removeMethodHandler:(NSNumber *_Nonnull)handle; @end From 96ffe4981bee8c162ebbec472c6ea94b0f6d1940 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Wed, 1 May 2019 15:00:33 -0700 Subject: [PATCH 06/12] Fix method call name --- packages/firebase_performance/ios/Classes/FLTHttpMetric.m | 6 +++--- packages/firebase_performance/ios/Classes/FLTTrace.m | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/firebase_performance/ios/Classes/FLTHttpMetric.m b/packages/firebase_performance/ios/Classes/FLTHttpMetric.m index 8c0bc1f86b35..af92b59d224d 100644 --- a/packages/firebase_performance/ios/Classes/FLTHttpMetric.m +++ b/packages/firebase_performance/ios/Classes/FLTHttpMetric.m @@ -34,11 +34,11 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result [self responseContentType:call result:result]; } else if ([@"HttpMetric#responsePayloadSize" isEqualToString:call.method]) { [self responsePayloadSize:call result:result]; - } else if ([@"HttpMetric#putAttribute" isEqualToString:call.method]) { + } else if ([@"PerformanceAttributes#putAttribute" isEqualToString:call.method]) { [self putAttribute:call result:result]; - } else if ([@"HttpMetric#removeAttribute" isEqualToString:call.method]) { + } else if ([@"PerformanceAttributes#removeAttribute" isEqualToString:call.method]) { [self removeAttribute:call result:result]; - } else if ([@"HttpMetric#getAttributes" isEqualToString:call.method]) { + } else if ([@"PerformanceAttributes#getAttributes" isEqualToString:call.method]) { [self getAttributes:result]; } else { result(FlutterMethodNotImplemented); diff --git a/packages/firebase_performance/ios/Classes/FLTTrace.m b/packages/firebase_performance/ios/Classes/FLTTrace.m index 510e8f5fc135..9336268ba68d 100644 --- a/packages/firebase_performance/ios/Classes/FLTTrace.m +++ b/packages/firebase_performance/ios/Classes/FLTTrace.m @@ -32,11 +32,11 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result [self incrementMetric:call result:result]; } else if ([@"Trace#getMetric" isEqualToString:call.method]) { [self getMetric:call result:result]; - } else if ([@"Trace#putAttribute" isEqualToString:call.method]) { + } else if ([@"PerformanceAttributes#putAttribute" isEqualToString:call.method]) { [self putAttribute:call result:result]; - } else if ([@"Trace#removeAttribute" isEqualToString:call.method]) { + } else if ([@"PerformanceAttributes#removeAttribute" isEqualToString:call.method]) { [self removeAttribute:call result:result]; - } else if ([@"Trace#getAttributes" isEqualToString:call.method]) { + } else if ([@"PerformanceAttributes#getAttributes" isEqualToString:call.method]) { [self getAttributes:result]; } else { result(FlutterMethodNotImplemented); From ecd0addcad64f0367017bfa8b3c75da6dbe6e876 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Wed, 1 May 2019 15:59:29 -0700 Subject: [PATCH 07/12] use block notation --- packages/firebase_performance/ios/Classes/FLTHttpMetric.m | 2 +- packages/firebase_performance/ios/Classes/FLTTrace.m | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/firebase_performance/ios/Classes/FLTHttpMetric.m b/packages/firebase_performance/ios/Classes/FLTHttpMetric.m index af92b59d224d..64a622aeb2d7 100644 --- a/packages/firebase_performance/ios/Classes/FLTHttpMetric.m +++ b/packages/firebase_performance/ios/Classes/FLTHttpMetric.m @@ -109,6 +109,6 @@ - (void)removeAttribute:(FlutterMethodCall *)call result:(FlutterResult)result { } - (void)getAttributes:(FlutterResult)result { - result(_metric.attributes); + result([_metric attributes]); } @end diff --git a/packages/firebase_performance/ios/Classes/FLTTrace.m b/packages/firebase_performance/ios/Classes/FLTTrace.m index 9336268ba68d..a522e3d38a39 100644 --- a/packages/firebase_performance/ios/Classes/FLTTrace.m +++ b/packages/firebase_performance/ios/Classes/FLTTrace.m @@ -96,6 +96,6 @@ - (void)removeAttribute:(FlutterMethodCall *)call result:(FlutterResult)result { } - (void)getAttributes:(FlutterResult)result { - result(_trace.attributes); + result([_trace attributes]); } @end From 7f96745e5037ad29dc125655333d74dd111b4f5d Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Wed, 1 May 2019 17:04:12 -0700 Subject: [PATCH 08/12] Temporarily remove integration tests --- .../example/test_driver/firebase_performance.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/firebase_performance/example/test_driver/firebase_performance.dart b/packages/firebase_performance/example/test_driver/firebase_performance.dart index fcabfe11f239..352db529bd1b 100644 --- a/packages/firebase_performance/example/test_driver/firebase_performance.dart +++ b/packages/firebase_performance/example/test_driver/firebase_performance.dart @@ -2,7 +2,6 @@ import 'dart:async'; import 'package:flutter_driver/driver_extension.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:firebase_performance/firebase_performance.dart'; void main() { final Completer completer = Completer(); @@ -10,6 +9,8 @@ void main() { tearDownAll(() => completer.complete(null)); group('firebase_performance test driver', () { + // TODO(bparrishMines): Rewrite integration tests when iOS portion is written. + /* final FirebasePerformance performance = FirebasePerformance.instance; setUp(() async { @@ -37,5 +38,6 @@ void main() { expect(trace.getAttribute('testAttribute2'), null); expect(trace.getAttribute('testMetric'), null); }); + */ }); } From 52f04b8d3dcfabf53f909006f4afdad7be7d1904 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Sun, 5 May 2019 22:38:34 -0700 Subject: [PATCH 09/12] Make sharedInstance a constructor --- .../ios/Classes/FLTFirebasePerformance.m | 20 ++++++++----------- .../ios/Classes/FirebasePerformancePlugin.h | 3 +-- .../ios/Classes/FirebasePerformancePlugin.m | 5 ++++- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/packages/firebase_performance/ios/Classes/FLTFirebasePerformance.m b/packages/firebase_performance/ios/Classes/FLTFirebasePerformance.m index 7737df7d67a6..b8869e03d9f0 100644 --- a/packages/firebase_performance/ios/Classes/FLTFirebasePerformance.m +++ b/packages/firebase_performance/ios/Classes/FLTFirebasePerformance.m @@ -12,18 +12,14 @@ @implementation FLTFirebasePerformance + (void)registerWithRegistrar:(nonnull NSObject *)registrar { } -+ (void)sharedInstanceWithCall:(FlutterMethodCall *)call result:(FlutterResult)result { - NSNumber *handle = call.arguments[@"handle"]; - [FLTFirebasePerformancePlugin addMethodHandler:handle methodHandler:[FLTFirebasePerformance new]]; -} - -- (instancetype)init { - self = [super init]; - if (self) { - _performance = [FIRPerformance sharedInstance]; - } - - return self; ++ (instancetype _Nonnull)sharedInstance { + static FLTFirebasePerformance *sharedInstance = nil; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + sharedInstance = [[FLTFirebasePerformance alloc] init]; + sharedInstance.performance = [FIRPerformance sharedInstance]; + }); + return sharedInstance; } - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result { diff --git a/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.h b/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.h index 3c45bd342866..17e20b5dfa21 100644 --- a/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.h +++ b/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.h @@ -8,8 +8,7 @@ @end @interface FLTFirebasePerformance : NSObject -+ (void)sharedInstanceWithCall:(FlutterMethodCall *_Nonnull)call - result:(FlutterResult _Nonnull)result; ++ (instancetype _Nonnull)sharedInstance; @end @interface FLTTrace : NSObject diff --git a/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.m b/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.m index 82298f0ae970..a88409b01e6f 100644 --- a/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.m +++ b/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.m @@ -33,7 +33,10 @@ - (instancetype)init { - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result { if ([@"FirebasePerformance#instance" isEqualToString:call.method]) { - [FLTFirebasePerformance sharedInstanceWithCall:call result:result]; + NSNumber *handle = call.arguments[@"handle"]; + FLTFirebasePerformance performance = [FLTFirebasePerformance sharedInstance]; + + [FLTFirebasePerformancePlugin addMethodHandler:handle methodHandler:performance]; result(nil); } else { NSNumber *handle = call.arguments[@"handle"]; From fda650fed83d25b32845b3dea950bb0b805bd1b0 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Sun, 5 May 2019 23:28:53 -0700 Subject: [PATCH 10/12] Update FirebasePerformancePlugin.m --- .../ios/Classes/FirebasePerformancePlugin.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.m b/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.m index a88409b01e6f..606d683067bb 100644 --- a/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.m +++ b/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.m @@ -34,7 +34,7 @@ - (instancetype)init { - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result { if ([@"FirebasePerformance#instance" isEqualToString:call.method]) { NSNumber *handle = call.arguments[@"handle"]; - FLTFirebasePerformance performance = [FLTFirebasePerformance sharedInstance]; + FLTFirebasePerformance *performance = [FLTFirebasePerformance sharedInstance]; [FLTFirebasePerformancePlugin addMethodHandler:handle methodHandler:performance]; result(nil); From 71ad2ea0b861e838b8d737c67c35a15637be64b2 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Tue, 7 May 2019 11:53:41 -0700 Subject: [PATCH 11/12] Create internal methods --- .../ios/Classes/FLTFirebasePerformance.m | 2 +- .../ios/Classes/FLTHttpMetric.m | 2 +- .../ios/Classes/FLTTrace.m | 2 +- .../FirebasePerformancePlugin+Internal.h | 23 +++++++++++++++++++ .../ios/Classes/FirebasePerformancePlugin.h | 15 ------------ .../ios/Classes/FirebasePerformancePlugin.m | 2 +- 6 files changed, 27 insertions(+), 19 deletions(-) create mode 100644 packages/firebase_performance/ios/Classes/FirebasePerformancePlugin+Internal.h diff --git a/packages/firebase_performance/ios/Classes/FLTFirebasePerformance.m b/packages/firebase_performance/ios/Classes/FLTFirebasePerformance.m index b8869e03d9f0..ab8a60b552fb 100644 --- a/packages/firebase_performance/ios/Classes/FLTFirebasePerformance.m +++ b/packages/firebase_performance/ios/Classes/FLTFirebasePerformance.m @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#import "FirebasePerformancePlugin.h" +#import "FirebasePerformancePlugin+Internal.h" @interface FLTFirebasePerformance () @property FIRPerformance *performance; diff --git a/packages/firebase_performance/ios/Classes/FLTHttpMetric.m b/packages/firebase_performance/ios/Classes/FLTHttpMetric.m index 64a622aeb2d7..6140cb348d3f 100644 --- a/packages/firebase_performance/ios/Classes/FLTHttpMetric.m +++ b/packages/firebase_performance/ios/Classes/FLTHttpMetric.m @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#import "FirebasePerformancePlugin.h" +#import "FirebasePerformancePlugin+Internal.h" @interface FLTHttpMetric () @property FIRHTTPMetric *metric; diff --git a/packages/firebase_performance/ios/Classes/FLTTrace.m b/packages/firebase_performance/ios/Classes/FLTTrace.m index a522e3d38a39..f4baa6ba2738 100644 --- a/packages/firebase_performance/ios/Classes/FLTTrace.m +++ b/packages/firebase_performance/ios/Classes/FLTTrace.m @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#import "FirebasePerformancePlugin.h" +#import "FirebasePerformancePlugin+Internal.h" @interface FLTTrace () @property FIRTrace *trace; diff --git a/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin+Internal.h b/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin+Internal.h new file mode 100644 index 000000000000..8c25eeec53fd --- /dev/null +++ b/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin+Internal.h @@ -0,0 +1,23 @@ +// Copyright 2019 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#import "FirebasePerformancePlugin.h" + +@interface FLTFirebasePerformancePlugin (Internal) ++ (void)addMethodHandler:(NSNumber *_Nonnull)handle + methodHandler:(id _Nonnull)handler; ++ (void)removeMethodHandler:(NSNumber *_Nonnull)handle; +@end + +@interface FLTFirebasePerformance : NSObject ++ (instancetype _Nonnull)sharedInstance; +@end + +@interface FLTTrace : NSObject +- (instancetype _Nonnull)initWithTrace:(FIRTrace *_Nonnull)trace; +@end + +@interface FLTHttpMetric : NSObject +- (instancetype _Nonnull)initWithHTTPMetric:(FIRHTTPMetric *_Nonnull)metric; +@end diff --git a/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.h b/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.h index 17e20b5dfa21..44bf53592eb9 100644 --- a/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.h +++ b/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.h @@ -2,19 +2,4 @@ #import @interface FLTFirebasePerformancePlugin : NSObject -+ (void)addMethodHandler:(NSNumber *_Nonnull)handle - methodHandler:(id _Nonnull)handler; -+ (void)removeMethodHandler:(NSNumber *_Nonnull)handle; -@end - -@interface FLTFirebasePerformance : NSObject -+ (instancetype _Nonnull)sharedInstance; -@end - -@interface FLTTrace : NSObject -- (instancetype _Nonnull)initWithTrace:(FIRTrace *_Nonnull)trace; -@end - -@interface FLTHttpMetric : NSObject -- (instancetype _Nonnull)initWithHTTPMetric:(FIRHTTPMetric *_Nonnull)metric; @end diff --git a/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.m b/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.m index 606d683067bb..2c2c8fa7efcf 100644 --- a/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.m +++ b/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.m @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#import "FirebasePerformancePlugin.h" +#import "FirebasePerformancePlugin+Internal.h" @implementation FLTFirebasePerformancePlugin static NSMutableDictionary> *methodHandlers; From 21a67f8f7c4bebb00c46e52861f50e984500a1ef Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Thu, 9 May 2019 13:11:53 -0700 Subject: [PATCH 12/12] Use MethodCallHandler protocol --- .../ios/Classes/FLTFirebasePerformance.m | 3 --- .../ios/Classes/FLTHttpMetric.m | 3 --- .../firebase_performance/ios/Classes/FLTTrace.m | 3 --- .../Classes/FirebasePerformancePlugin+Internal.h | 13 +++++++++---- .../ios/Classes/FirebasePerformancePlugin.m | 4 ++-- 5 files changed, 11 insertions(+), 15 deletions(-) diff --git a/packages/firebase_performance/ios/Classes/FLTFirebasePerformance.m b/packages/firebase_performance/ios/Classes/FLTFirebasePerformance.m index ab8a60b552fb..81cf29c06559 100644 --- a/packages/firebase_performance/ios/Classes/FLTFirebasePerformance.m +++ b/packages/firebase_performance/ios/Classes/FLTFirebasePerformance.m @@ -9,9 +9,6 @@ @interface FLTFirebasePerformance () @end @implementation FLTFirebasePerformance -+ (void)registerWithRegistrar:(nonnull NSObject *)registrar { -} - + (instancetype _Nonnull)sharedInstance { static FLTFirebasePerformance *sharedInstance = nil; static dispatch_once_t onceToken; diff --git a/packages/firebase_performance/ios/Classes/FLTHttpMetric.m b/packages/firebase_performance/ios/Classes/FLTHttpMetric.m index 6140cb348d3f..3a12f3400613 100644 --- a/packages/firebase_performance/ios/Classes/FLTHttpMetric.m +++ b/packages/firebase_performance/ios/Classes/FLTHttpMetric.m @@ -9,9 +9,6 @@ @interface FLTHttpMetric () @end @implementation FLTHttpMetric -+ (void)registerWithRegistrar:(nonnull NSObject *)registrar { -} - - (instancetype _Nonnull)initWithHTTPMetric:(FIRHTTPMetric *)metric { self = [self init]; if (self) { diff --git a/packages/firebase_performance/ios/Classes/FLTTrace.m b/packages/firebase_performance/ios/Classes/FLTTrace.m index f4baa6ba2738..3ce6af5fc3ef 100644 --- a/packages/firebase_performance/ios/Classes/FLTTrace.m +++ b/packages/firebase_performance/ios/Classes/FLTTrace.m @@ -9,9 +9,6 @@ @interface FLTTrace () @end @implementation FLTTrace -+ (void)registerWithRegistrar:(nonnull NSObject *)registrar { -} - - (instancetype _Nonnull)initWithTrace:(FIRTrace *)trace { self = [self init]; if (self) { diff --git a/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin+Internal.h b/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin+Internal.h index 8c25eeec53fd..f0adca5b905b 100644 --- a/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin+Internal.h +++ b/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin+Internal.h @@ -4,20 +4,25 @@ #import "FirebasePerformancePlugin.h" +@protocol MethodCallHandler +@required +- (void)handleMethodCall:(FlutterMethodCall *_Nonnull)call result:(FlutterResult _Nonnull)result; +@end + @interface FLTFirebasePerformancePlugin (Internal) + (void)addMethodHandler:(NSNumber *_Nonnull)handle - methodHandler:(id _Nonnull)handler; + methodHandler:(id _Nonnull)handler; + (void)removeMethodHandler:(NSNumber *_Nonnull)handle; @end -@interface FLTFirebasePerformance : NSObject +@interface FLTFirebasePerformance : NSObject + (instancetype _Nonnull)sharedInstance; @end -@interface FLTTrace : NSObject +@interface FLTTrace : NSObject - (instancetype _Nonnull)initWithTrace:(FIRTrace *_Nonnull)trace; @end -@interface FLTHttpMetric : NSObject +@interface FLTHttpMetric : NSObject - (instancetype _Nonnull)initWithHTTPMetric:(FIRHTTPMetric *_Nonnull)metric; @end diff --git a/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.m b/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.m index 2c2c8fa7efcf..1c387265c988 100644 --- a/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.m +++ b/packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.m @@ -5,7 +5,7 @@ #import "FirebasePerformancePlugin+Internal.h" @implementation FLTFirebasePerformancePlugin -static NSMutableDictionary> *methodHandlers; +static NSMutableDictionary> *methodHandlers; + (void)registerWithRegistrar:(NSObject *)registrar { methodHandlers = [NSMutableDictionary new]; @@ -49,7 +49,7 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result } } -+ (void)addMethodHandler:(NSNumber *)handle methodHandler:(id)handler { ++ (void)addMethodHandler:(NSNumber *)handle methodHandler:(id)handler { if (methodHandlers[handle]) { NSString *reason = [[NSString alloc] initWithFormat:@"Object for handle already exists: %d", handle.intValue];