From 3139eac9599adf01322a5c308f3a02355aa31b3c Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Mon, 4 Dec 2023 15:39:54 -0900 Subject: [PATCH] fix: implify dispatch queue wrapper access --- Sources/Sentry/SentryTracer.m | 36 +++++++++++-------- .../SentryUIEventTrackerTransactionMode.m | 6 +--- .../Sentry/SentryUIEventTrackingIntegration.m | 7 ++-- .../include/SentryTracerConfiguration.h | 5 --- .../SentryUIEventTrackerTransactionMode.h | 5 +-- 5 files changed, 25 insertions(+), 34 deletions(-) diff --git a/Sources/Sentry/SentryTracer.m b/Sources/Sentry/SentryTracer.m index 04f21900122..145ccf15fb3 100644 --- a/Sources/Sentry/SentryTracer.m +++ b/Sources/Sentry/SentryTracer.m @@ -195,16 +195,18 @@ - (void)dispatchIdleTimeout { @synchronized(_idleTimeoutLock) { if (_idleTimeoutBlock != NULL) { - [_configuration.dispatchQueueWrapper dispatchCancel:_idleTimeoutBlock]; + [SentryDependencyContainer.sharedInstance.dispatchQueueWrapper + dispatchCancel:_idleTimeoutBlock]; } __weak SentryTracer *weakSelf = self; - _idleTimeoutBlock = [_configuration.dispatchQueueWrapper createDispatchBlock:^{ - if (weakSelf == nil) { - SENTRY_LOG_DEBUG(@"WeakSelf is nil. Not doing anything."); - return; - } - [weakSelf finishInternal]; - }]; + _idleTimeoutBlock = + [SentryDependencyContainer.sharedInstance.dispatchQueueWrapper createDispatchBlock:^{ + if (weakSelf == nil) { + SENTRY_LOG_DEBUG(@"WeakSelf is nil. Not doing anything."); + return; + } + [weakSelf finishInternal]; + }]; if (_idleTimeoutBlock == NULL) { SENTRY_LOG_WARN(@"Couldn't create idle time out block. Can't schedule idle timeout. " @@ -212,15 +214,17 @@ - (void)dispatchIdleTimeout // If the transaction has no children, the SDK will discard it. [self finishInternal]; } else { - [_configuration.dispatchQueueWrapper dispatchAfter:_configuration.idleTimeout - block:_idleTimeoutBlock]; + [SentryDependencyContainer.sharedInstance.dispatchQueueWrapper + dispatchAfter:_configuration.idleTimeout + block:_idleTimeoutBlock]; } } } - (BOOL)hasIdleTimeout { - return _configuration.idleTimeout > 0 && _configuration.dispatchQueueWrapper != nil; + return _configuration.idleTimeout > 0 + && SentryDependencyContainer.sharedInstance.dispatchQueueWrapper != nil; } - (BOOL)isAutoGeneratedTransaction @@ -232,7 +236,8 @@ - (void)cancelIdleTimeout { @synchronized(_idleTimeoutLock) { if ([self hasIdleTimeout]) { - [_configuration.dispatchQueueWrapper dispatchCancel:_idleTimeoutBlock]; + [SentryDependencyContainer.sharedInstance.dispatchQueueWrapper + dispatchCancel:_idleTimeoutBlock]; } } } @@ -240,7 +245,7 @@ - (void)cancelIdleTimeout - (void)startDeadlineTimer { __weak SentryTracer *weakSelf = self; - [_configuration.dispatchQueueWrapper dispatchOnMainQueue:^{ + [SentryDependencyContainer.sharedInstance.dispatchQueueWrapper dispatchOnMainQueue:^{ weakSelf.deadlineTimer = [weakSelf.configuration.timerFactory scheduledTimerWithTimeInterval:SENTRY_AUTO_TRANSACTION_DEADLINE repeats:NO @@ -282,7 +287,7 @@ - (void)cancelDeadlineTimer // The timer must be invalidated from the thread on which the timer was installed, see // https://developer.apple.com/documentation/foundation/nstimer/1415405-invalidate#1770468 - [_configuration.dispatchQueueWrapper dispatchOnMainQueue:^{ + [SentryDependencyContainer.sharedInstance.dispatchQueueWrapper dispatchOnMainQueue:^{ if (weakSelf == nil) { SENTRY_LOG_DEBUG(@"WeakSelf is nil. Not invalidating deadlineTimer."); return; @@ -441,7 +446,8 @@ - (void)canBeFinished } if (!self.wasFinishCalled || hasUnfinishedChildSpansToWaitFor) { - SENTRY_LOG_DEBUG(@"Span with id %@ has children but isn't waiting for them right now.", + SENTRY_LOG_DEBUG(@"Span with id %@ has children but hasn't finished yet so isn't waiting " + @"for them right now.", self.spanId.sentrySpanIdString); return; } diff --git a/Sources/Sentry/SentryUIEventTrackerTransactionMode.m b/Sources/Sentry/SentryUIEventTrackerTransactionMode.m index 781fc808598..095040c1a49 100644 --- a/Sources/Sentry/SentryUIEventTrackerTransactionMode.m +++ b/Sources/Sentry/SentryUIEventTrackerTransactionMode.m @@ -19,7 +19,6 @@ @interface SentryUIEventTrackerTransactionMode () -@property (nonatomic, strong) SentryDispatchQueueWrapper *dispatchQueueWrapper; @property (nonatomic, assign) NSTimeInterval idleTimeout; @property (nullable, nonatomic, strong) NSMutableArray *activeTransactions; @@ -27,11 +26,9 @@ @implementation SentryUIEventTrackerTransactionMode -- (instancetype)initWithDispatchQueueWrapper:(SentryDispatchQueueWrapper *)dispatchQueueWrapper - idleTimeout:(NSTimeInterval)idleTimeout +- (instancetype)initWithIdleTimeout:(NSTimeInterval)idleTimeout { if (self = [super init]) { - self.dispatchQueueWrapper = dispatchQueueWrapper; self.idleTimeout = idleTimeout; self.activeTransactions = [NSMutableArray new]; } @@ -91,7 +88,6 @@ - (void)handleUIEvent:(NSString *)action SentryTracerConfiguration *config) { config.idleTimeout = self.idleTimeout; config.waitForChildren = YES; - config.dispatchQueueWrapper = self.dispatchQueueWrapper; }]]; SENTRY_LOG_DEBUG(@"Automatically started a new transaction with name: " diff --git a/Sources/Sentry/SentryUIEventTrackingIntegration.m b/Sources/Sentry/SentryUIEventTrackingIntegration.m index 130b3792b3a..e35db492bb5 100644 --- a/Sources/Sentry/SentryUIEventTrackingIntegration.m +++ b/Sources/Sentry/SentryUIEventTrackingIntegration.m @@ -2,7 +2,6 @@ #if SENTRY_HAS_UIKIT -# import # import # import # import @@ -25,10 +24,8 @@ - (BOOL)installWithOptions:(SentryOptions *)options return NO; } - SentryDependencyContainer *dependencies = [SentryDependencyContainer sharedInstance]; - SentryUIEventTrackerTransactionMode *mode = [[SentryUIEventTrackerTransactionMode alloc] - initWithDispatchQueueWrapper:dependencies.dispatchQueueWrapper - idleTimeout:options.idleTimeout]; + SentryUIEventTrackerTransactionMode *mode = + [[SentryUIEventTrackerTransactionMode alloc] initWithIdleTimeout:options.idleTimeout]; self.uiEventTracker = [[SentryUIEventTracker alloc] initWithMode:mode]; diff --git a/Sources/Sentry/include/SentryTracerConfiguration.h b/Sources/Sentry/include/SentryTracerConfiguration.h index cb38c47745f..5b81a0ffbb4 100644 --- a/Sources/Sentry/include/SentryTracerConfiguration.h +++ b/Sources/Sentry/include/SentryTracerConfiguration.h @@ -26,11 +26,6 @@ NS_ASSUME_NONNULL_BEGIN */ @property (nonatomic) BOOL waitForChildren; -/** - * A dispatch queue wrapper to intermediate between the tracer and dispatch calls. - */ -@property (nonatomic, strong, nullable) SentryDispatchQueueWrapper *dispatchQueueWrapper; - #if SENTRY_TARGET_PROFILING_SUPPORTED /** * Whether to sample a profile corresponding to this transaction diff --git a/Sources/Sentry/include/SentryUIEventTrackerTransactionMode.h b/Sources/Sentry/include/SentryUIEventTrackerTransactionMode.h index 4df6f1ea968..43b24d65d30 100644 --- a/Sources/Sentry/include/SentryUIEventTrackerTransactionMode.h +++ b/Sources/Sentry/include/SentryUIEventTrackerTransactionMode.h @@ -2,15 +2,12 @@ #if SENTRY_HAS_UIKIT -@class SentryDispatchQueueWrapper; - NS_ASSUME_NONNULL_BEGIN @interface SentryUIEventTrackerTransactionMode : NSObject SENTRY_NO_INIT -- (instancetype)initWithDispatchQueueWrapper:(SentryDispatchQueueWrapper *)dispatchQueueWrapper - idleTimeout:(NSTimeInterval)idleTimeout; +- (instancetype)initWithIdleTimeout:(NSTimeInterval)idleTimeout; @end