diff options
author | zxu123 <zxu@google.com> | 2017-12-04 09:18:27 -0500 |
---|---|---|
committer | zxu123 <zxu@google.com> | 2017-12-04 09:18:27 -0500 |
commit | ac8ada0000612f4bbc3e0329e40b0b6f7d0abcba (patch) | |
tree | 72e4ee985b7151178fcf5ad1a141bd047e106e36 /Firestore | |
parent | 64204886af165557792a0a51954ae2a00fa3a02f (diff) | |
parent | 9c08142051f522c6214337470b870919c30a6192 (diff) |
Merge branch 'master' into zxu/logoffline
fix pod error:
[!] CocoaPods could not find compatible versions for pod "FirebaseCor
Diffstat (limited to 'Firestore')
27 files changed, 123 insertions, 131 deletions
diff --git a/Firestore/CHANGELOG.md b/Firestore/CHANGELOG.md index f1cd832..0c5bcdc 100644 --- a/Firestore/CHANGELOG.md +++ b/Firestore/CHANGELOG.md @@ -3,6 +3,8 @@ - [fixed] Fixed a crash when using path names with international characters with persistence enabled. +- [fixed] Addressed race condition during the teardown of idle streams (#490). + # v0.9.3 - [changed] Improved performance loading documents matching a query. - [changed] Cleanly shut down idle write streams. diff --git a/Firestore/CMakeLists.txt b/Firestore/CMakeLists.txt index 119af5e..82e1903 100644 --- a/Firestore/CMakeLists.txt +++ b/Firestore/CMakeLists.txt @@ -14,8 +14,5 @@ include(${PROJECT_SOURCE_DIR}/cmake/external/googletest.cmake) -add_subdirectory(src/support) -add_subdirectory(test/support) - -add_subdirectory(src/core/util) -add_subdirectory(test/core/util) +add_subdirectory(core/src/firebase/firestore/util) +add_subdirectory(core/test/firebase/firestore/util) diff --git a/Firestore/Example/Firestore.xcodeproj/project.pbxproj b/Firestore/Example/Firestore.xcodeproj/project.pbxproj index ea9ae44..437b661 100644 --- a/Firestore/Example/Firestore.xcodeproj/project.pbxproj +++ b/Firestore/Example/Firestore.xcodeproj/project.pbxproj @@ -24,8 +24,8 @@ /* Begin PBXBuildFile section */ 3B843E4C1F3A182900548890 /* remote_store_spec_test.json in Resources */ = {isa = PBXBuildFile; fileRef = 3B843E4A1F3930A400548890 /* remote_store_spec_test.json */; }; - 5463926E1FBEDE28005031AA /* secure_random_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 5463926D1FBEDE28005031AA /* secure_random_test.cc */; }; - 5471DCF91FBF99AC00656CD3 /* autoid_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 5471DCF71FBF99A300656CD3 /* autoid_test.cc */; }; + 54740A571FC914BA00713A1A /* secure_random_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 54740A531FC913E500713A1A /* secure_random_test.cc */; }; + 54740A581FC914F000713A1A /* autoid_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 54740A521FC913E500713A1A /* autoid_test.cc */; }; 54764FAB1FAA0C320085E60A /* string_util_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 54764FAA1FAA0C320085E60A /* string_util_test.cc */; }; 54764FAF1FAA21B90085E60A /* FSTGoogleTestTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 54764FAE1FAA21B90085E60A /* FSTGoogleTestTests.mm */; }; 5491BC721FB44593008B3588 /* FSTIntegrationTestCase.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5491BC711FB44593008B3588 /* FSTIntegrationTestCase.mm */; }; @@ -185,8 +185,8 @@ 3B843E4A1F3930A400548890 /* remote_store_spec_test.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = remote_store_spec_test.json; sourceTree = "<group>"; }; 42491D7DC8C8CD245CC22B93 /* Pods-SwiftBuildTest.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SwiftBuildTest.debug.xcconfig"; path = "Pods/Target Support Files/Pods-SwiftBuildTest/Pods-SwiftBuildTest.debug.xcconfig"; sourceTree = "<group>"; }; 4EBC5F5ABE1FD097EFE5E224 /* Pods-Firestore_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Firestore_Example.release.xcconfig"; path = "Pods/Target Support Files/Pods-Firestore_Example/Pods-Firestore_Example.release.xcconfig"; sourceTree = "<group>"; }; - 5463926D1FBEDE28005031AA /* secure_random_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = secure_random_test.cc; path = ../../test/support/secure_random_test.cc; sourceTree = "<group>"; }; - 5471DCF71FBF99A300656CD3 /* autoid_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = autoid_test.cc; path = ../../test/core/util/autoid_test.cc; sourceTree = "<group>"; }; + 54740A521FC913E500713A1A /* autoid_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = autoid_test.cc; path = ../../core/test/firebase/firestore/util/autoid_test.cc; sourceTree = "<group>"; }; + 54740A531FC913E500713A1A /* secure_random_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = secure_random_test.cc; path = ../../core/test/firebase/firestore/util/secure_random_test.cc; sourceTree = "<group>"; }; 54764FAA1FAA0C320085E60A /* string_util_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = string_util_test.cc; path = ../../Port/string_util_test.cc; sourceTree = "<group>"; }; 54764FAE1FAA21B90085E60A /* FSTGoogleTestTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = FSTGoogleTestTests.mm; path = GoogleTest/FSTGoogleTestTests.mm; sourceTree = "<group>"; }; 5491BC711FB44593008B3588 /* FSTIntegrationTestCase.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FSTIntegrationTestCase.mm; sourceTree = "<group>"; }; @@ -368,26 +368,11 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ - 5463926F1FBEDE2F005031AA /* support */ = { + 54740A561FC913EB00713A1A /* util */ = { isa = PBXGroup; children = ( - 5463926D1FBEDE28005031AA /* secure_random_test.cc */, - ); - name = support; - sourceTree = "<group>"; - }; - 5471DCFA1FBF99B100656CD3 /* core */ = { - isa = PBXGroup; - children = ( - 5471DCFB1FBF99B800656CD3 /* util */, - ); - name = core; - sourceTree = "<group>"; - }; - 5471DCFB1FBF99B800656CD3 /* util */ = { - isa = PBXGroup; - children = ( - 5471DCF71FBF99A300656CD3 /* autoid_test.cc */, + 54740A521FC913E500713A1A /* autoid_test.cc */, + 54740A531FC913E500713A1A /* secure_random_test.cc */, ); name = util; sourceTree = "<group>"; @@ -395,9 +380,8 @@ 54764FAC1FAA0C390085E60A /* GoogleTests */ = { isa = PBXGroup; children = ( - 5471DCFA1FBF99B100656CD3 /* core */, 54764FAD1FAA0C650085E60A /* Port */, - 5463926F1FBEDE2F005031AA /* support */, + 54740A561FC913EB00713A1A /* util */, 54764FAE1FAA21B90085E60A /* FSTGoogleTestTests.mm */, ); name = GoogleTests; @@ -1186,7 +1170,6 @@ DE51B1F81F0D491F0013853F /* FSTWatchChange+Testing.m in Sources */, DE51B1EB1F0D490D0013853F /* FSTWriteGroupTests.mm in Sources */, DE51B2011F0D493E0013853F /* FSTHelpers.m in Sources */, - 5471DCF91FBF99AC00656CD3 /* autoid_test.cc in Sources */, DE51B1F61F0D491B0013853F /* FSTSerializerBetaTests.m in Sources */, DE51B1F01F0D49140013853F /* FSTFieldValueTests.m in Sources */, 5491BC721FB44593008B3588 /* FSTIntegrationTestCase.mm in Sources */, @@ -1195,6 +1178,7 @@ DE51B1EC1F0D49140013853F /* FSTDatabaseIDTests.m in Sources */, DE51B1ED1F0D49140013853F /* FSTDocumentKeyTests.m in Sources */, DE51B1D41F0D48CD0013853F /* FSTViewTests.m in Sources */, + 54740A581FC914F000713A1A /* autoid_test.cc in Sources */, DE51B1F41F0D491B0013853F /* FSTRemoteEventTests.m in Sources */, 54E928241F33953300C1953E /* FSTEventAccumulator.m in Sources */, DE51B1D11F0D48CD0013853F /* FSTTargetIDGeneratorTests.m in Sources */, @@ -1223,7 +1207,6 @@ DE51B1D91F0D490D0013853F /* FSTEagerGarbageCollectorTests.m in Sources */, DE51B1E21F0D490D0013853F /* FSTMutationQueueTests.m in Sources */, DE51B1E81F0D490D0013853F /* FSTLevelDBKeyTests.mm in Sources */, - 5463926E1FBEDE28005031AA /* secure_random_test.cc in Sources */, DE51B1E31F0D490D0013853F /* FSTPersistenceTestHelpers.m in Sources */, DE51B1CF1F0D48CD0013853F /* FSTQueryListenerTests.m in Sources */, DE51B1DA1F0D490D0013853F /* FSTLevelDBLocalStoreTests.m in Sources */, @@ -1234,6 +1217,7 @@ DE51B1E41F0D490D0013853F /* FSTQueryCacheTests.m in Sources */, DE51B1CD1F0D48CD0013853F /* FSTDatabaseInfoTests.m in Sources */, DE51B1F21F0D49140013853F /* FSTPathTests.m in Sources */, + 54740A571FC914BA00713A1A /* secure_random_test.cc in Sources */, DE51B1DD1F0D490D0013853F /* FSTLocalStoreTests.m in Sources */, D5B25474286C9800CE42B8C2 /* FSTTestDispatchQueue.m in Sources */, ); diff --git a/Firestore/Example/Podfile b/Firestore/Example/Podfile index 923ab22..89af74f 100644 --- a/Firestore/Example/Podfile +++ b/Firestore/Example/Podfile @@ -1,7 +1,7 @@ # The next line is the forcing function for the Firebase pod. The Firebase # version's subspecs should depend on the component versions in their # corresponding podspec's. -pod 'Firebase/Core', '4.6.0' +pod 'Firebase/Core', '4.7.0' use_frameworks! platform :ios, '8.0' diff --git a/Firestore/Example/Tests/Local/StringViewTests.mm b/Firestore/Example/Tests/Local/StringViewTests.mm index fd97c13..b30b43d 100644 --- a/Firestore/Example/Tests/Local/StringViewTests.mm +++ b/Firestore/Example/Tests/Local/StringViewTests.mm @@ -21,7 +21,7 @@ using Firestore::StringView; -#define ASSERT_NSSTRING_TO_STRINGVIEW_AND_BACK_OK( nsstr ) \ +#define ASSERT_NSSTRING_TO_STRINGVIEW_AND_BACK_OK(nsstr) \ StringView sv(nsstr); \ leveldb::Slice slice = sv; \ NSString *afterConversion = [[NSString alloc] initWithBytes:slice.data() \ diff --git a/Firestore/Example/Tests/Util/FSTIntegrationTestCase.mm b/Firestore/Example/Tests/Util/FSTIntegrationTestCase.mm index 2c29bf0..3d30a77 100644 --- a/Firestore/Example/Tests/Util/FSTIntegrationTestCase.mm +++ b/Firestore/Example/Tests/Util/FSTIntegrationTestCase.mm @@ -21,7 +21,7 @@ #import <GRPCClient/GRPCCall+ChannelArg.h> #import <GRPCClient/GRPCCall+Tests.h> -#include "Firestore/src/core/util/autoid.h" +#include "Firestore/core/src/firebase/firestore/util/autoid.h" #import "Firestore/Source/API/FIRFirestore+Internal.h" #import "Firestore/Source/Auth/FSTEmptyCredentialsProvider.h" @@ -32,6 +32,8 @@ #import "Firestore/Example/Tests/Util/FSTEventAccumulator.h" #import "Firestore/Example/Tests/Util/FSTTestDispatchQueue.h" +using firebase::firestore::util::CreateAutoId; + NS_ASSUME_NONNULL_BEGIN @interface FIRFirestore (Testing) @@ -165,7 +167,7 @@ NS_ASSUME_NONNULL_BEGIN } - (NSString *)documentPath { - std::string autoId = firestore::CreateAutoId(); + std::string autoId = CreateAutoId(); return [NSString stringWithFormat:@"test-collection/%s", autoId.c_str()]; } @@ -174,7 +176,7 @@ NS_ASSUME_NONNULL_BEGIN } - (FIRCollectionReference *)collectionRef { - std::string autoId = firestore::CreateAutoId(); + std::string autoId = CreateAutoId(); NSString *collectionName = [NSString stringWithFormat:@"test-collection-%s", autoId.c_str()]; return [self.db collectionWithPath:collectionName]; } diff --git a/Firestore/Source/API/FIRCollectionReference.mm b/Firestore/Source/API/FIRCollectionReference.mm index 7b487c6..92cccc6 100644 --- a/Firestore/Source/API/FIRCollectionReference.mm +++ b/Firestore/Source/API/FIRCollectionReference.mm @@ -16,7 +16,7 @@ #import "FIRCollectionReference.h" -#include "Firestore/src/core/util/autoid.h" +#include "Firestore/core/src/firebase/firestore/util/autoid.h" #import "Firestore/Source/API/FIRDocumentReference+Internal.h" #import "Firestore/Source/API/FIRQuery+Internal.h" @@ -27,6 +27,8 @@ #import "Firestore/Source/Util/FSTAssert.h" #import "Firestore/Source/Util/FSTUsageValidation.h" +using firebase::firestore::util::CreateAutoId; + NS_ASSUME_NONNULL_BEGIN @interface FIRCollectionReference () @@ -103,7 +105,7 @@ NS_ASSUME_NONNULL_BEGIN } - (FIRDocumentReference *)documentWithAutoID { - NSString *autoID = [NSString stringWithUTF8String:firestore::CreateAutoId().c_str()]; + NSString *autoID = [NSString stringWithUTF8String:CreateAutoId().c_str()]; FSTDocumentKey *key = [FSTDocumentKey keyWithPath:[self.query.path pathByAppendingSegment:autoID]]; return [FIRDocumentReference referenceWithKey:key firestore:self.firestore]; diff --git a/Firestore/Source/Auth/FSTCredentialsProvider.m b/Firestore/Source/Auth/FSTCredentialsProvider.m index 57d79cb..653d7ff 100644 --- a/Firestore/Source/Auth/FSTCredentialsProvider.m +++ b/Firestore/Source/Auth/FSTCredentialsProvider.m @@ -83,7 +83,8 @@ NS_ASSUME_NONNULL_BEGIN NSDictionary *userInfo = notification.userInfo; // ensure we're only notifiying for the current app. - FIRApp *notifiedApp = userInfo[FIRAuthStateDidChangeInternalNotificationAppKey]; + FIRApp *notifiedApp = + userInfo[FIRAuthStateDidChangeInternalNotificationAppKey]; if (![self.app isEqual:notifiedApp]) { return; } diff --git a/Firestore/Source/Public/FIRCollectionReference.h b/Firestore/Source/Public/FIRCollectionReference.h index ba3389f..bc9a56a 100644 --- a/Firestore/Source/Public/FIRCollectionReference.h +++ b/Firestore/Source/Public/FIRCollectionReference.h @@ -81,7 +81,9 @@ NS_SWIFT_NAME(CollectionReference) * automatically. * * @param data An `NSDictionary` containing the data for the new document. - * @param completion A block to execute once the document has been successfully written. + * @param completion A block to execute once the document has been successfully written to + * the server. This block will not be called while the client is offline, though local + * changes will be visible immediately. * * @return A `FIRDocumentReference` pointing to the newly created document. */ diff --git a/Firestore/Source/Public/FIRDocumentReference.h b/Firestore/Source/Public/FIRDocumentReference.h index bd6d7b8..439e727 100644 --- a/Firestore/Source/Public/FIRDocumentReference.h +++ b/Firestore/Source/Public/FIRDocumentReference.h @@ -121,8 +121,10 @@ NS_SWIFT_NAME(DocumentReference) * is created. If a document already exists, it is overwritten. * * @param documentData An `NSDictionary` containing the fields that make up the document - * to be written. - * @param completion A block to execute once the document has been successfully written. + * to be written. + * @param completion A block to execute once the document has been successfully written to the + * server. This block will not be called while the client is offline, though local + * changes will be visible immediately. */ - (void)setData:(NSDictionary<NSString *, id> *)documentData completion:(nullable void (^)(NSError *_Nullable error))completion; @@ -135,7 +137,9 @@ NS_SWIFT_NAME(DocumentReference) * @param documentData An `NSDictionary` containing the fields that make up the document * to be written. * @param options A `FIRSetOptions` used to configure the set behavior. - * @param completion A block to execute once the document has been successfully written. + * @param completion A block to execute once the document has been successfully written to the + * server. This block will not be called while the client is offline, though local + * changes will be visible immediately. */ - (void)setData:(NSDictionary<NSString *, id> *)documentData options:(FIRSetOptions *)options @@ -146,7 +150,7 @@ NS_SWIFT_NAME(DocumentReference) * If the document does not exist, the update fails (specify a completion block to be notified). * * @param fields An `NSDictionary` containing the fields (expressed as an `NSString` or - * `FIRFieldPath`) and values with which to update the document. + * `FIRFieldPath`) and values with which to update the document. */ - (void)updateData:(NSDictionary<id, id> *)fields; @@ -155,9 +159,12 @@ NS_SWIFT_NAME(DocumentReference) * does not exist, the update fails and the specified completion block receives an error. * * @param fields An `NSDictionary` containing the fields (expressed as an `NSString` or - * `FIRFieldPath`) and values with which to update the document. + * `FIRFieldPath`) and values with which to update the document. * @param completion A block to execute when the update is complete. If the update is successful the - * error parameter will be nil, otherwise it will give an indication of how the update failed. + * error parameter will be nil, otherwise it will give an indication of how the update failed. + * This block will only execute when the client is online and the commit has completed against + * the server. The completion handler will not be called when the device is offline, though + * local changes will be visible immediately. */ - (void)updateData:(NSDictionary<id, id> *)fields completion:(nullable void (^)(NSError *_Nullable error))completion; @@ -171,7 +178,9 @@ NS_SWIFT_NAME(DocumentReference) /** * Deletes the document referred to by this `FIRDocumentReference`. * - * @param completion A block to execute once the document has been successfully deleted. + * @param completion A block to execute once the document has been successfully written to the + * server. This block will not be called while the client is offline, though local + * changes will be visible immediately. */ // clang-format off - (void)deleteDocumentWithCompletion:(nullable void (^)(NSError *_Nullable error))completion diff --git a/Firestore/Source/Public/FIRFirestore.h b/Firestore/Source/Public/FIRFirestore.h index 0935917..91a96a5 100644 --- a/Firestore/Source/Public/FIRFirestore.h +++ b/Firestore/Source/Public/FIRFirestore.h @@ -115,10 +115,11 @@ NS_SWIFT_NAME(Firestore) * and collections. Unlike other firestore access, data accessed with the transaction will not * reflect local changes that have not been committed. For this reason, it is required that all * reads are performed before any writes. Transactions must be performed while online. Otherwise, - * reads will fail, and the final commit will fail. + * reads will fail, the final commit will fail, and the completion block will return an error. * * @param updateBlock The block to execute within the transaction context. - * @param completion The block to call with the result or error of the transaction. + * @param completion The block to call with the result or error of the transaction. This + * block will run even if the client is offline, unless the process is killed. */ - (void)runTransactionWithBlock:(id _Nullable (^)(FIRTransaction *, NSError **))updateBlock completion:(void (^)(id _Nullable result, NSError *_Nullable error))completion; diff --git a/Firestore/Source/Public/FIRWriteBatch.h b/Firestore/Source/Public/FIRWriteBatch.h index a74d451..5f0034c 100644 --- a/Firestore/Source/Public/FIRWriteBatch.h +++ b/Firestore/Source/Public/FIRWriteBatch.h @@ -73,7 +73,7 @@ NS_SWIFT_NAME(WriteBatch) * If document does not exist, the write batch will fail. * * @param fields An `NSDictionary` containing the fields (expressed as an `NSString` or - * `FIRFieldPath`) and values with which to update the document. + * `FIRFieldPath`) and values with which to update the document. * @param document A reference to the document whose data should be updated. * @return This `FIRWriteBatch` instance. Used for chaining method calls. */ @@ -96,7 +96,10 @@ NS_SWIFT_NAME(WriteBatch) * Commits all of the writes in this write batch as a single atomic unit. * * @param completion A block to be called once all of the writes in the batch have been - * successfully written to the backend as an atomic unit. + * successfully written to the backend as an atomic unit. This block will only execute + * when the client is online and the commit has completed against the server. The + * completion handler will not be called when the device is offline, though local + * changes will be visible immediately. */ - (void)commitWithCompletion:(void (^)(NSError *_Nullable error))completion; diff --git a/Firestore/Source/Remote/FSTExponentialBackoff.mm b/Firestore/Source/Remote/FSTExponentialBackoff.mm index ad27c25..8077357 100644 --- a/Firestore/Source/Remote/FSTExponentialBackoff.mm +++ b/Firestore/Source/Remote/FSTExponentialBackoff.mm @@ -18,11 +18,13 @@ #include <random> -#include "Firestore/src/support/secure_random.h" +#include "Firestore/core/src/firebase/firestore/util/secure_random.h" #import "Firestore/Source/Util/FSTDispatchQueue.h" #import "Firestore/Source/Util/FSTLogger.h" +using firebase::firestore::util::SecureRandom; + @interface FSTExponentialBackoff () - (instancetype)initWithDispatchQueue:(FSTDispatchQueue *)dispatchQueue initialDelay:(NSTimeInterval)initialDelay @@ -37,7 +39,7 @@ @end @implementation FSTExponentialBackoff { - firestore::SecureRandom _secureRandom; + SecureRandom _secureRandom; } - (instancetype)initWithDispatchQueue:(FSTDispatchQueue *)dispatchQueue diff --git a/Firestore/Source/Remote/FSTStream.m b/Firestore/Source/Remote/FSTStream.m index 614f611..21b343a 100644 --- a/Firestore/Source/Remote/FSTStream.m +++ b/Firestore/Source/Remote/FSTStream.m @@ -343,6 +343,9 @@ static const NSTimeInterval kIdleTimeout = 60.0; - (void)closeWithFinalState:(FSTStreamState)finalState error:(nullable NSError *)error { FSTAssert(finalState == FSTStreamStateError || error == nil, @"Can't provide an error when not in an error state."); + FSTAssert(self.delegate, + @"closeWithFinalState should only be called for a started stream that has an active " + @"delegate."); [self.workerDispatchQueue verifyIsCurrentQueue]; [self cancelIdleCheck]; @@ -388,9 +391,6 @@ static const NSTimeInterval kIdleTimeout = 60.0; } // Clear the delegates to avoid any possible bleed through of events from GRPC. - FSTAssert(_delegate, - @"closeWithFinalState should only be called for a started stream that has an active " - @"delegate."); _delegate = nil; } @@ -515,7 +515,11 @@ static const NSTimeInterval kIdleTimeout = 60.0; */ - (void)handleStreamClose:(nullable NSError *)error { FSTLog(@"%@ %p close: %@", NSStringFromClass([self class]), (__bridge void *)self, error); - FSTAssert([self isStarted], @"Can't handle server close in non-started state."); + + if (![self isStarted]) { // The stream could have already been closed by the idle close timer. + FSTLog(@"%@ Ignoring server close for already closed stream.", NSStringFromClass([self class])); + return; + } // In theory the stream could close cleanly, however, in our current model we never expect this // to happen because if we stop a stream ourselves, this callback will never be called. To @@ -538,9 +542,10 @@ static const NSTimeInterval kIdleTimeout = 60.0; FSTWeakify(self); [self.workerDispatchQueue dispatchAsync:^{ FSTStrongify(self); - if (!self || self.state == FSTStreamStateStopped) { - return; + if (!self || ![self isStarted]) { + FSTLog(@"%@ Ignoring stream message from inactive stream.", NSStringFromClass([self class])); } + if (!self.messageReceived) { self.messageReceived = YES; if ([FIRFirestore isLoggingEnabled]) { @@ -615,7 +620,9 @@ static const NSTimeInterval kIdleTimeout = 60.0; } - (void)notifyStreamInterruptedWithError:(nullable NSError *)error { - [self.delegate watchStreamWasInterruptedWithError:error]; + id<FSTWatchStreamDelegate> delegate = self.delegate; + self.delegate = nil; + [delegate watchStreamWasInterruptedWithError:error]; } - (void)watchQuery:(FSTQueryData *)query { @@ -701,7 +708,9 @@ static const NSTimeInterval kIdleTimeout = 60.0; } - (void)notifyStreamInterruptedWithError:(nullable NSError *)error { - [self.delegate writeStreamWasInterruptedWithError:error]; + id<FSTWriteStreamDelegate> delegate = self.delegate; + self.delegate = nil; + [delegate writeStreamWasInterruptedWithError:error]; } - (void)tearDown { diff --git a/Firestore/Source/Util/FSTLogger.m b/Firestore/Source/Util/FSTLogger.m index 7742aeb..f0081e0 100644 --- a/Firestore/Source/Util/FSTLogger.m +++ b/Firestore/Source/Util/FSTLogger.m @@ -16,7 +16,8 @@ #import "Firestore/Source/Util/FSTLogger.h" -#import "FIRLogger.h" +#import <FirebaseCore/FIRLogger.h> + #import "Firestore/Source/API/FIRFirestore+Internal.h" NS_ASSUME_NONNULL_BEGIN diff --git a/Firestore/src/.clang-format b/Firestore/core/.clang-format index 7a0e321..7a0e321 100644 --- a/Firestore/src/.clang-format +++ b/Firestore/core/.clang-format diff --git a/Firestore/src/support/port.h b/Firestore/core/src/firebase/firestore/base/port.h index 6af898a..37d1041 100644 --- a/Firestore/src/support/port.h +++ b/Firestore/core/src/firebase/firestore/base/port.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef FIRESTORE_SRC_SUPPORT_PORT_H_ -#define FIRESTORE_SRC_SUPPORT_PORT_H_ +#ifndef FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_BASE_PORT_H_ +#define FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_BASE_PORT_H_ #if defined(__APPLE__) // On Apple platforms we support building via Cocoapods without CMake. When @@ -30,4 +30,4 @@ #error "Unknown platform." #endif // defined(__APPLE__) -#endif // FIRESTORE_SRC_SUPPORT_PORT_H_ +#endif // FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_BASE_PORT_H_ diff --git a/Firestore/src/support/CMakeLists.txt b/Firestore/core/src/firebase/firestore/util/CMakeLists.txt index 8110c6f..ce81363 100644 --- a/Firestore/src/support/CMakeLists.txt +++ b/Firestore/core/src/firebase/firestore/util/CMakeLists.txt @@ -13,6 +13,7 @@ # limitations under the License. add_library( - firestore_support + firebase_firestore_util + autoid.cc secure_random_arc4random.cc ) diff --git a/Firestore/src/core/util/autoid.cc b/Firestore/core/src/firebase/firestore/util/autoid.cc index 762bbcc..10a2cde 100644 --- a/Firestore/src/core/util/autoid.cc +++ b/Firestore/core/src/firebase/firestore/util/autoid.cc @@ -14,12 +14,16 @@ * limitations under the License. */ -#include "Firestore/src/core/util/autoid.h" +#include "Firestore/core/src/firebase/firestore/util/autoid.h" #include <random> #include <string> -#include "Firestore/src/support/secure_random.h" +#include "Firestore/core/src/firebase/firestore/util/secure_random.h" + +namespace firebase { +namespace firestore { +namespace util { namespace { @@ -27,12 +31,10 @@ const int kAutoIdLength = 20; const char kAutoIdAlphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; -firestore::SecureRandom shared_random; +SecureRandom shared_random; } // namespace -namespace firestore { - std::string CreateAutoId() { std::string auto_id; auto_id.reserve(kAutoIdLength); @@ -49,4 +51,6 @@ std::string CreateAutoId() { return auto_id; } +} // namespace util } // namespace firestore +} // namespace firebase diff --git a/Firestore/src/core/util/autoid.h b/Firestore/core/src/firebase/firestore/util/autoid.h index 13486af..22d7d7d 100644 --- a/Firestore/src/core/util/autoid.h +++ b/Firestore/core/src/firebase/firestore/util/autoid.h @@ -14,16 +14,20 @@ * limitations under the License. */ -#ifndef FIRESTORE_SRC_CORE_UTIL_AUTOID_H_ -#define FIRESTORE_SRC_CORE_UTIL_AUTOID_H_ +#ifndef FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_UTIL_AUTOID_H_ +#define FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_UTIL_AUTOID_H_ #include <string> +namespace firebase { namespace firestore { +namespace util { // Generates a random ID suitable for use as a document ID. std::string CreateAutoId(); +} // namespace util } // namespace firestore +} // namespace firebase -#endif // FIRESTORE_SRC_CORE_UTIL_AUTOID_H_ +#endif // FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_UTIL_AUTOID_H_ diff --git a/Firestore/src/support/secure_random.h b/Firestore/core/src/firebase/firestore/util/secure_random.h index 92a3eaf..72be1bd 100644 --- a/Firestore/src/support/secure_random.h +++ b/Firestore/core/src/firebase/firestore/util/secure_random.h @@ -14,14 +14,16 @@ * limitations under the License. */ -#ifndef FIRESTORE_SRC_SUPPORT_SECURE_RANDOM_H_ -#define FIRESTORE_SRC_SUPPORT_SECURE_RANDOM_H_ +#ifndef FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_UTIL_SECURE_RANDOM_H_ +#define FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_UTIL_SECURE_RANDOM_H_ #include <stdint.h> #include <limits> +namespace firebase { namespace firestore { +namespace util { // A "secure" pseudorandom number generator, suitable for generating // unguessable identifiers. This exists because @@ -50,6 +52,8 @@ class SecureRandom { result_type operator()(); }; +} // namespace util } // namespace firestore +} // namespace firebase -#endif // FIRESTORE_SRC_SUPPORT_SECURE_RANDOM_H_ +#endif // FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_UTIL_SECURE_RANDOM_H_ diff --git a/Firestore/src/support/secure_random_arc4random.cc b/Firestore/core/src/firebase/firestore/util/secure_random_arc4random.cc index 4cd7f9d..a76ade3 100644 --- a/Firestore/src/support/secure_random_arc4random.cc +++ b/Firestore/core/src/firebase/firestore/util/secure_random_arc4random.cc @@ -14,20 +14,24 @@ * limitations under the License. */ -#include "Firestore/src/support/secure_random.h" +#include "Firestore/core/src/firebase/firestore/util/secure_random.h" -#include "Firestore/src/support/port.h" +#include "Firestore/core/src/firebase/firestore/base/port.h" #if HAVE_ARC4RANDOM #include <stdlib.h> +namespace firebase { namespace firestore { +namespace util { SecureRandom::result_type SecureRandom::operator()() { return arc4random(); } +} // namespace util } // namespace firestore +} // namespace firebase #endif // HAVE_ARC4RANDOM diff --git a/Firestore/test/support/CMakeLists.txt b/Firestore/core/test/firebase/firestore/util/CMakeLists.txt index 7de5367..223fa41 100644 --- a/Firestore/test/support/CMakeLists.txt +++ b/Firestore/core/test/firebase/firestore/util/CMakeLists.txt @@ -13,10 +13,11 @@ # limitations under the License. cc_test( - firestore_support_test + firebase_firestore_util_test + autoid_test.cc secure_random_test.cc ) target_link_libraries( - firestore_support_test - firestore_support + firebase_firestore_util_test + firebase_firestore_util ) diff --git a/Firestore/test/core/util/autoid_test.cc b/Firestore/core/test/firebase/firestore/util/autoid_test.cc index b17a34e..730c683 100644 --- a/Firestore/test/core/util/autoid_test.cc +++ b/Firestore/core/test/firebase/firestore/util/autoid_test.cc @@ -14,20 +14,23 @@ * limitations under the License. */ -#include "Firestore/src/core/util/autoid.h" +#include "Firestore/core/src/firebase/firestore/util/autoid.h" #include <ctype.h> #include "gtest/gtest.h" +using firebase::firestore::util::CreateAutoId; + TEST(AutoId, IsSane) { for (int i = 0; i < 50; i++) { - std::string auto_id = firestore::CreateAutoId(); + std::string auto_id = CreateAutoId(); EXPECT_EQ(20, auto_id.length()); for (int pos = 0; pos < 20; pos++) { char c = auto_id[pos]; EXPECT_TRUE(isalpha(c) || isdigit(c)) - << "Should be printable ascii character: '" << c << "' in \"" << auto_id << "\""; + << "Should be printable ascii character: '" << c << "' in \"" + << auto_id << "\""; } } } diff --git a/Firestore/test/support/secure_random_test.cc b/Firestore/core/test/firebase/firestore/util/secure_random_test.cc index 244227b..f96f3de 100644 --- a/Firestore/test/support/secure_random_test.cc +++ b/Firestore/core/test/firebase/firestore/util/secure_random_test.cc @@ -14,11 +14,11 @@ * limitations under the License. */ -#include "Firestore/src/support/secure_random.h" +#include "Firestore/core/src/firebase/firestore/util/secure_random.h" #include "gtest/gtest.h" -using firestore::SecureRandom; +using firebase::firestore::util::SecureRandom; TEST(SecureRandomTest, ResultsAreBounded) { SecureRandom rng; diff --git a/Firestore/src/core/util/CMakeLists.txt b/Firestore/src/core/util/CMakeLists.txt deleted file mode 100644 index 6b08d8e..0000000 --- a/Firestore/src/core/util/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright 2017 Google -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -add_library( - firestore_core_util - autoid.cc -) -target_link_libraries( - firestore_core_util - firestore_support -) diff --git a/Firestore/test/core/util/CMakeLists.txt b/Firestore/test/core/util/CMakeLists.txt deleted file mode 100644 index 1989c0e..0000000 --- a/Firestore/test/core/util/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright 2017 Google -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -cc_test( - firestore_core_util_test - autoid_test.cc -) -target_link_libraries( - firestore_core_util_test - firestore_core_util -) |