Prefer "app is ready" flag to "storage is ready" flag.

This commit is contained in:
Matthew Chen 2018-01-30 11:34:00 -05:00
parent be1fde905c
commit a30170b3b2
7 changed files with 25 additions and 15 deletions

View File

@ -946,7 +946,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
DDLogInfo(@"%@ ensureRootViewController", self.logTag);
if (![OWSStorage isStorageReady] || self.hasInitialRootViewController) {
if (!AppReadiness.isAppReady || self.hasInitialRootViewController) {
return;
}
self.hasInitialRootViewController = YES;

View File

@ -4,6 +4,7 @@
#import "OWSBatchMessageProcessor.h"
#import "AppContext.h"
#import "AppReadiness.h"
#import "NSArray+OWS.h"
#import "OWSBackgroundTask.h"
#import "OWSMessageManager.h"
@ -262,8 +263,8 @@ NSString *const OWSMessageContentJobFinderExtensionGroup = @"OWSMessageContentJo
_isDrainingQueue = NO;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(storageIsReady)
name:StorageIsReadyNotification
selector:@selector(appIsReady)
name:AppIsReadyNotification
object:nil];
return self;
@ -274,7 +275,7 @@ NSString *const OWSMessageContentJobFinderExtensionGroup = @"OWSMessageContentJo
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)storageIsReady
- (void)appIsReady
{
[self drainQueue];
}
@ -307,7 +308,7 @@ NSString *const OWSMessageContentJobFinderExtensionGroup = @"OWSMessageContentJo
}
dispatch_async(self.serialQueue, ^{
if (![OWSStorage isStorageReady]) {
if (!AppReadiness.isAppReady) {
// We don't want to process incoming messages until storage is ready.
return;
}

View File

@ -4,6 +4,7 @@
#import "OWSMessageReceiver.h"
#import "AppContext.h"
#import "AppReadiness.h"
#import "NSArray+OWS.h"
#import "OWSBackgroundTask.h"
#import "OWSBatchMessageProcessor.h"
@ -242,8 +243,8 @@ NSString *const OWSMessageDecryptJobFinderExtensionGroup = @"OWSMessageProcessin
_isDrainingQueue = NO;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(storageIsReady)
name:StorageIsReadyNotification
selector:@selector(appIsReady)
name:AppIsReadyNotification
object:nil];
return self;
@ -254,7 +255,7 @@ NSString *const OWSMessageDecryptJobFinderExtensionGroup = @"OWSMessageProcessin
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)storageIsReady
- (void)appIsReady
{
[self drainQueue];
}
@ -284,7 +285,7 @@ NSString *const OWSMessageDecryptJobFinderExtensionGroup = @"OWSMessageProcessin
}
dispatch_async(self.serialQueue, ^{
if (![OWSStorage isStorageReady]) {
if (!AppReadiness.isAppReady) {
// We don't want to process incoming messages until storage is ready.
return;
}

View File

@ -1,8 +1,9 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSReadReceiptManager.h"
#import "AppReadiness.h"
#import "NSNotificationCenter+OWS.h"
#import "OWSLinkedDeviceReadReceipt.h"
#import "OWSMessageSender.h"
@ -177,8 +178,8 @@ NSString *const OWSReadReceiptManagerAreReadReceiptsEnabled = @"areReadReceiptsE
OWSSingletonAssert();
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(storageIsReady)
name:StorageIsReadyNotification
selector:@selector(appIsReady)
name:AppIsReadyNotification
object:nil];
// Try to start processing.
@ -192,7 +193,7 @@ NSString *const OWSReadReceiptManagerAreReadReceiptsEnabled = @"areReadReceiptsE
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)storageIsReady
- (void)appIsReady
{
[self scheduleProcessing];
}
@ -203,7 +204,7 @@ NSString *const OWSReadReceiptManagerAreReadReceiptsEnabled = @"areReadReceiptsE
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
@synchronized(self)
{
if (![OWSStorage isStorageReady]) {
if (!AppReadiness.isAppReady) {
DDLogInfo(@"%@ Deferring read receipt processing; storage not yet ready.", self.logTag);
return;
}

View File

@ -4,6 +4,8 @@
NS_ASSUME_NONNULL_BEGIN
extern NSString *const AppIsReadyNotification;
typedef void (^AppReadyBlock)(void);
@interface AppReadiness : NSObject

View File

@ -3,9 +3,12 @@
//
#import "AppReadiness.h"
#import "NSNotificationCenter+OWS.h"
NS_ASSUME_NONNULL_BEGIN
NSString *const AppIsReadyNotification = @"AppIsReadyNotification";
@interface AppReadiness ()
@property (atomic) BOOL isAppReady;
@ -82,6 +85,8 @@ NS_ASSUME_NONNULL_BEGIN
self.isAppReady = YES;
[self runAppReadyBlocks];
[[NSNotificationCenter defaultCenter] postNotificationNameAsync:AppIsReadyNotification object:nil userInfo:nil];
}
- (void)runAppReadyBlocks

View File

@ -282,7 +282,7 @@ public class ShareViewController: UINavigationController, ShareViewDelegate, SAE
private func ensureRootViewController() {
Logger.debug("\(self.logTag) \(#function)")
guard OWSStorage.isStorageReady() else {
guard AppReadiness.isAppReady() else {
return
}
guard !hasInitialRootViewController else {