Skip to content

Commit

Permalink
big ref
Browse files Browse the repository at this point in the history
  • Loading branch information
brustolin committed Oct 14, 2024
1 parent 6b86347 commit 4c0b921
Show file tree
Hide file tree
Showing 21 changed files with 51 additions and 65 deletions.
12 changes: 5 additions & 7 deletions SentryTestUtils/TestCurrentDateProvider.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
@testable import Sentry

public class TestCurrentDateProvider: SentryCurrentDateProvider {
public class TestCurrentDateProvider: NSObject, SentryCurrentDateProvider {
public static let defaultStartingDate = Date(timeIntervalSinceReferenceDate: 0)
private var internalDate = defaultStartingDate
private var internalSystemTime: UInt64 = 0
Expand All @@ -10,10 +10,9 @@ public class TestCurrentDateProvider: SentryCurrentDateProvider {
private var _systemUptime: TimeInterval = 0

public override init() {

}

public override func date() -> Date {
public func date() -> Date {

defer {
if driftTimeForEveryRead {
Expand Down Expand Up @@ -51,15 +50,14 @@ public class TestCurrentDateProvider: SentryCurrentDateProvider {
}

public var timezoneOffsetValue = 0
public override func timezoneOffset() -> Int {
public func timezoneOffset() -> Int {
return timezoneOffsetValue
}

public override func systemTime() -> UInt64 {
public func systemTime() -> UInt64 {
return internalSystemTime
}

override public func systemUptime() -> TimeInterval {
public func systemUptime() -> TimeInterval {
_systemUptime
}
public func setSystemUptime(_ uptime: TimeInterval) {
Expand Down
3 changes: 2 additions & 1 deletion Sources/Sentry/SentryANRTrackerV1.m
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ - (void)detectANRs
NSInteger reportThreshold = 5;
NSTimeInterval sleepInterval = self.timeoutInterval / reportThreshold;

SentryCurrentDateProvider *dateProvider = SentryDependencyContainer.sharedInstance.dateProvider;
id<SentryCurrentDateProvider> dateProvider
= SentryDependencyContainer.sharedInstance.dateProvider;

// Canceling the thread can take up to sleepInterval.
while (YES) {
Expand Down
3 changes: 2 additions & 1 deletion Sources/Sentry/SentryANRTrackerV2.m
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ - (void)detectANRs
state = kSentryANRTrackerRunning;
}

SentryCurrentDateProvider *dateProvider = SentryDependencyContainer.sharedInstance.dateProvider;
id<SentryCurrentDateProvider> dateProvider
= SentryDependencyContainer.sharedInstance.dateProvider;

BOOL reported = NO;

Expand Down
4 changes: 2 additions & 2 deletions Sources/Sentry/SentryDateUtil.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

@interface SentryDateUtil ()

@property (nonatomic, strong) SentryCurrentDateProvider *currentDateProvider;
@property (nonatomic, strong) id<SentryCurrentDateProvider> currentDateProvider;

@end

@implementation SentryDateUtil

- (instancetype)initWithCurrentDateProvider:(SentryCurrentDateProvider *)currentDateProvider
- (instancetype)initWithCurrentDateProvider:(id<SentryCurrentDateProvider>)currentDateProvider
{
if (self = [super init]) {
self.currentDateProvider = currentDateProvider;
Expand Down
4 changes: 2 additions & 2 deletions Sources/Sentry/SentryDefaultRateLimits.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ @interface SentryDefaultRateLimits ()
@property (nonatomic, strong) SentryConcurrentRateLimitsDictionary *rateLimits;
@property (nonatomic, strong) SentryRetryAfterHeaderParser *retryAfterHeaderParser;
@property (nonatomic, strong) SentryRateLimitParser *rateLimitParser;
@property (nonatomic, strong) SentryCurrentDateProvider *currentDateProvider;
@property (nonatomic, strong) id<SentryCurrentDateProvider> currentDateProvider;
@property (nonatomic, strong) SentryDateUtil *dateUtil;

@end
Expand All @@ -25,7 +25,7 @@ @implementation SentryDefaultRateLimits
- (instancetype)initWithRetryAfterHeaderParser:
(SentryRetryAfterHeaderParser *)retryAfterHeaderParser
andRateLimitParser:(SentryRateLimitParser *)rateLimitParser
currentDateProvider:(SentryCurrentDateProvider *)currentDateProvider
currentDateProvider:(id<SentryCurrentDateProvider>)currentDateProvider
{
if (self = [super init]) {
self.rateLimits = [[SentryConcurrentRateLimitsDictionary alloc] init];
Expand Down
4 changes: 2 additions & 2 deletions Sources/Sentry/SentryDelayedFramesTracker.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@interface SentryDelayedFramesTracker ()

@property (nonatomic, assign) CFTimeInterval keepDelayedFramesDuration;
@property (nonatomic, strong, readonly) SentryCurrentDateProvider *dateProvider;
@property (nonatomic, strong, readonly) id<SentryCurrentDateProvider> dateProvider;
@property (nonatomic, strong) NSMutableArray<SentryDelayedFrame *> *delayedFrames;
@property (nonatomic) uint64_t lastDelayedFrameSystemTimestamp;
@property (nonatomic) uint64_t previousFrameSystemTimestamp;
Expand All @@ -23,7 +23,7 @@ @interface SentryDelayedFramesTracker ()
@implementation SentryDelayedFramesTracker

- (instancetype)initWithKeepDelayedFramesDuration:(CFTimeInterval)keepDelayedFramesDuration
dateProvider:(SentryCurrentDateProvider *)dateProvider
dateProvider:(id<SentryCurrentDateProvider>)dateProvider
{
if (self = [super init]) {
_keepDelayedFramesDuration = keepDelayedFramesDuration;
Expand Down
2 changes: 1 addition & 1 deletion Sources/Sentry/SentryDependencyContainer.m
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ - (instancetype)init
_threadWrapper = [[SentryThreadWrapper alloc] init];
_binaryImageCache = [[SentryBinaryImageCache alloc] init];
_debugImageProvider = [[SentryDebugImageProvider alloc] init];
_dateProvider = [[SentryCurrentDateProvider alloc] init];
_dateProvider = [[SentryDefaultCurrentDateProvider alloc] init];
}
return self;
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Sentry/SentryFramesTracker.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ @interface SentryFramesTracker ()
@property (nonatomic, assign, readonly) BOOL isStarted;

@property (nonatomic, strong, readonly) SentryDisplayLinkWrapper *displayLinkWrapper;
@property (nonatomic, strong, readonly) SentryCurrentDateProvider *dateProvider;
@property (nonatomic, strong, readonly) id<SentryCurrentDateProvider> dateProvider;
@property (nonatomic, strong, readonly) SentryDispatchQueueWrapper *dispatchQueueWrapper;
@property (nonatomic, strong) SentryNSNotificationCenterWrapper *notificationCenter;
@property (nonatomic, assign) CFTimeInterval previousFrameTimestamp;
Expand Down Expand Up @@ -65,7 +65,7 @@ @implementation SentryFramesTracker {
}

- (instancetype)initWithDisplayLinkWrapper:(SentryDisplayLinkWrapper *)displayLinkWrapper
dateProvider:(SentryCurrentDateProvider *)dateProvider
dateProvider:(id<SentryCurrentDateProvider>)dateProvider
dispatchQueueWrapper:(SentryDispatchQueueWrapper *)dispatchQueueWrapper
notificationCenter:(SentryNSNotificationCenterWrapper *)notificationCenter
keepDelayedFramesDuration:(CFTimeInterval)keepDelayedFramesDuration
Expand Down
4 changes: 2 additions & 2 deletions Sources/Sentry/SentryRateLimitParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

@interface SentryRateLimitParser ()

@property (nonatomic, strong) SentryCurrentDateProvider *currentDateProvider;
@property (nonatomic, strong) id<SentryCurrentDateProvider> currentDateProvider;

@end

@implementation SentryRateLimitParser

- (instancetype)initWithCurrentDateProvider:(SentryCurrentDateProvider *)currentDateProvider
- (instancetype)initWithCurrentDateProvider:(id<SentryCurrentDateProvider>)currentDateProvider
{
if (self = [super init]) {
self.currentDateProvider = currentDateProvider;
Expand Down
4 changes: 2 additions & 2 deletions Sources/Sentry/SentryRetryAfterHeaderParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
@interface SentryRetryAfterHeaderParser ()

@property (nonatomic, strong) SentryHttpDateParser *httpDateParser;
@property (nonatomic, strong) SentryCurrentDateProvider *currentDateProvider;
@property (nonatomic, strong) id<SentryCurrentDateProvider> currentDateProvider;

@end

@implementation SentryRetryAfterHeaderParser

- (instancetype)initWithHttpDateParser:(SentryHttpDateParser *)httpDateParser
currentDateProvider:(SentryCurrentDateProvider *)currentDateProvider
currentDateProvider:(id<SentryCurrentDateProvider>)currentDateProvider
{
if (self = [super init]) {
self.httpDateParser = httpDateParser;
Expand Down
2 changes: 1 addition & 1 deletion Sources/Sentry/SentryTransportFactory.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ @implementation SentryTransportFactory

+ (NSArray<id<SentryTransport>> *)initTransports:(SentryOptions *)options
sentryFileManager:(SentryFileManager *)sentryFileManager
currentDateProvider:(SentryCurrentDateProvider *)currentDateProvider
currentDateProvider:(id<SentryCurrentDateProvider>)currentDateProvider
{
NSURLSession *session;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
@class SentryBinaryImageCache;
@class SentryCrash;
@class SentryCrashWrapper;
@class SentryCurrentDateProvider;
@class SentryDebugImageProvider;
@class SentryDispatchFactory;
@class SentryDispatchQueueWrapper;
Expand All @@ -20,6 +19,7 @@
@class SentryThreadWrapper;
@class SentryThreadInspector;
@protocol SentryRandom;
@protocol SentryCurrentDateProvider;

#if SENTRY_HAS_METRIC_KIT
@class SentryMXManager;
Expand Down Expand Up @@ -66,7 +66,7 @@ SENTRY_NO_INIT
@property (nonatomic, strong) SentrySystemWrapper *systemWrapper;
@property (nonatomic, strong) SentryDispatchFactory *dispatchFactory;
@property (nonatomic, strong) SentryNSTimerFactory *timerFactory;
@property (nonatomic, strong) SentryCurrentDateProvider *dateProvider;
@property (nonatomic, strong) id<SentryCurrentDateProvider> dateProvider;
@property (nonatomic, strong) SentryBinaryImageCache *binaryImageCache;
@property (nonatomic, strong) SentryExtraContextProvider *extraContextProvider;
@property (nonatomic, strong) SentrySysctl *sysctlWrapper;
Expand Down
4 changes: 2 additions & 2 deletions Sources/Sentry/include/HybridPublic/SentryFramesTracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# import "SentryProfilingConditionals.h"

@class SentryDisplayLinkWrapper;
@class SentryCurrentDateProvider;
@protocol SentryCurrentDateProvider;
@class SentryDispatchQueueWrapper;
@class SentryNSNotificationCenterWrapper;
@class SentryScreenFrames;
Expand Down Expand Up @@ -33,7 +33,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface SentryFramesTracker : NSObject

- (instancetype)initWithDisplayLinkWrapper:(SentryDisplayLinkWrapper *)displayLinkWrapper
dateProvider:(SentryCurrentDateProvider *)dateProvider
dateProvider:(id<SentryCurrentDateProvider>)dateProvider
dispatchQueueWrapper:(SentryDispatchQueueWrapper *)dispatchQueueWrapper
notificationCenter:(SentryNSNotificationCenterWrapper *)notificationCenter
keepDelayedFramesDuration:(CFTimeInterval)keepDelayedFramesDuration;
Expand Down
4 changes: 2 additions & 2 deletions Sources/Sentry/include/SentryDateUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

NS_ASSUME_NONNULL_BEGIN

@class SentryCurrentDateProvider;
@protocol SentryCurrentDateProvider;

@interface SentryDateUtil : NSObject
SENTRY_NO_INIT

- (instancetype)initWithCurrentDateProvider:(SentryCurrentDateProvider *)currentDateProvider;
- (instancetype)initWithCurrentDateProvider:(id<SentryCurrentDateProvider>)currentDateProvider;

- (BOOL)isInFuture:(NSDate *_Nullable)date;

Expand Down
4 changes: 2 additions & 2 deletions Sources/Sentry/include/SentryDefaultRateLimits.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

@class SentryRetryAfterHeaderParser;
@class SentryRateLimitParser;
@class SentryCurrentDateProvider;
@protocol SentryCurrentDateProvider;

NS_ASSUME_NONNULL_BEGIN

Expand All @@ -19,7 +19,7 @@ NS_SWIFT_NAME(DefaultRateLimits)
- (instancetype)initWithRetryAfterHeaderParser:
(SentryRetryAfterHeaderParser *)retryAfterHeaderParser
andRateLimitParser:(SentryRateLimitParser *)rateLimitParser
currentDateProvider:(SentryCurrentDateProvider *)currentDateProvider;
currentDateProvider:(id<SentryCurrentDateProvider>)currentDateProvider;

@end

Expand Down
4 changes: 2 additions & 2 deletions Sources/Sentry/include/SentryDelayedFramesTracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#if SENTRY_HAS_UIKIT

@class SentryCurrentDateProvider;
@protocol SentryCurrentDateProvider;
@class SentryFramesDelayResult;

NS_ASSUME_NONNULL_BEGIN
Expand All @@ -19,7 +19,7 @@ SENTRY_NO_INIT
* @param dateProvider The instance of a date provider.
*/
- (instancetype)initWithKeepDelayedFramesDuration:(CFTimeInterval)keepDelayedFramesDuration
dateProvider:(SentryCurrentDateProvider *)dateProvider;
dateProvider:(id<SentryCurrentDateProvider>)dateProvider;

- (void)resetDelayedFramesTimeStamps;

Expand Down
4 changes: 2 additions & 2 deletions Sources/Sentry/include/SentryRateLimitParser.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#import "SentryDefines.h"

@class SentryCurrentDateProvider;
@protocol SentryCurrentDateProvider;

NS_ASSUME_NONNULL_BEGIN

Expand All @@ -16,7 +16,7 @@ NS_SWIFT_NAME(RateLimitParser)
@interface SentryRateLimitParser : NSObject
SENTRY_NO_INIT

- (instancetype)initWithCurrentDateProvider:(SentryCurrentDateProvider *)currentDateProvider;
- (instancetype)initWithCurrentDateProvider:(id<SentryCurrentDateProvider>)currentDateProvider;

- (NSDictionary<NSNumber *, NSDate *> *)parse:(NSString *)header;

Expand Down
4 changes: 2 additions & 2 deletions Sources/Sentry/include/SentryRetryAfterHeaderParser.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#import <Foundation/Foundation.h>

@class SentryHttpDateParser;
@class SentryCurrentDateProvider;
@protocol SentryCurrentDateProvider;

NS_ASSUME_NONNULL_BEGIN

Expand All @@ -13,7 +13,7 @@ NS_SWIFT_NAME(RetryAfterHeaderParser)
@interface SentryRetryAfterHeaderParser : NSObject

- (instancetype)initWithHttpDateParser:(SentryHttpDateParser *)httpDateParser
currentDateProvider:(SentryCurrentDateProvider *)currentDateProvider;
currentDateProvider:(id<SentryCurrentDateProvider>)currentDateProvider;

/** Parses the HTTP header into a NSDate.
Expand Down
4 changes: 2 additions & 2 deletions Sources/Sentry/include/SentryTransportFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#import "SentryTransport.h"

@class SentryOptions, SentryFileManager;
@class SentryCurrentDateProvider;
@protocol SentryCurrentDateProvider;

NS_ASSUME_NONNULL_BEGIN

Expand All @@ -12,7 +12,7 @@ NS_SWIFT_NAME(TransportInitializer)

+ (NSArray<id<SentryTransport>> *)initTransports:(SentryOptions *)options
sentryFileManager:(SentryFileManager *)sentryFileManager
currentDateProvider:(SentryCurrentDateProvider *)currentDateProvider;
currentDateProvider:(id<SentryCurrentDateProvider>)currentDateProvider;

@end

Expand Down
34 changes: 10 additions & 24 deletions Sources/Swift/Helper/SentryCurrentDateProvider.swift
Original file line number Diff line number Diff line change
@@ -1,37 +1,24 @@
@_implementationOnly import _SentryPrivate
import Foundation

#if TEST
@objcMembers
public class SentryCurrentDateProvider: NSObject {
public func date() -> Date {
return Date()
}

public func timezoneOffset() -> Int {
return TimeZone.current.secondsFromGMT()
}

public func systemTime() -> UInt64 {
getAbsoluteTime()
}

public func systemUptime() -> TimeInterval {
ProcessInfo.processInfo.systemUptime
}
@objc
protocol SentryCurrentDateProvider: NSObjectProtocol {
func date() -> Date
func timezoneOffset() -> Int
func systemTime() -> UInt64
func systemUptime() -> TimeInterval
}
#else

@objcMembers
class SentryCurrentDateProvider: NSObject {

class SentryDefaultCurrentDateProvider: NSObject, SentryCurrentDateProvider {
func date() -> Date {
return Date()
}

func timezoneOffset() -> Int {
return TimeZone.current.secondsFromGMT()
}

func systemTime() -> UInt64 {
getAbsoluteTime()
}
Expand All @@ -40,4 +27,3 @@ class SentryCurrentDateProvider: NSObject {
ProcessInfo.processInfo.systemUptime
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ class SentryOnDemandReplay: NSObject, SentryReplayVideoMaker {
convenience init(outputPath: String) {
self.init(outputPath: outputPath,
workingQueue: SentryDispatchQueueWrapper(name: "io.sentry.onDemandReplay", attributes: nil),
dateProvider: SentryCurrentDateProvider())
dateProvider: SentryDefaultCurrentDateProvider())
}

convenience init(withContentFrom outputPath: String) {
self.init(withContentFrom: outputPath,
workingQueue: SentryDispatchQueueWrapper(name: "io.sentry.onDemandReplay", attributes: nil),
dateProvider: SentryCurrentDateProvider())
dateProvider: SentryDefaultCurrentDateProvider())
}

func addFrameAsync(image: UIImage, forScreen: String?) {
Expand Down

0 comments on commit 4c0b921

Please sign in to comment.