diff options
author | zxu <zxu@google.com> | 2018-02-15 17:23:08 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-15 17:23:08 -0500 |
commit | fd9fd271d0dba3935a6f5611a1554f2c59b696af (patch) | |
tree | be6d8355254891cb83201c7bfac2082c0f95978f /Firestore/Source/Core | |
parent | 6889850b251ab56186bc13765baee0c3d0f1ae61 (diff) |
replacing Auth/FSTUser by C++ auth implementation (#804)
* replacing Auth/FSTUser by C++ auth implementation
* address changes
Diffstat (limited to 'Firestore/Source/Core')
-rw-r--r-- | Firestore/Source/Core/FSTFirestoreClient.mm | 16 | ||||
-rw-r--r-- | Firestore/Source/Core/FSTSyncEngine.h | 8 | ||||
-rw-r--r-- | Firestore/Source/Core/FSTSyncEngine.mm | 32 |
3 files changed, 32 insertions, 24 deletions
diff --git a/Firestore/Source/Core/FSTFirestoreClient.mm b/Firestore/Source/Core/FSTFirestoreClient.mm index 1961460..823f488 100644 --- a/Firestore/Source/Core/FSTFirestoreClient.mm +++ b/Firestore/Source/Core/FSTFirestoreClient.mm @@ -38,6 +38,8 @@ #include "Firestore/core/src/firebase/firestore/model/database_id.h" #include "Firestore/core/src/firebase/firestore/util/string_apple.h" +namespace util = firebase::firestore::util; +using firebase::firestore::auth::User; using firebase::firestore::core::DatabaseInfo; using firebase::firestore::model::DatabaseId; @@ -98,13 +100,15 @@ NS_ASSUME_NONNULL_BEGIN _workerDispatchQueue = workerDispatchQueue; dispatch_semaphore_t initialUserAvailable = dispatch_semaphore_create(0); - __block FSTUser *initialUser; + __block bool initialized = false; + __block User initialUser; FSTWeakify(self); - _credentialsProvider.userChangeListener = ^(FSTUser *user) { + _credentialsProvider.userChangeListener = ^(const User &user) { FSTStrongify(self); if (self) { - if (!initialUser) { + if (!initialized) { initialUser = user; + initialized = true; dispatch_semaphore_signal(initialUserAvailable); } else { [workerDispatchQueue dispatchAsync:^{ @@ -126,7 +130,7 @@ NS_ASSUME_NONNULL_BEGIN return self; } -- (void)initializeWithUser:(FSTUser *)user usePersistence:(BOOL)usePersistence { +- (void)initializeWithUser:(const User &)user usePersistence:(BOOL)usePersistence { // Do all of our initialization on our own dispatch queue. [self.workerDispatchQueue verifyIsCurrentQueue]; @@ -189,10 +193,10 @@ NS_ASSUME_NONNULL_BEGIN [_remoteStore start]; } -- (void)userDidChange:(FSTUser *)user { +- (void)userDidChange:(const User &)user { [self.workerDispatchQueue verifyIsCurrentQueue]; - FSTLog(@"User Changed: %@", user); + FSTLog(@"User Changed: %@", util::WrapNSStringNoCopy(user.uid())); [self.syncEngine userDidChange:user]; } diff --git a/Firestore/Source/Core/FSTSyncEngine.h b/Firestore/Source/Core/FSTSyncEngine.h index 7060155..3b28e36 100644 --- a/Firestore/Source/Core/FSTSyncEngine.h +++ b/Firestore/Source/Core/FSTSyncEngine.h @@ -19,13 +19,14 @@ #import "Firestore/Source/Core/FSTTypes.h" #import "Firestore/Source/Remote/FSTRemoteStore.h" +#include "Firestore/core/src/firebase/firestore/auth/user.h" + @class FSTDispatchQueue; @class FSTLocalStore; @class FSTMutation; @class FSTQuery; @class FSTRemoteEvent; @class FSTRemoteStore; -@class FSTUser; @class FSTViewSnapshot; NS_ASSUME_NONNULL_BEGIN @@ -57,7 +58,8 @@ NS_ASSUME_NONNULL_BEGIN - (instancetype)init NS_UNAVAILABLE; - (instancetype)initWithLocalStore:(FSTLocalStore *)localStore remoteStore:(FSTRemoteStore *)remoteStore - initialUser:(FSTUser *)user NS_DESIGNATED_INITIALIZER; + initialUser:(const firebase::firestore::auth::User &)user + NS_DESIGNATED_INITIALIZER; /** * A delegate to be notified when queries being listened to produce new view snapshots or @@ -98,7 +100,7 @@ NS_ASSUME_NONNULL_BEGIN updateBlock:(FSTTransactionBlock)updateBlock completion:(FSTVoidIDErrorBlock)completion; -- (void)userDidChange:(FSTUser *)user; +- (void)userDidChange:(const firebase::firestore::auth::User &)user; /** Applies an FSTOnlineState change to the sync engine and notifies any views of the change. */ - (void)applyChangedOnlineState:(FSTOnlineState)onlineState; diff --git a/Firestore/Source/Core/FSTSyncEngine.mm b/Firestore/Source/Core/FSTSyncEngine.mm index d6ee956..61fac7d 100644 --- a/Firestore/Source/Core/FSTSyncEngine.mm +++ b/Firestore/Source/Core/FSTSyncEngine.mm @@ -16,10 +16,11 @@ #import "Firestore/Source/Core/FSTSyncEngine.h" +#include <unordered_map> + #import <GRPCClient/GRPCCall.h> #import "FIRFirestoreErrors.h" -#import "Firestore/Source/Auth/FSTUser.h" #import "Firestore/Source/Core/FSTQuery.h" #import "Firestore/Source/Core/FSTSnapshotVersion.h" #import "Firestore/Source/Core/FSTTransaction.h" @@ -40,8 +41,11 @@ #import "Firestore/Source/Util/FSTDispatchQueue.h" #import "Firestore/Source/Util/FSTLogger.h" +#include "Firestore/core/src/firebase/firestore/auth/user.h" #include "Firestore/core/src/firebase/firestore/core/target_id_generator.h" +using firebase::firestore::auth::HashUser; +using firebase::firestore::auth::User; using firebase::firestore::core::TargetIdGenerator; NS_ASSUME_NONNULL_BEGIN @@ -139,23 +143,22 @@ static const FSTListenSequenceNumber kIrrelevantSequenceNumber = -1; /** The garbage collector used to collect documents that are no longer in limbo. */ @property(nonatomic, strong, readonly) FSTEagerGarbageCollector *limboCollector; -/** Stores user completion blocks, indexed by user and FSTBatchID. */ -@property(nonatomic, strong) - NSMutableDictionary<FSTUser *, NSMutableDictionary<NSNumber *, FSTVoidErrorBlock> *> - *mutationCompletionBlocks; - -@property(nonatomic, strong) FSTUser *currentUser; - @end @implementation FSTSyncEngine { /** Used for creating the FSTTargetIDs for the listens used to resolve limbo documents. */ TargetIdGenerator _targetIdGenerator; + + /** Stores user completion blocks, indexed by user and FSTBatchID. */ + std::unordered_map<User, NSMutableDictionary<NSNumber *, FSTVoidErrorBlock> *, HashUser> + _mutationCompletionBlocks; + + User _currentUser; } - (instancetype)initWithLocalStore:(FSTLocalStore *)localStore remoteStore:(FSTRemoteStore *)remoteStore - initialUser:(FSTUser *)initialUser { + initialUser:(const User &)initialUser { if (self = [super init]) { _localStore = localStore; _remoteStore = remoteStore; @@ -169,7 +172,6 @@ static const FSTListenSequenceNumber kIrrelevantSequenceNumber = -1; _limboDocumentRefs = [[FSTReferenceSet alloc] init]; [_limboCollector addGarbageSource:_limboDocumentRefs]; - _mutationCompletionBlocks = [NSMutableDictionary dictionary]; _targetIdGenerator = TargetIdGenerator::SyncEngineTargetIdGenerator(0); _currentUser = initialUser; } @@ -227,10 +229,10 @@ static const FSTListenSequenceNumber kIrrelevantSequenceNumber = -1; - (void)addMutationCompletionBlock:(FSTVoidErrorBlock)completion batchID:(FSTBatchID)batchID { NSMutableDictionary<NSNumber *, FSTVoidErrorBlock> *completionBlocks = - self.mutationCompletionBlocks[self.currentUser]; + _mutationCompletionBlocks[_currentUser]; if (!completionBlocks) { completionBlocks = [NSMutableDictionary dictionary]; - self.mutationCompletionBlocks[self.currentUser] = completionBlocks; + _mutationCompletionBlocks[_currentUser] = completionBlocks; } [completionBlocks setObject:completion forKey:@(batchID)]; } @@ -400,7 +402,7 @@ static const FSTListenSequenceNumber kIrrelevantSequenceNumber = -1; - (void)processUserCallbacksForBatchID:(FSTBatchID)batchID error:(NSError *_Nullable)error { NSMutableDictionary<NSNumber *, FSTVoidErrorBlock> *completionBlocks = - self.mutationCompletionBlocks[self.currentUser]; + _mutationCompletionBlocks[_currentUser]; // NOTE: Mutations restored from persistence won't have completion blocks, so it's okay for // this (or the completion below) to be nil. @@ -527,8 +529,8 @@ static const FSTListenSequenceNumber kIrrelevantSequenceNumber = -1; return [self.limboTargetsByKey copy]; } -- (void)userDidChange:(FSTUser *)user { - self.currentUser = user; +- (void)userDidChange:(const User &)user { + _currentUser = user; // Notify local store and emit any resulting events from swapping out the mutation queue. FSTMaybeDocumentDictionary *changes = [self.localStore userDidChange:user]; |