Skip to content

Commit

Permalink
ref: Unify ANRTrackerDelegate
Browse files Browse the repository at this point in the history
Merge SentryANRTrackerDelegate and SentryANRTrackerDelegateV2 into one
implementation to reduce complexity.
  • Loading branch information
philipphofmann committed Sep 20, 2024
1 parent 394ad33 commit 5ff5827
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Sources/Sentry/SentryANRTracker.m
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ - (void)ANRDetected
}

for (id<SentryANRTrackerDelegate> target in localListeners) {
[target anrDetected];
[target anrDetectedWithType:SentryANRTypeUnknown];
}
}

Expand Down
10 changes: 5 additions & 5 deletions Sources/Sentry/SentryANRTrackerV2.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ @interface SentryANRTrackerV2 ()
@property (nonatomic, strong) SentryCrashWrapper *crashWrapper;
@property (nonatomic, strong) SentryDispatchQueueWrapper *dispatchQueueWrapper;
@property (nonatomic, strong) SentryThreadWrapper *threadWrapper;
@property (nonatomic, strong) NSHashTable<id<SentryANRTrackerV2Delegate>> *listeners;
@property (nonatomic, strong) NSHashTable<id<SentryANRTrackerDelegate>> *listeners;
@property (nonatomic, strong) SentryFramesTracker *framesTracker;
@property (nonatomic, assign) NSTimeInterval timeoutInterval;

Expand Down Expand Up @@ -199,7 +199,7 @@ - (void)ANRDetected:(enum SentryANRType)type
localListeners = [self.listeners allObjects];
}

for (id<SentryANRTrackerV2Delegate> target in localListeners) {
for (id<SentryANRTrackerDelegate> target in localListeners) {
[target anrDetectedWithType:type];
}
}
Expand All @@ -211,12 +211,12 @@ - (void)ANRStopped
targets = [self.listeners allObjects];
}

for (id<SentryANRTrackerV2Delegate> target in targets) {
for (id<SentryANRTrackerDelegate> target in targets) {
[target anrStopped];
}
}

- (void)addListener:(id<SentryANRTrackerV2Delegate>)listener
- (void)addListener:(id<SentryANRTrackerDelegate>)listener
{
@synchronized(self.listeners) {
[self.listeners addObject:listener];
Expand All @@ -234,7 +234,7 @@ - (void)addListener:(id<SentryANRTrackerV2Delegate>)listener
}
}

- (void)removeListener:(id<SentryANRTrackerV2Delegate>)listener
- (void)removeListener:(id<SentryANRTrackerDelegate>)listener
{
@synchronized(self.listeners) {
[self.listeners removeObject:listener];
Expand Down
2 changes: 1 addition & 1 deletion Sources/Sentry/SentryANRTrackingIntegration.m
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ - (void)dealloc
[self uninstall];
}

- (void)anrDetected
- (void)anrDetectedWithType:(enum SentryANRType)type
{
if (self.reportAppHangs == NO) {
SENTRY_LOG_DEBUG(@"AppHangTracking paused. Ignoring reported app hang.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ - (void)uninstall
[self.anrTracker removeListener:self];
}

- (void)anrDetected
- (void)anrDetectedWithType:(enum SentryANRType)type
{
[self.appStateManager
updateAppState:^(SentryAppState *appState) { appState.isANROngoing = YES; }];
Expand Down
12 changes: 1 addition & 11 deletions Sources/Sentry/include/SentryANRTracker.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#import "SentryDefines.h"
#import "SentrySwift.h"

@class SentryOptions, SentryCrashWrapper, SentryDispatchQueueWrapper, SentryThreadWrapper;

Expand Down Expand Up @@ -36,15 +37,4 @@ SENTRY_NO_INIT

@end

/**
* The ``SentryANRTracker`` calls the methods from background threads.
*/
@protocol SentryANRTrackerDelegate <NSObject>

- (void)anrDetected;

- (void)anrStopped;

@end

NS_ASSUME_NONNULL_END
4 changes: 2 additions & 2 deletions Sources/Sentry/include/SentryANRTrackerV2.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ SENTRY_NO_INIT
threadWrapper:(SentryThreadWrapper *)threadWrapper
framesTracker:(SentryFramesTracker *)framesTracker;

- (void)addListener:(id<SentryANRTrackerV2Delegate>)listener;
- (void)addListener:(id<SentryANRTrackerDelegate>)listener;

- (void)removeListener:(id<SentryANRTrackerV2Delegate>)listener;
- (void)removeListener:(id<SentryANRTrackerDelegate>)listener;

// Function used for tests
- (void)clear;
Expand Down
2 changes: 1 addition & 1 deletion Sources/Sentry/include/SentryANRTrackingIntegrationV2.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ NS_ASSUME_NONNULL_BEGIN
static NSString *const SentryANRExceptionTypeV2 = @"App Hanging";

@interface SentryANRTrackingIntegrationV2
: SentryBaseIntegration <SentryIntegrationProtocol, SentryANRTrackerV2Delegate>
: SentryBaseIntegration <SentryIntegrationProtocol, SentryANRTrackerDelegate>

- (void)pauseAppHangTracking;
- (void)resumeAppHangTracking;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Foundation

/// The methods are called from a background thread.
@objc
protocol SentryANRTrackerV2Delegate {
protocol SentryANRTrackerDelegate {
func anrDetected(type: SentryANRType)
func anrStopped()
}
Expand All @@ -10,4 +11,5 @@ protocol SentryANRTrackerV2Delegate {
enum SentryANRType: Int {
case fullyBlocking
case nonFullyBlocking
case unknown
}
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class SentryANRTrackerTests: XCTestCase, SentryANRTrackerDelegate {
XCTAssertEqual(1, fixture.threadWrapper.threadFinishedInvocations.count)
}

func anrDetected() {
func anrDetected(type: Sentry.SentryANRType) {
anrDetectedExpectation.fulfill()
}

Expand All @@ -231,7 +231,7 @@ class SentryANRTrackerTestDelegate: NSObject, SentryANRTrackerDelegate {
anrStoppedExpectation.fulfill()
}

func anrDetected() {
func anrDetected(type: Sentry.SentryANRType) {
anrDetectedExpectation.fulfill()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ class SentryANRTrackerV2Tests: XCTestCase {

}

class SentryANRTrackerV2TestDelegate: NSObject, SentryANRTrackerV2Delegate {
class SentryANRTrackerV2TestDelegate: NSObject, SentryANRTrackerDelegate {

let anrDetectedExpectation = XCTestExpectation(description: "Test Delegate ANR Detection")
let anrStoppedExpectation = XCTestExpectation(description: "Test Delegate ANR Stopped")
Expand Down

0 comments on commit 5ff5827

Please sign in to comment.