2 * Copyright (c) 2016 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
27 #import <Foundation/Foundation.h>
30 #import "keychain/ckks/CloudKitDependencies.h"
31 #import "keychain/ckks/CKKSCKAccountStateTracker.h"
35 @interface CKKSZone
: NSObject
<CKKSZoneUpdateReceiver
, CKKSAccountStateListener
> {
36 CKContainer
* _container
;
37 CKDatabase
* _database
;
41 @interface CKKSZone
: NSObject
{
45 @
property (readonly
) NSString
* zoneName
;
47 @property
bool setupStarted
;
48 @property
bool setupComplete
;
49 @property CKKSGroupOperation
* zoneSetupOperation
;
51 @property
bool zoneCreated
;
52 @property
bool zoneSubscribed
;
53 @property NSError
* zoneCreatedError
;
54 @property NSError
* zoneSubscribedError
;
57 @property CKKSAccountStatus accountStatus
;
59 @
property (readonly
) CKContainer
* container
;
60 @
property (readonly
) CKDatabase
* database
;
62 @
property (weak
) CKKSCKAccountStateTracker
* accountTracker
;
64 @
property (readonly
) CKRecordZone
* zone
;
65 @
property (readonly
) CKRecordZoneID
* zoneID
;
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
;
73 @property dispatch_queue_t queue
;
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
;
84 - (NSOperation
*) createSetupOperation
: (bool) zoneCreated zoneSubscribed
: (bool) zoneSubscribed
;
86 - (CKKSResultOperation
*) beginResetCloudKitZoneOperation
;
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
;
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
;
98 // Cancels all operations (no matter what they are).
99 - (void)cancelAllOperations
;
101 // Schedules this operation for execution (if the CloudKit account exists)
102 - (bool)scheduleOperation
: (NSOperation
*) op
;
104 // Use this to schedule an operation handling account status (cleaning up after logout, etc.).
105 - (bool)scheduleAccountStatusOperation
: (NSOperation
*) op
;
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
;
111 // Use this for testing.
112 - (void)waitUntilAllOperationsAreFinished
;
114 // Use this for testing, to only wait for a certain type of operation to finish.
115 - (void)waitForOperationsOfClass
:(Class
) operationClass
;
117 // If this object wants to do anything that needs synchronization, use this.
118 - (void) dispatchSync
: (bool (^)(void)) block
;
120 // Call this to reset this object's setup, so you can call createSetupOperation again.
126 #endif /* CKKSZone_h */