Skip to content

Commit 61f173e

Browse files
authored
C++ migration: port FSTOnlineStateTracker (#2325)
1 parent 9ec14cc commit 61f173e

File tree

12 files changed

+318
-311
lines changed

12 files changed

+318
-311
lines changed

Firestore/Example/Tests/Integration/FSTDatastoreTests.mm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
using firebase::firestore::model::DocumentKey;
5656
using firebase::firestore::model::DocumentKeySet;
5757
using firebase::firestore::model::Precondition;
58+
using firebase::firestore::model::OnlineState;
5859
using firebase::firestore::model::TargetId;
5960
using firebase::firestore::remote::Datastore;
6061
using firebase::firestore::remote::GrpcConnection;
@@ -186,7 +187,8 @@ - (void)setUp {
186187

187188
_remoteStore = [[FSTRemoteStore alloc] initWithLocalStore:_localStore
188189
datastore:_datastore
189-
workerQueue:_testWorkerQueue.get()];
190+
workerQueue:_testWorkerQueue.get()
191+
onlineStateHandler:[](OnlineState) {}];
190192

191193
_testWorkerQueue->Enqueue([=] { [_remoteStore start]; });
192194
}

Firestore/Example/Tests/SpecTests/FSTSyncEngineTestDriver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ typedef std::unordered_map<firebase::firestore::auth::User,
8686
*
8787
* Each method on the driver injects a different event into the system.
8888
*/
89-
@interface FSTSyncEngineTestDriver : NSObject <FSTOnlineStateDelegate>
89+
@interface FSTSyncEngineTestDriver : NSObject
9090

9191
/**
9292
* Initializes the underlying FSTSyncEngine with the given local persistence implementation and

Firestore/Example/Tests/SpecTests/FSTSyncEngineTestDriver.mm

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,18 +153,21 @@ - (instancetype)initWithPersistence:(id<FSTPersistence>)persistence
153153

154154
_datastore =
155155
std::make_shared<MockDatastore>(_databaseInfo, _workerQueue.get(), &_credentialProvider);
156-
_remoteStore = [[FSTRemoteStore alloc] initWithLocalStore:_localStore
157-
datastore:_datastore
158-
workerQueue:_workerQueue.get()];
156+
_remoteStore =
157+
[[FSTRemoteStore alloc] initWithLocalStore:_localStore
158+
datastore:_datastore
159+
workerQueue:_workerQueue.get()
160+
onlineStateHandler:[self](OnlineState onlineState) {
161+
[self.syncEngine applyChangedOnlineState:onlineState];
162+
[self.eventManager applyChangedOnlineState:onlineState];
163+
}];
159164

160165
_syncEngine = [[FSTSyncEngine alloc] initWithLocalStore:_localStore
161166
remoteStore:_remoteStore
162167
initialUser:initialUser];
163168
_remoteStore.syncEngine = _syncEngine;
164169
_eventManager = [FSTEventManager eventManagerWithSyncEngine:_syncEngine];
165170

166-
_remoteStore.onlineStateDelegate = self;
167-
168171
// Set up internal event tracking for the spec tests.
169172
NSMutableArray<FSTQueryEvent *> *events = [NSMutableArray array];
170173
_eventHandler = ^(FSTQueryEvent *e) {
@@ -203,11 +206,6 @@ - (void)drainQueue {
203206
return _currentUser;
204207
}
205208

206-
- (void)applyChangedOnlineState:(OnlineState)onlineState {
207-
[self.syncEngine applyChangedOnlineState:onlineState];
208-
[self.eventManager applyChangedOnlineState:onlineState];
209-
}
210-
211209
- (void)start {
212210
_workerQueue->EnqueueBlocking([&] {
213211
[self.localStore start];

Firestore/Source/Core/FSTEventManager.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ NS_ASSUME_NONNULL_BEGIN
7575
* EventManager is responsible for mapping queries to query event emitters. It handles "fan-out."
7676
* (Identical queries will re-use the same watch on the backend.)
7777
*/
78-
@interface FSTEventManager : NSObject <FSTOnlineStateDelegate>
78+
@interface FSTEventManager : NSObject
7979

8080
+ (instancetype)eventManagerWithSyncEngine:(FSTSyncEngine *)syncEngine;
8181

@@ -84,6 +84,8 @@ NS_ASSUME_NONNULL_BEGIN
8484
- (firebase::firestore::model::TargetId)addListener:(FSTQueryListener *)listener;
8585
- (void)removeListener:(FSTQueryListener *)listener;
8686

87+
- (void)applyChangedOnlineState:(firebase::firestore::model::OnlineState)onlineState;
88+
8789
@end
8890

8991
NS_ASSUME_NONNULL_END

Firestore/Source/Core/FSTFirestoreClient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ NS_ASSUME_NONNULL_BEGIN
4949
* SDK architecture. It is responsible for creating the worker queue that is shared by all of the
5050
* other components in the system.
5151
*/
52-
@interface FSTFirestoreClient : NSObject <FSTOnlineStateDelegate>
52+
@interface FSTFirestoreClient : NSObject
5353

5454
/**
5555
* Creates and returns a FSTFirestoreClient with the given parameters.

Firestore/Source/Core/FSTFirestoreClient.mm

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,10 @@ - (void)initializeWithUser:(const User &)user settings:(FIRFirestoreSettings *)s
228228

229229
_remoteStore = [[FSTRemoteStore alloc] initWithLocalStore:_localStore
230230
datastore:std::move(datastore)
231-
workerQueue:_workerQueue.get()];
231+
workerQueue:_workerQueue.get()
232+
onlineStateHandler:[self](OnlineState onlineState) {
233+
[self.syncEngine applyChangedOnlineState:onlineState];
234+
}];
232235

233236
_syncEngine = [[FSTSyncEngine alloc] initWithLocalStore:_localStore
234237
remoteStore:_remoteStore
@@ -239,8 +242,6 @@ - (void)initializeWithUser:(const User &)user settings:(FIRFirestoreSettings *)s
239242
// Setup wiring for remote store.
240243
_remoteStore.syncEngine = _syncEngine;
241244

242-
_remoteStore.onlineStateDelegate = self;
243-
244245
// NOTE: RemoteStore depends on LocalStore (for persisting stream tokens, refilling mutation
245246
// queue, etc.) so must be started after LocalStore.
246247
[_localStore start];
@@ -267,10 +268,6 @@ - (void)credentialDidChangeWithUser:(const User &)user {
267268
[self.syncEngine credentialDidChangeWithUser:user];
268269
}
269270

270-
- (void)applyChangedOnlineState:(OnlineState)onlineState {
271-
[self.syncEngine applyChangedOnlineState:onlineState];
272-
}
273-
274271
- (void)disableNetworkWithCompletion:(nullable FSTVoidErrorBlock)completion {
275272
_workerQueue->Enqueue([self, completion] {
276273
[self.remoteStore disableNetwork];

Firestore/Source/Remote/FSTOnlineStateTracker.h

Lines changed: 0 additions & 72 deletions
This file was deleted.

Firestore/Source/Remote/FSTOnlineStateTracker.mm

Lines changed: 0 additions & 175 deletions
This file was deleted.

0 commit comments

Comments
 (0)