session-ios/Session/Backups/OWSBackup.h

106 lines
3.3 KiB
C
Raw Normal View History

2018-01-04 21:16:24 +01:00
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
NS_ASSUME_NONNULL_BEGIN
extern NSString *const NSNotificationNameBackupStateDidChange;
2018-01-05 20:42:50 +01:00
2018-03-08 15:52:57 +01:00
typedef void (^OWSBackupBoolBlock)(BOOL value);
typedef void (^OWSBackupStringListBlock)(NSArray<NSString *> *value);
2018-03-08 14:59:34 +01:00
typedef void (^OWSBackupErrorBlock)(NSError *error);
2018-01-05 20:42:50 +01:00
typedef NS_ENUM(NSUInteger, OWSBackupState) {
2018-03-06 21:00:28 +01:00
// Has never backed up, not trying to backup yet.
OWSBackupState_Idle = 0,
// Backing up.
2018-01-05 20:42:50 +01:00
OWSBackupState_InProgress,
2018-03-06 21:00:28 +01:00
// Last backup failed.
OWSBackupState_Failed,
2018-03-06 21:00:28 +01:00
// Last backup succeeded.
OWSBackupState_Succeeded,
2018-01-05 20:42:50 +01:00
};
2018-11-19 23:35:35 +01:00
NSString *NSStringForBackupExportState(OWSBackupState state);
NSString *NSStringForBackupImportState(OWSBackupState state);
2018-11-28 15:32:12 +01:00
NSArray<NSString *> *MiscCollectionsToBackup(void);
2018-11-27 20:01:25 +01:00
NSError *OWSBackupErrorWithDescription(NSString *description);
2018-11-27 17:33:31 +01:00
@class AnyPromise;
2018-03-20 22:22:19 +01:00
@class OWSBackupIO;
@class TSAttachmentPointer;
2018-01-05 20:42:50 +01:00
@class TSThread;
2018-11-30 18:05:18 +01:00
@class YapDatabaseConnection;
2018-01-05 20:42:50 +01:00
2018-01-04 21:16:24 +01:00
@interface OWSBackup : NSObject
2018-11-21 18:25:24 +01:00
- (instancetype)init NS_DESIGNATED_INITIALIZER;
2018-03-20 22:22:19 +01:00
+ (instancetype)sharedManager NS_SWIFT_NAME(shared());
2018-01-04 21:16:24 +01:00
2018-03-08 15:52:57 +01:00
#pragma mark - Backup Export
@property (atomic, readonly) OWSBackupState backupExportState;
2018-03-13 16:18:41 +01:00
2018-03-08 15:52:57 +01:00
// If a "backup export" is in progress (see backupExportState),
// backupExportDescription _might_ contain a string that describes
// the current phase and backupExportProgress _might_ contain a
// 0.0<=x<=1.0 progress value that indicates progress within the
// current phase.
@property (nonatomic, readonly, nullable) NSString *backupExportDescription;
@property (nonatomic, readonly, nullable) NSNumber *backupExportProgress;
2018-12-03 14:46:58 +01:00
+ (BOOL)isFeatureEnabled;
- (BOOL)isBackupEnabled;
- (void)setIsBackupEnabled:(BOOL)value;
2018-11-21 20:05:15 +01:00
- (BOOL)hasPendingRestoreDecision;
- (void)setHasPendingRestoreDecision:(BOOL)value;
2018-03-13 16:18:41 +01:00
- (void)tryToExportBackup;
- (void)cancelExportBackup;
2018-03-08 15:52:57 +01:00
#pragma mark - Backup Import
@property (atomic, readonly) OWSBackupState backupImportState;
2018-03-13 16:18:41 +01:00
2018-03-08 15:52:57 +01:00
// If a "backup import" is in progress (see backupImportState),
// backupImportDescription _might_ contain a string that describes
// the current phase and backupImportProgress _might_ contain a
// 0.0<=x<=1.0 progress value that indicates progress within the
// current phase.
@property (nonatomic, readonly, nullable) NSString *backupImportDescription;
@property (nonatomic, readonly, nullable) NSNumber *backupImportProgress;
- (void)allRecipientIdsWithManifestsInCloud:(OWSBackupStringListBlock)success failure:(OWSBackupErrorBlock)failure;
- (AnyPromise *)ensureCloudKitAccess __attribute__((warn_unused_result));
2018-11-27 17:33:31 +01:00
2018-03-08 15:52:57 +01:00
- (void)checkCanImportBackup:(OWSBackupBoolBlock)success failure:(OWSBackupErrorBlock)failure;
// TODO: After a successful import, we should enable backup and
// preserve our PIN and/or private key so that restored users
// continues to backup.
- (void)tryToImportBackup;
2018-03-08 16:10:43 +01:00
- (void)cancelImportBackup;
2018-03-06 16:10:22 +01:00
2018-03-12 20:10:37 +01:00
- (void)logBackupRecords;
2018-03-17 21:29:57 +01:00
- (void)clearAllCloudKitRecords;
2018-03-12 20:10:37 +01:00
2018-11-30 18:05:18 +01:00
- (void)logBackupMetadataCache:(YapDatabaseConnection *)dbConnection;
2018-03-20 22:22:19 +01:00
#pragma mark - Lazy Restore
- (NSArray<NSString *> *)attachmentRecordNamesForLazyRestore;
2018-03-20 22:22:19 +01:00
- (NSArray<NSString *> *)attachmentIdsForLazyRestore;
- (AnyPromise *)lazyRestoreAttachment:(TSAttachmentPointer *)attachment backupIO:(OWSBackupIO *)backupIO __attribute__((warn_unused_result));
2018-03-20 22:22:19 +01:00
2018-01-04 21:16:24 +01:00
@end
NS_ASSUME_NONNULL_END