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

pull/1/head
Matthew Chen 7 years ago
parent be1fde905c
commit a30170b3b2

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

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

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

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

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

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

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

Loading…
Cancel
Save