This repository was archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[firebase_perfomance] iOS side of reformat of Firebase Performance #1556
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
0295e2e
Start of perf iOS
bparrishMines f581dd9
Firebase Performance iOS finish
bparrishMines 3e6fe50
Redesign for iOS
bparrishMines 21fd8cb
Formatting
bparrishMines 83aa1a9
formattinn
bparrishMines 96ffe49
Fix method call name
bparrishMines ecd0add
use block notation
bparrishMines 7f96745
Temporarily remove integration tests
bparrishMines 52f04b8
Make sharedInstance a constructor
bparrishMines fda650f
Update FirebasePerformancePlugin.m
bparrishMines 71ad2ea
Create internal methods
bparrishMines 21a67f8
Use MethodCallHandler protocol
bparrishMines File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
packages/firebase_performance/ios/Classes/FLTFirebasePerformance.m
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| // 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+Internal.h" | ||
|
|
||
| @interface FLTFirebasePerformance () | ||
| @property FIRPerformance *performance; | ||
| @end | ||
|
|
||
| @implementation FLTFirebasePerformance | ||
| + (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 { | ||
| if ([@"FirebasePerformance#isPerformanceCollectionEnabled" isEqualToString:call.method]) { | ||
| [self isPerformanceCollectionEnabled:result]; | ||
| } else if ([@"FirebasePerformance#setPerformanceCollectionEnabled" isEqualToString:call.method]) { | ||
| [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[@"enable"]; | ||
| [_performance setDataCollectionEnabled:[enable boolValue]]; | ||
| result(nil); | ||
| } | ||
|
|
||
| - (void)newTrace:(FlutterMethodCall *)call result:(FlutterResult)result { | ||
| NSString *name = call.arguments[@"name"]; | ||
| FIRTrace *trace = [_performance traceWithName:name]; | ||
| FLTTrace *handler = [[FLTTrace alloc] initWithTrace:trace]; | ||
|
|
||
| NSNumber *handle = call.arguments[@"traceHandle"]; | ||
| [FLTFirebasePerformancePlugin addMethodHandler:handle methodHandler:handler]; | ||
|
|
||
| result(nil); | ||
| } | ||
|
|
||
| - (void)newHttpMetric:(FlutterMethodCall *)call result:(FlutterResult)result { | ||
| 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]; | ||
|
|
||
| NSNumber *handle = call.arguments[@"httpMetricHandle"]; | ||
| [FLTFirebasePerformancePlugin addMethodHandler:handle methodHandler:handler]; | ||
|
|
||
| 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 |
111 changes: 111 additions & 0 deletions
111
packages/firebase_performance/ios/Classes/FLTHttpMetric.m
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| // 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+Internal.h" | ||
|
|
||
| @interface FLTHttpMetric () | ||
| @property FIRHTTPMetric *metric; | ||
| @end | ||
|
|
||
| @implementation FLTHttpMetric | ||
| - (instancetype _Nonnull)initWithHTTPMetric:(FIRHTTPMetric *)metric { | ||
| self = [self init]; | ||
| if (self) { | ||
| _metric = metric; | ||
| } | ||
|
|
||
| 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:call result: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 ([@"PerformanceAttributes#putAttribute" isEqualToString:call.method]) { | ||
| [self putAttribute:call result:result]; | ||
| } else if ([@"PerformanceAttributes#removeAttribute" isEqualToString:call.method]) { | ||
| [self removeAttribute:call result:result]; | ||
| } else if ([@"PerformanceAttributes#getAttributes" isEqualToString:call.method]) { | ||
| [self getAttributes:result]; | ||
| } else { | ||
| result(FlutterMethodNotImplemented); | ||
| } | ||
| } | ||
|
|
||
| - (void)start:(FlutterResult)result { | ||
| [_metric start]; | ||
| result(nil); | ||
| } | ||
|
|
||
| - (void)stop:(FlutterMethodCall *)call result:(FlutterResult)result { | ||
| [_metric stop]; | ||
|
|
||
| NSNumber *handle = call.arguments[@"handle"]; | ||
| [FLTFirebasePerformancePlugin removeMethodHandler:handle]; | ||
|
|
||
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| // 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+Internal.h" | ||
|
|
||
| @interface FLTTrace () | ||
| @property FIRTrace *trace; | ||
| @end | ||
|
|
||
| @implementation FLTTrace | ||
| - (instancetype _Nonnull)initWithTrace:(FIRTrace *)trace { | ||
| self = [self init]; | ||
| if (self) { | ||
| _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:call result: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 ([@"PerformanceAttributes#putAttribute" isEqualToString:call.method]) { | ||
| [self putAttribute:call result:result]; | ||
| } else if ([@"PerformanceAttributes#removeAttribute" isEqualToString:call.method]) { | ||
| [self removeAttribute:call result:result]; | ||
| } else if ([@"PerformanceAttributes#getAttributes" isEqualToString:call.method]) { | ||
| [self getAttributes:result]; | ||
| } else { | ||
| result(FlutterMethodNotImplemented); | ||
| } | ||
| } | ||
|
|
||
| - (void)start:(FlutterResult)result { | ||
| [_trace start]; | ||
| result(nil); | ||
| } | ||
|
|
||
| - (void)stop:(FlutterMethodCall *)call result:(FlutterResult)result { | ||
| [_trace stop]; | ||
|
|
||
| NSNumber *handle = call.arguments[@"handle"]; | ||
| [FLTFirebasePerformancePlugin removeMethodHandler:handle]; | ||
|
|
||
| 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 |
28 changes: 28 additions & 0 deletions
28
packages/firebase_performance/ios/Classes/FirebasePerformancePlugin+Internal.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // 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" | ||
|
|
||
| @protocol MethodCallHandler | ||
| @required | ||
| - (void)handleMethodCall:(FlutterMethodCall *_Nonnull)call result:(FlutterResult _Nonnull)result; | ||
| @end | ||
|
|
||
| @interface FLTFirebasePerformancePlugin (Internal) | ||
| + (void)addMethodHandler:(NSNumber *_Nonnull)handle | ||
| methodHandler:(id<MethodCallHandler> _Nonnull)handler; | ||
| + (void)removeMethodHandler:(NSNumber *_Nonnull)handle; | ||
| @end | ||
|
|
||
| @interface FLTFirebasePerformance : NSObject <MethodCallHandler> | ||
| + (instancetype _Nonnull)sharedInstance; | ||
| @end | ||
|
|
||
| @interface FLTTrace : NSObject <MethodCallHandler> | ||
| - (instancetype _Nonnull)initWithTrace:(FIRTrace *_Nonnull)trace; | ||
| @end | ||
|
|
||
| @interface FLTHttpMetric : NSObject <MethodCallHandler> | ||
| - (instancetype _Nonnull)initWithHTTPMetric:(FIRHTTPMetric *_Nonnull)metric; | ||
| @end |
1 change: 1 addition & 0 deletions
1
packages/firebase_performance/ios/Classes/FirebasePerformancePlugin.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reminder to address this