Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Crashlytics/Crashlytics/Models/FIRCLSSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;
- (instancetype)initWithFileManager:(FIRCLSFileManager *)fileManager
appIDModel:(FIRCLSApplicationIdentifierModel *)appIDModel
NS_DESIGNATED_INITIALIZER;
appIDModel:(FIRCLSApplicationIdentifierModel *)appIDModel;

/**
* Recreates the settings dictionary by re-reading the settings file from persistent storage. This
Expand Down
19 changes: 14 additions & 5 deletions Crashlytics/Crashlytics/Models/FIRCLSSettings.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,23 @@ @interface FIRCLSSettings ()

@property(nonatomic) BOOL isCacheKeyExpired;

@property(nonatomic) dispatch_queue_t deletionQueue;

@end

@implementation FIRCLSSettings

- (instancetype)initWithFileManager:(FIRCLSFileManager *)fileManager
appIDModel:(FIRCLSApplicationIdentifierModel *)appIDModel {
return
[self initWithFileManager:fileManager
appIDModel:appIDModel
deletionQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0)];
}

- (instancetype)initWithFileManager:(FIRCLSFileManager *)fileManager
appIDModel:(FIRCLSApplicationIdentifierModel *)appIDModel
deletionQueue:(dispatch_queue_t)deletionQueue {
self = [super init];
if (!self) {
return nil;
Expand All @@ -57,6 +68,8 @@ - (instancetype)initWithFileManager:(FIRCLSFileManager *)fileManager
_settingsDictionary = nil;
_isCacheKeyExpired = NO;

_deletionQueue = deletionQueue;

return self;
}

Expand Down Expand Up @@ -190,19 +203,15 @@ - (NSDictionary *)loadCacheKey {

- (void)deleteCachedSettings {
__weak FIRCLSSettings *weakSelf = self;
#ifndef FIREBASE_IS_NIGHTLY_TESTING
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
#endif
dispatch_async(_deletionQueue, ^{
__strong FIRCLSSettings *strongSelf = weakSelf;
if ([strongSelf.fileManager fileExistsAtPath:strongSelf.fileManager.settingsFilePath]) {
[strongSelf.fileManager removeItemAtPath:strongSelf.fileManager.settingsFilePath];
}
if ([strongSelf.fileManager fileExistsAtPath:strongSelf.fileManager.settingsCacheKeyPath]) {
[strongSelf.fileManager removeItemAtPath:strongSelf.fileManager.settingsCacheKeyPath];
}
#ifndef FIREBASE_IS_NIGHTLY_TESTING
});
#endif

@synchronized(self) {
self.isCacheKeyExpired = YES;
Expand Down
13 changes: 10 additions & 3 deletions Crashlytics/UnitTests/FIRCLSSettingsTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ @interface FIRCLSSettings (Testing)

@property(nonatomic, strong) NSDictionary<NSString *, id> *settingsDictionary;

- (instancetype)initWithFileManager:(FIRCLSFileManager *)fileManager
appIDModel:(FIRCLSApplicationIdentifierModel *)appIDModel
deletionQueue:(dispatch_queue_t)deletionQueue;

@end

@interface FIRCLSSettingsTests : XCTestCase
Expand All @@ -75,15 +79,18 @@ @implementation FIRCLSSettingsTests

- (void)setUp {
[super setUp];

_fileManager = [[FIRCLSMockFileManager alloc] init];

_appIDModel = [[FABMockApplicationIdentifierModel alloc] init];
_appIDModel.buildInstanceID = FIRCLSDefaultMockBuildInstanceID;
_appIDModel.displayVersion = FIRCLSDefaultMockAppDisplayVersion;
_appIDModel.buildVersion = FIRCLSDefaultMockAppBuildVersion;

_settings = [[FIRCLSSettings alloc] initWithFileManager:_fileManager appIDModel:_appIDModel];
// Inject a higher priority queue for deletion operations to reduce flakes.
_settings = [[FIRCLSSettings alloc]
initWithFileManager:_fileManager
appIDModel:_appIDModel
deletionQueue:dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0)];
}

- (void)testDefaultSettings {
Expand Down Expand Up @@ -134,7 +141,7 @@ - (void)cacheSettingsWithGoogleAppID:(NSString *)googleAppID

[self.settings cacheSettingsWithGoogleAppID:googleAppID currentTimestamp:currentTimestamp];

[self waitForExpectations:@[ self.fileManager.removeExpectation ] timeout:1];
[self waitForExpectations:@[ self.fileManager.removeExpectation ] timeout:5.0];
}

- (void)reloadFromCacheWithGoogleAppID:(NSString *)googleAppID
Expand Down
Loading