]> git.saurik.com Git - apple/security.git/blob - keychain/ckks/CKKSFetchAllRecordZoneChangesOperation.h
Security-59306.41.2.tar.gz
[apple/security.git] / keychain / ckks / CKKSFetchAllRecordZoneChangesOperation.h
1 /*
2 * Copyright (c) 2016 Apple Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 #import <Foundation/Foundation.h>
25
26 #if OCTAGON
27 @class CKKSKeychainView;
28 #import "keychain/ckks/CKKSGroupOperation.h"
29 #import "keychain/ckks/CloudKitDependencies.h"
30
31 NS_ASSUME_NONNULL_BEGIN
32
33 /* Fetch Reasons */
34 @protocol CKKSFetchBecauseProtocol <NSObject>
35 @end
36 typedef NSString<CKKSFetchBecauseProtocol> CKKSFetchBecause;
37 extern CKKSFetchBecause* const CKKSFetchBecauseAPNS;
38 extern CKKSFetchBecause* const CKKSFetchBecauseAPIFetchRequest;
39 extern CKKSFetchBecause* const CKKSFetchBecauseCurrentItemFetchRequest;
40 extern CKKSFetchBecause* const CKKSFetchBecauseInitialStart;
41 extern CKKSFetchBecause* const CKKSFetchBecauseSecuritydRestart;
42 extern CKKSFetchBecause* const CKKSFetchBecausePreviousFetchFailed;
43 extern CKKSFetchBecause* const CKKSFetchBecauseKeyHierarchy;
44 extern CKKSFetchBecause* const CKKSFetchBecauseTesting;
45 extern CKKSFetchBecause* const CKKSFetchBecauseResync;
46
47 /* Clients that register to use fetches */
48 @interface CKKSCloudKitFetchRequest : NSObject
49 @property bool participateInFetch;
50
51 // If true, you will receive YES in the resync parameter to your callback.
52 // You may also receive YES to your callback if a resync has been triggered for you.
53 // It does nothing else. Use as you see fit.
54 // Note: you will receive exactly one callback with moreComing=0 and resync=1 for each
55 // resync fetch. You may then receive further callbacks with resync=0 during the same fetch,
56 // if other clients keep needing fetches.
57 @property BOOL resync;
58
59 @property (nullable) CKServerChangeToken* changeToken;
60 @end
61
62 @class CKKSCloudKitDeletion;
63 @protocol CKKSChangeFetcherClient <NSObject>
64 - (CKRecordZoneID*)zoneID;
65 - (CKKSCloudKitFetchRequest*)participateInFetch;
66
67 // Return false if this is a 'fatal' error and you don't want another fetch to be tried
68 - (bool)shouldRetryAfterFetchError:(NSError*)error;
69
70 - (void)changesFetched:(NSArray<CKRecord*>*)changedRecords
71 deletedRecordIDs:(NSArray<CKKSCloudKitDeletion*>*)deleted
72 newChangeToken:(CKServerChangeToken*)changeToken
73 moreComing:(BOOL)moreComing
74 resync:(BOOL)resync;
75 @end
76
77 // I don't understand why recordType isn't part of record ID, but deletions come in as both things
78 @interface CKKSCloudKitDeletion : NSObject
79 @property CKRecordID* recordID;
80 @property NSString* recordType;
81 - (instancetype)initWithRecordID:(CKRecordID*)recordID recordType:(NSString*)recordType;
82 @end
83
84
85 @interface CKKSFetchAllRecordZoneChangesOperation : CKKSGroupOperation
86 @property (readonly) Class<CKKSFetchRecordZoneChangesOperation> fetchRecordZoneChangesOperationClass;
87 @property (readonly) CKContainer* container;
88
89 // Set this to true before starting this operation if you'd like resync behavior:
90 // Fetching everything currently in CloudKit and comparing to local copy
91 @property bool resync;
92
93 @property (nullable) NSMutableArray<CKRecordZoneID*>* fetchedZoneIDs;
94
95 @property NSSet<CKKSFetchBecause*>* fetchReasons;
96 @property NSSet<CKRecordZoneNotification*>* apnsPushes;
97
98 @property NSMutableDictionary<CKRecordID*, CKRecord*>* modifications;
99 @property NSMutableDictionary<CKRecordID*, CKKSCloudKitDeletion*>* deletions;
100 @property NSMutableDictionary<CKRecordZoneID*, CKServerChangeToken*>* changeTokens;
101
102 - (instancetype)init NS_UNAVAILABLE;
103 - (instancetype)initWithContainer:(CKContainer*)container
104 fetchClass:(Class<CKKSFetchRecordZoneChangesOperation>)fetchRecordZoneChangesOperationClass
105 clients:(NSArray<id<CKKSChangeFetcherClient>>*)clients
106 fetchReasons:(NSSet<CKKSFetchBecause*>*)fetchReasons
107 apnsPushes:(NSSet<CKRecordZoneNotification*>* _Nullable)apnsPushes
108 forceResync:(bool)forceResync
109 ckoperationGroup:(CKOperationGroup*)ckoperationGroup;
110
111 @end
112
113 NS_ASSUME_NONNULL_END
114
115 #endif