Skip to content

Commit e2641bd

Browse files
committed
addressing comments #3
1 parent db41d46 commit e2641bd

File tree

10 files changed

+21
-25
lines changed

10 files changed

+21
-25
lines changed

Firestore/Example/Tests/Integration/API/FIRDatabaseTests.mm

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,13 +1331,7 @@ - (void)testRestartFirestoreLeadsToNewInstance {
13311331
@{@"owner" : @{@"name" : @"Jonny", @"email" : @"[email protected]"}};
13321332
[self writeDocumentRef:[firestore documentWithPath:@"abc/123"] data:data];
13331333

1334-
// Shutdown `firestore`.
1335-
XCTestExpectation *expectation = [self expectationWithDescription:@"shudown"];
1336-
[firestore shutdownWithCompletion:^(NSError *_Nullable error) {
1337-
XCTAssertNil(error);
1338-
[expectation fulfill];
1339-
}];
1340-
[self awaitExpectations];
1334+
[self shutdownFirestore:firestore];
13411335

13421336
// Create a new instance, check it's a different instance.
13431337
FIRFirestore *newInstance = [FIRFirestore firestoreForApp:app];

Firestore/Source/API/FIRFirestore+Internal.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ NS_ASSUME_NONNULL_BEGIN
3737
/** Provides a registry management interface for FIRFirestore instances. */
3838
@protocol FSTFirestoreInstanceRegistry
3939

40-
/** Removes the FIRFirestore instance with given name from registry. */
41-
- (void)removeInstance:(NSString *)database;
40+
/** Removes the FIRFirestore instance with given database name from registry. */
41+
- (void)removeInstanceWithDatabase:(NSString *)database;
4242

4343
@end
4444

@@ -53,7 +53,7 @@ NS_ASSUME_NONNULL_BEGIN
5353
credentialsProvider:(std::shared_ptr<auth::CredentialsProvider>)credentialsProvider
5454
workerQueue:(std::shared_ptr<util::AsyncQueue>)workerQueue
5555
firebaseApp:(FIRApp *)app
56-
instanceRegistry:(id<FSTFirestoreInstanceRegistry>)registry;
56+
instanceRegistry:(nullable id<FSTFirestoreInstanceRegistry>)registry;
5757
@end
5858

5959
/** Internal FIRFirestore API we don't want exposed in our public header files. */

Firestore/Source/API/FIRFirestore.mm

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ @interface FIRFirestore ()
7272
@implementation FIRFirestore {
7373
std::shared_ptr<Firestore> _firestore;
7474
FIRFirestoreSettings *_settings;
75-
id<FSTFirestoreInstanceRegistry> _registry;
75+
__weak id<FSTFirestoreInstanceRegistry> _registry;
7676
}
7777

7878
+ (instancetype)firestore {
@@ -110,7 +110,7 @@ - (instancetype)initWithDatabaseID:(model::DatabaseId)databaseID
110110
credentialsProvider:(std::shared_ptr<CredentialsProvider>)credentialsProvider
111111
workerQueue:(std::shared_ptr<AsyncQueue>)workerQueue
112112
firebaseApp:(FIRApp *)app
113-
instanceRegistry:(id<FSTFirestoreInstanceRegistry>)registry {
113+
instanceRegistry:(nullable id<FSTFirestoreInstanceRegistry>)registry {
114114
if (self = [super init]) {
115115
_firestore = std::make_shared<Firestore>(std::move(databaseID), std::move(persistenceKey),
116116
std::move(credentialsProvider), std::move(workerQueue),
@@ -306,8 +306,10 @@ - (void)shutdownInternalWithCompletion:(nullable void (^)(NSError *_Nullable err
306306
}
307307

308308
- (void)shutdownWithCompletion:(nullable void (^)(NSError *_Nullable error))completion {
309-
if (_registry) {
310-
[_registry removeInstance:util::MakeNSString(_firestore->database_id().database_id())];
309+
id<FSTFirestoreInstanceRegistry> strongRegistry = _registry;
310+
if (strongRegistry) {
311+
[strongRegistry
312+
removeInstanceWithDatabase:util::MakeNSString(_firestore->database_id().database_id())];
311313
}
312314
[self shutdownInternalWithCompletion:completion];
313315
}

Firestore/Source/API/FSTFirestoreComponent.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ NS_ASSUME_NONNULL_BEGIN
4949
/// Default method for retrieving a Firestore instance, or creating one if it doesn't exist.
5050
- (FIRFirestore *)firestoreForDatabase:(NSString *)database;
5151

52-
- (void)removeInstance:(NSString *)database;
52+
- (void)removeInstanceWithDatabase:(NSString *)database;
5353

5454
/// Default initializer.
5555
- (instancetype)initWithApp:(FIRApp *)app NS_DESIGNATED_INITIALIZER;

Firestore/Source/API/FSTFirestoreComponent.mm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ - (FIRFirestore *)firestoreForDatabase:(NSString *)database {
114114
}
115115
}
116116

117-
- (void)removeInstance:(NSString *)database {
118-
@synchronized(self.instances) {
117+
- (void)removeInstanceWithDatabase:(NSString *)database {
118+
@synchronized(_instances) {
119119
NSString *key = [self keyForDatabase:database];
120120
[_instances removeObjectForKey:key];
121121
}
@@ -125,7 +125,7 @@ - (void)removeInstance:(NSString *)database {
125125

126126
- (void)appWillBeDeleted:(FIRApp *)app {
127127
NSDictionary<NSString *, FIRFirestore *> *instances;
128-
@synchronized(self.instances) {
128+
@synchronized(_instances) {
129129
instances = [_instances copy];
130130
[_instances removeAllObjects];
131131
}

Firestore/Source/Core/FSTFirestoreClient.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ - (void)enableNetworkWithCallback:(util::StatusCallback)callback {
305305
}
306306

307307
- (void)shutdownWithCallback:(util::StatusCallback)callback {
308-
_workerQueue->EnqueueAndInitializeShutdown([self, callback] {
308+
_workerQueue->EnqueueAndInitiateShutdown([self, callback] {
309309
self->_credentialsProvider->SetCredentialChangeListener(nullptr);
310310

311311
// If we've scheduled LRU garbage collection, cancel it.

Firestore/core/src/firebase/firestore/remote/connectivity_monitor_apple.mm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ explicit ConnectivityMonitorApple(
100100
}
101101

102102
// It's okay to use the main queue for reachability events because they are
103-
// fairly infrequent,
104-
// and there's no good way to get the underlying dispatch queue out of the
105-
// worker queue. The callback itself is still executed on the worker queue.
103+
// fairly infrequent, and there's no good way to get the underlying dispatch
104+
// queue out of the worker queue. The callback itself is still executed on
105+
// the worker queue.
106106
success = SCNetworkReachabilitySetDispatchQueue(reachability_,
107107
dispatch_get_main_queue());
108108
if (!success) {

Firestore/core/src/firebase/firestore/util/async_queue.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void AsyncQueue::Enqueue(const Operation& operation) {
6868
EnqueueRelaxed(operation);
6969
}
7070

71-
void AsyncQueue::EnqueueAndInitializeShutdown(const Operation& operation) {
71+
void AsyncQueue::EnqueueAndInitiateShutdown(const Operation& operation) {
7272
std::lock_guard<std::mutex> lock{shut_down_mutex_};
7373
VerifySequentialOrder();
7474
if (is_shutting_down_) {

Firestore/core/src/firebase/firestore/util/async_queue.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class AsyncQueue {
106106
//
107107
// The exception is `EnqueueEvenAfterShutdown`, operations requsted via
108108
// this will still be scheduled.
109-
void EnqueueAndInitializeShutdown(const Operation& operation);
109+
void EnqueueAndInitiateShutdown(const Operation& operation);
110110

111111
// Like `Enqueue`, but it will proceed scheduling the requested operation
112112
// regardless of whether the queue is shut down or not.

Firestore/core/test/firebase/firestore/util/async_queue_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ TEST_P(AsyncQueueTest, CanScheduleOprationsWithRespectsToShutdownState) {
187187
std::string steps;
188188

189189
queue.Enqueue([&] { steps += '1'; });
190-
queue.EnqueueAndInitializeShutdown([&] { steps += '2'; });
190+
queue.EnqueueAndInitiateShutdown([&] { steps += '2'; });
191191
queue.Enqueue([&] { steps += '3'; });
192192
queue.EnqueueEvenAfterShutdown([&] { steps += '4'; });
193193
queue.EnqueueEvenAfterShutdown([&] { signal_finished(); });

0 commit comments

Comments
 (0)