summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabian Guerra <fabian.guerra@mapbox.com>2019-03-05 16:24:05 -0800
committerFabian Guerra <fabian.guerra@mapbox.com>2019-03-28 15:05:26 -0700
commit1cc38bebf022f87a3b5698162028255f0c99c325 (patch)
tree34f36b17a173ed2bb9355507ab7accdfe6275685
parenta2f0ce505b6f714f130746be7cb9409667174cbc (diff)
downloadqtlocation-mapboxgl-1cc38bebf022f87a3b5698162028255f0c99c325.tar.gz
[ios, macos] Make MGLMetricsDelegate follow delegate convention.
-rw-r--r--platform/darwin/src/MGLMetricsManager.h5
-rw-r--r--platform/darwin/src/MGLMetricsManager.m8
-rw-r--r--platform/darwin/src/MGLMetricsManager_Private.h4
-rw-r--r--platform/darwin/src/MGLNetworkConfiguration.m7
-rw-r--r--platform/ios/app/MBXAppDelegate.m2
5 files changed, 16 insertions, 10 deletions
diff --git a/platform/darwin/src/MGLMetricsManager.h b/platform/darwin/src/MGLMetricsManager.h
index 73756cebed..29fd5c79f8 100644
--- a/platform/darwin/src/MGLMetricsManager.h
+++ b/platform/darwin/src/MGLMetricsManager.h
@@ -7,10 +7,13 @@ typedef NS_ENUM(NSUInteger, MGLMetricType) {
MGLMetricTypePerformance = 0,
};
+FOUNDATION_EXTERN MGL_EXPORT NSString* MGLStringFromMetricType(MGLMetricType metricType);
+
+@class MGLMetricsManager;
@protocol MGLMetricsDelegate <NSObject>
- (BOOL)shouldHandleMetric:(MGLMetricType)metricType;
-- (void)didCollectMetric:(MGLMetricType)metricType withAttributes:(NSDictionary *)attributes;
+- (void)metricsManager:(MGLMetricsManager *)metricsManager didCollectMetric:(MGLMetricType)metricType withAttributes:(NSDictionary *)attributes;
@end
diff --git a/platform/darwin/src/MGLMetricsManager.m b/platform/darwin/src/MGLMetricsManager.m
index 75dc593aa7..cdc392ce40 100644
--- a/platform/darwin/src/MGLMetricsManager.m
+++ b/platform/darwin/src/MGLMetricsManager.m
@@ -5,6 +5,10 @@
NSString * const kMGLPerformanceMetric = @"mobile.performance_trace";
+NSString* MGLStringFromMetricType(MGLMetricType metricType) {
+ return [@[kMGLPerformanceMetric] objectAtIndex:metricType];
+}
+
@implementation MGLMetricsManager
+ (instancetype)sharedManager
@@ -17,9 +21,9 @@ NSString * const kMGLPerformanceMetric = @"mobile.performance_trace";
return sharedConfiguration;
}
-- (void)handleMetricEvent:(MGLMetricType)metricType withAttributes:(NSDictionary *)attributes {
+- (void)handleMetricsEvent:(MGLMetricType)metricType withAttributes:(NSDictionary *)attributes {
if ([self.delegate shouldHandleMetric:metricType]) {
- [self.delegate didCollectMetric:metricType withAttributes:attributes];
+ [self.delegate metricsManager:self didCollectMetric:metricType withAttributes:attributes];
}
}
diff --git a/platform/darwin/src/MGLMetricsManager_Private.h b/platform/darwin/src/MGLMetricsManager_Private.h
index 4a32710925..a2b2d9548c 100644
--- a/platform/darwin/src/MGLMetricsManager_Private.h
+++ b/platform/darwin/src/MGLMetricsManager_Private.h
@@ -2,11 +2,11 @@
NS_ASSUME_NONNULL_BEGIN
-extern NSString *const kMGLPerformanceMetric;
+FOUNDATION_EXTERN MGL_EXPORT NSString *const kMGLPerformanceMetric;
@interface MGLMetricsManager (Private)
-- (void)handleMetricEvent:(MGLMetricType)metricType withAttributes:(NSDictionary *)attributes;
+- (void)handleMetricsEvent:(MGLMetricType)metricType withAttributes:(NSDictionary *)attributes;
@end
diff --git a/platform/darwin/src/MGLNetworkConfiguration.m b/platform/darwin/src/MGLNetworkConfiguration.m
index 5682e0bc1e..f938bcc753 100644
--- a/platform/darwin/src/MGLNetworkConfiguration.m
+++ b/platform/darwin/src/MGLNetworkConfiguration.m
@@ -1,7 +1,6 @@
#import "MGLNetworkConfiguration_Private.h"
#import "MGLMetricsManager_Private.h"
-NSString * const kMGLDownloadPerformanceEvent = @"mobile.performance_trace";
static NSString * const MGLStartTime = @"start_time";
static NSString * const MGLResourceType = @"resource_type";
@@ -73,7 +72,7 @@ static NSString * const MGLResourceType = @"resource_type";
{
if (urlString && [self.events objectForKey:urlString]) {
NSDictionary *eventAttributes = [self eventAttributesForURL:urlString withAction:action];
- [[MGLMetricsManager sharedManager] handleMetricEvent:MGLMetricTypePerformance withAttributes:eventAttributes];
+ [[MGLMetricsManager sharedManager] handleMetricsEvent:MGLMetricTypePerformance withAttributes:eventAttributes];
[self.events removeObjectForKey:urlString];
}
}
@@ -94,9 +93,9 @@ static NSString * const MGLResourceType = @"resource_type";
if (action) {
[attributes addObject:@{ @"name" : @"action" , @"value" : action }];
}
-
+ NSString *event = MGLStringFromMetricType(MGLMetricTypePerformance);
return @{
- @"event" : kMGLPerformanceMetric,
+ @"event" : event,
@"created" : createdDate,
@"sessionId" : [NSUUID UUID].UUIDString,
@"counters" : @[ @{ @"name" : @"elapsed_time" , @"value" : @(elapsedTime) } ],
diff --git a/platform/ios/app/MBXAppDelegate.m b/platform/ios/app/MBXAppDelegate.m
index a49a1651e2..1216c98dd6 100644
--- a/platform/ios/app/MBXAppDelegate.m
+++ b/platform/ios/app/MBXAppDelegate.m
@@ -56,7 +56,7 @@ NSString * const MBXMapboxAccessTokenDefaultsKey = @"MBXMapboxAccessToken";
return YES;
}
-- (void)didCollectMetric:(MGLMetricType)metricType withAttributes:(NSDictionary *)attributes {
+- (void)metricsManager:(MGLMetricsManager *)metricsManager didCollectMetric:(MGLMetricType)metricType withAttributes:(NSDictionary *)attributes {
[[MGLMetricsManager sharedManager] pushMetric:metricType withAttributes:attributes];
}