]> git.saurik.com Git - apple/security.git/blob - keychain/ckks/CKKSZone.h
9db60dd55bf803c2ee4b95d6eac6b58d6a7508c0
[apple/security.git] / keychain / ckks / CKKSZone.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 #ifndef CKKSZone_h
25 #define CKKSZone_h
26
27 #import <Foundation/Foundation.h>
28
29 #if OCTAGON
30 #import "keychain/ckks/CloudKitDependencies.h"
31 #import "keychain/ckks/CKKSCKAccountStateTracker.h"
32 #endif
33
34 #if OCTAGON
35 @interface CKKSZone : NSObject<CKKSZoneUpdateReceiver, CKKSAccountStateListener> {
36 CKContainer* _container;
37 CKDatabase* _database;
38 CKRecordZone* _zone;
39 }
40 #else
41 @interface CKKSZone : NSObject {
42 }
43 #endif
44
45 @property (readonly) NSString* zoneName;
46
47 @property bool setupStarted;
48 @property bool setupComplete;
49 @property CKKSGroupOperation* zoneSetupOperation;
50
51 @property bool zoneCreated;
52 @property bool zoneSubscribed;
53 @property NSError* zoneCreatedError;
54 @property NSError* zoneSubscribedError;
55
56 #if OCTAGON
57 @property CKKSAccountStatus accountStatus;
58
59 @property (readonly) CKContainer* container;
60 @property (readonly) CKDatabase* database;
61
62 @property (weak) CKKSCKAccountStateTracker* accountTracker;
63
64 @property (readonly) CKRecordZone* zone;
65 @property (readonly) CKRecordZoneID* zoneID;
66
67 // Dependencies (for injection)
68 @property (readonly) Class<CKKSFetchRecordZoneChangesOperation> fetchRecordZoneChangesOperationClass;
69 @property (readonly) Class<CKKSModifySubscriptionsOperation> modifySubscriptionsOperationClass;
70 @property (readonly) Class<CKKSModifyRecordZonesOperation> modifyRecordZonesOperationClass;
71 @property (readonly) Class<CKKSAPSConnection> apsConnectionClass;
72
73 @property dispatch_queue_t queue;
74
75 - (instancetype)initWithContainer: (CKContainer*) container
76 zoneName: (NSString*) zoneName
77 accountTracker:(CKKSCKAccountStateTracker*) tracker
78 fetchRecordZoneChangesOperationClass: (Class<CKKSFetchRecordZoneChangesOperation>) fetchRecordZoneChangesOperationClass
79 modifySubscriptionsOperationClass: (Class<CKKSModifySubscriptionsOperation>) modifySubscriptionsOperationClass
80 modifyRecordZonesOperationClass: (Class<CKKSModifyRecordZonesOperation>) modifyRecordZonesOperationClass
81 apsConnectionClass: (Class<CKKSAPSConnection>) apsConnectionClass;
82
83
84 - (NSOperation*) createSetupOperation: (bool) zoneCreated zoneSubscribed: (bool) zoneSubscribed;
85
86 - (CKKSResultOperation*) beginResetCloudKitZoneOperation;
87
88 // Called when CloudKit notifies us that we just logged in.
89 // That is, if we transition from any state to CKAccountStatusAvailable.
90 // This will be called under the protection of dispatchSync
91 - (void)handleCKLogin;
92
93 // Called when CloudKit notifies us that we just logged out.
94 // i.e. we transition from CKAccountStatusAvailable to any other state.
95 // This will be called under the protection of dispatchSync
96 - (void)handleCKLogout;
97
98 // Cancels all operations (no matter what they are).
99 - (void)cancelAllOperations;
100
101 // Schedules this operation for execution (if the CloudKit account exists)
102 - (bool)scheduleOperation: (NSOperation*) op;
103
104 // Use this to schedule an operation handling account status (cleaning up after logout, etc.).
105 - (bool)scheduleAccountStatusOperation: (NSOperation*) op;
106
107 // Schedules this operation for execution, and doesn't do any dependency magic
108 // This should _only_ be used if you want to run something even if the CloudKit account is logged out
109 - (bool)scheduleOperationWithoutDependencies:(NSOperation*)op;
110
111 // Use this for testing.
112 - (void)waitUntilAllOperationsAreFinished;
113
114 // Use this for testing, to only wait for a certain type of operation to finish.
115 - (void)waitForOperationsOfClass:(Class) operationClass;
116
117 // If this object wants to do anything that needs synchronization, use this.
118 - (void) dispatchSync: (bool (^)(void)) block;
119
120 // Call this to reset this object's setup, so you can call createSetupOperation again.
121 - (void)resetSetup;
122
123 #endif
124 @end
125
126 #endif /* CKKSZone_h */