From a9120906fa0956ed83bf9442b43b8a23021c853c Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Tue, 27 Nov 2018 11:49:30 -0500 Subject: [PATCH] Convert backup logic to use promises. --- .../OWSBackupSettingsViewController.m | 16 ++++++++-------- .../ViewControllers/DebugUI/DebugUIBackup.m | 18 ++++++++---------- Signal/src/util/Backup/OWSBackup.m | 6 ++---- Signal/src/util/Backup/OWSBackupExportJob.m | 14 +++++--------- Signal/src/util/Backup/OWSBackupImportJob.m | 14 +++++--------- 5 files changed, 28 insertions(+), 40 deletions(-) diff --git a/Signal/src/ViewControllers/AppSettings/OWSBackupSettingsViewController.m b/Signal/src/ViewControllers/AppSettings/OWSBackupSettingsViewController.m index 4a96353e3..f02cf6f3a 100644 --- a/Signal/src/ViewControllers/AppSettings/OWSBackupSettingsViewController.m +++ b/Signal/src/ViewControllers/AppSettings/OWSBackupSettingsViewController.m @@ -74,16 +74,16 @@ NS_ASSUME_NONNULL_BEGIN __weak OWSBackupSettingsViewController *weakSelf = self; [[self.backup checkCloudKitAccess] .then(^{ - dispatch_async(dispatch_get_main_queue(), ^{ - weakSelf.iCloudError = nil; - [weakSelf updateTableContents]; - }); + OWSAssertIsOnMainThread(); + + weakSelf.iCloudError = nil; + [weakSelf updateTableContents]; }) .catch(^(NSError *error) { - dispatch_async(dispatch_get_main_queue(), ^{ - weakSelf.iCloudError = error; - [weakSelf updateTableContents]; - }); + OWSAssertIsOnMainThread(); + + weakSelf.iCloudError = error; + [weakSelf updateTableContents]; }) retainUntilComplete]; } diff --git a/Signal/src/ViewControllers/DebugUI/DebugUIBackup.m b/Signal/src/ViewControllers/DebugUI/DebugUIBackup.m index 79a013d21..52201a886 100644 --- a/Signal/src/ViewControllers/DebugUI/DebugUIBackup.m +++ b/Signal/src/ViewControllers/DebugUI/DebugUIBackup.m @@ -90,16 +90,14 @@ NS_ASSUME_NONNULL_BEGIN NSString *recipientId = self.tsAccountManager.localNumber; [[self.backup checkCloudKitAccess] .then(^{ - dispatch_async(dispatch_get_main_queue(), ^{ - [OWSBackupAPI saveTestFileToCloudWithRecipientId:recipientId - fileUrl:[NSURL fileURLWithPath:filePath] - success:^(NSString *recordName) { - // Do nothing, the API method will log for us. - } - failure:^(NSError *error){ - // Do nothing, the API method will log for us. - }]; - }); + [OWSBackupAPI saveTestFileToCloudWithRecipientId:recipientId + fileUrl:[NSURL fileURLWithPath:filePath] + success:^(NSString *recordName) { + // Do nothing, the API method will log for us. + } + failure:^(NSError *error){ + // Do nothing, the API method will log for us. + }]; }) .catch(^(NSError *error){ // Do nothing, the API method will log for us. diff --git a/Signal/src/util/Backup/OWSBackup.m b/Signal/src/util/Backup/OWSBackup.m index b997dd174..25001fa9b 100644 --- a/Signal/src/util/Backup/OWSBackup.m +++ b/Signal/src/util/Backup/OWSBackup.m @@ -474,7 +474,7 @@ NSArray *MiscCollectionsToBackup(void) } [[OWSBackupAPI checkCloudKitAccessObjc] - .then(^{ + .thenInBackground(^{ [OWSBackupAPI checkForManifestInCloudWithRecipientId:recipientId success:^(BOOL value) { dispatch_async(dispatch_get_main_queue(), ^{ @@ -488,9 +488,7 @@ NSArray *MiscCollectionsToBackup(void) }]; }) .catch(^(NSError *error) { - dispatch_async(dispatch_get_main_queue(), ^{ - failure(error); - }); + failure(error); }) retainUntilComplete]; } diff --git a/Signal/src/util/Backup/OWSBackupExportJob.m b/Signal/src/util/Backup/OWSBackupExportJob.m index 11540d20e..61313a17c 100644 --- a/Signal/src/util/Backup/OWSBackupExportJob.m +++ b/Signal/src/util/Backup/OWSBackupExportJob.m @@ -349,17 +349,13 @@ NS_ASSUME_NONNULL_BEGIN __weak OWSBackupExportJob *weakSelf = self; [[self.backup checkCloudKitAccess] - .then(^{ - dispatch_async(dispatch_get_main_queue(), ^{ - [weakSelf start]; - }); + .thenInBackground(^{ + [weakSelf start]; }) .catch(^(NSError *error) { - dispatch_async(dispatch_get_main_queue(), ^{ - [weakSelf failWithErrorDescription: - NSLocalizedString(@"BACKUP_EXPORT_ERROR_COULD_NOT_EXPORT", - @"Error indicating the backup export could not export the user's data.")]; - }); + [weakSelf failWithErrorDescription: + NSLocalizedString(@"BACKUP_EXPORT_ERROR_COULD_NOT_EXPORT", + @"Error indicating the backup export could not export the user's data.")]; }) retainUntilComplete]; } diff --git a/Signal/src/util/Backup/OWSBackupImportJob.m b/Signal/src/util/Backup/OWSBackupImportJob.m index 3ceeb578b..7343cbac0 100644 --- a/Signal/src/util/Backup/OWSBackupImportJob.m +++ b/Signal/src/util/Backup/OWSBackupImportJob.m @@ -78,17 +78,13 @@ NSString *const kOWSBackup_ImportDatabaseKeySpec = @"kOWSBackup_ImportDatabaseKe __weak OWSBackupImportJob *weakSelf = self; [[self.backup checkCloudKitAccess] - .then(^{ - dispatch_async(dispatch_get_main_queue(), ^{ - [weakSelf start]; - }); + .thenInBackground(^{ + [weakSelf start]; }) .catch(^(NSError *error) { - dispatch_async(dispatch_get_main_queue(), ^{ - [weakSelf failWithErrorDescription: - NSLocalizedString(@"BACKUP_IMPORT_ERROR_COULD_NOT_IMPORT", - @"Error indicating the backup import could not import the user's data.")]; - }); + [weakSelf failWithErrorDescription: + NSLocalizedString(@"BACKUP_IMPORT_ERROR_COULD_NOT_IMPORT", + @"Error indicating the backup import could not import the user's data.")]; }) retainUntilComplete]; }