]> git.saurik.com Git - apple/security.git/blame - keychain/ckks/CKKSZone.h
Security-59306.41.2.tar.gz
[apple/security.git] / keychain / ckks / CKKSZone.h
CommitLineData
866f8763
A
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
866f8763
A
24#import <Foundation/Foundation.h>
25
26#if OCTAGON
b54c578e 27#import "keychain/ckks/CKKSAccountStateTracker.h"
ecaf5866 28#import "keychain/ckks/CKKSReachabilityTracker.h"
3f0f0d49 29#import "keychain/ckks/CloudKitDependencies.h"
b54c578e
A
30#import "keychain/ckks/CKKSCloudKitClassDependencies.h"
31#import "keychain/ckks/OctagonAPSReceiver.h"
ecaf5866 32#import "keychain/ckks/CKKSGroupOperation.h"
b54c578e
A
33#import "keychain/ckks/CKKSNearFutureScheduler.h"
34#import "keychain/ckks/CKKSZoneModifier.h"
866f8763 35
3f0f0d49
A
36NS_ASSUME_NONNULL_BEGIN
37
b54c578e 38@interface CKKSZone : NSObject <CKKSZoneUpdateReceiver, CKKSCloudKitAccountStateListener>
3f0f0d49 39{
866f8763
A
40 CKContainer* _container;
41 CKDatabase* _database;
42 CKRecordZone* _zone;
43}
866f8763
A
44
45@property (readonly) NSString* zoneName;
46
866f8763 47@property CKKSGroupOperation* zoneSetupOperation;
ecaf5866 48@property (nullable) CKOperationGroup* zoneSetupOperationGroup; // set this if you want zone creates to use a different operation group
866f8763
A
49
50@property bool zoneCreated;
51@property bool zoneSubscribed;
3f0f0d49
A
52@property (nullable) NSError* zoneCreatedError;
53@property (nullable) NSError* zoneSubscribedError;
54
55// True if this zone object has been halted. Halted zones will never recover.
56@property (readonly) bool halted;
866f8763 57
866f8763
A
58@property CKKSAccountStatus accountStatus;
59
60@property (readonly) CKContainer* container;
61@property (readonly) CKDatabase* database;
62
b54c578e 63@property (weak) CKKSAccountStateTracker* accountTracker;
ecaf5866 64@property (weak) CKKSReachabilityTracker* reachabilityTracker;
866f8763
A
65
66@property (readonly) CKRecordZone* zone;
67@property (readonly) CKRecordZoneID* zoneID;
68
b54c578e
A
69@property (readonly) CKKSZoneModifier* zoneModifier;
70
866f8763 71// Dependencies (for injection)
b54c578e 72@property (readonly) CKKSCloudKitClassDependencies* cloudKitClassDependencies;
866f8763
A
73
74@property dispatch_queue_t queue;
75
3f0f0d49 76- (instancetype)initWithContainer:(CKContainer*)container
b54c578e
A
77 zoneName:(NSString*)zoneName
78 accountTracker:(CKKSAccountStateTracker*)accountTracker
79 reachabilityTracker:(CKKSReachabilityTracker*)reachabilityTracker
80 zoneModifier:(CKKSZoneModifier*)zoneModifier
81 cloudKitClassDependencies:(CKKSCloudKitClassDependencies*)cloudKitClassDependencies;
866f8763 82
866f8763 83
ecaf5866 84- (CKKSResultOperation* _Nullable)deleteCloudKitZoneOperation:(CKOperationGroup* _Nullable)ckoperationGroup;
866f8763
A
85
86// Called when CloudKit notifies us that we just logged in.
87// That is, if we transition from any state to CKAccountStatusAvailable.
3f0f0d49
A
88// This will be called under the protection of dispatchSync.
89// This is a no-op; you should intercept this call and call handleCKLogin:zoneSubscribed:
90// with the appropriate state
866f8763
A
91- (void)handleCKLogin;
92
3f0f0d49
A
93// Actually start a cloudkit login. Pass in whether you believe this zone has been created and if this device has
94// subscribed to this zone on the server.
ecaf5866 95- (CKKSResultOperation* _Nullable)handleCKLogin:(bool)zoneCreated zoneSubscribed:(bool)zoneSubscribed;
3f0f0d49 96
866f8763
A
97// Called when CloudKit notifies us that we just logged out.
98// i.e. we transition from CKAccountStatusAvailable to any other state.
99// This will be called under the protection of dispatchSync
100- (void)handleCKLogout;
101
3f0f0d49
A
102// Call this when you're ready for this zone to kick off operations
103// based on iCloud account status
b54c578e 104- (void)beginCloudKitOperation;
3f0f0d49 105
866f8763
A
106// Cancels all operations (no matter what they are).
107- (void)cancelAllOperations;
108
109// Schedules this operation for execution (if the CloudKit account exists)
3f0f0d49 110- (bool)scheduleOperation:(NSOperation*)op;
866f8763
A
111
112// Use this to schedule an operation handling account status (cleaning up after logout, etc.).
3f0f0d49 113- (bool)scheduleAccountStatusOperation:(NSOperation*)op;
866f8763
A
114
115// Schedules this operation for execution, and doesn't do any dependency magic
116// This should _only_ be used if you want to run something even if the CloudKit account is logged out
117- (bool)scheduleOperationWithoutDependencies:(NSOperation*)op;
118
119// Use this for testing.
120- (void)waitUntilAllOperationsAreFinished;
121
122// Use this for testing, to only wait for a certain type of operation to finish.
3f0f0d49 123- (void)waitForOperationsOfClass:(Class)operationClass;
866f8763
A
124
125// If this object wants to do anything that needs synchronization, use this.
3f0f0d49
A
126// If this object has had -halt called, this block will never fire.
127- (void)dispatchSync:(bool (^)(void))block;
128
129// Call this to halt everything this zone is doing. This object will never recover. Use for testing.
130- (void)halt;
866f8763
A
131
132// Call this to reset this object's setup, so you can call createSetupOperation again.
133- (void)resetSetup;
134
866f8763
A
135@end
136
3f0f0d49
A
137NS_ASSUME_NONNULL_END
138#endif // OCTAGON