Skip to content

Commit 4267fcb

Browse files
committed
Wip
1 parent 21fcf54 commit 4267fcb

File tree

5 files changed

+29
-20
lines changed

5 files changed

+29
-20
lines changed

Firestore/Example/Firestore.xcodeproj/project.pbxproj

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@
206206
B67BF44A216EB43000CA9097 /* create_noop_connectivity_monitor.cc in Sources */ = {isa = PBXBuildFile; fileRef = B67BF448216EB43000CA9097 /* create_noop_connectivity_monitor.cc */; };
207207
B686F2AF2023DDEE0028D6BE /* field_path_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = B686F2AD2023DDB20028D6BE /* field_path_test.cc */; };
208208
B686F2B22025000D0028D6BE /* resource_path_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = B686F2B02024FFD70028D6BE /* resource_path_test.cc */; };
209+
B69CF05C219B9106004C434D /* FSTFirestoreClient+Testing.mm in Sources */ = {isa = PBXBuildFile; fileRef = B69CF058219B9105004C434D /* FSTFirestoreClient+Testing.mm */; };
210+
B69CF05D219B9106004C434D /* FIRFirestore+Testing.mm in Sources */ = {isa = PBXBuildFile; fileRef = B69CF059219B9105004C434D /* FIRFirestore+Testing.mm */; };
209211
B6BBE43121262CF400C6A53E /* grpc_stream_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = B6BBE42F21262CF400C6A53E /* grpc_stream_test.cc */; };
210212
B6D1B68520E2AB1B00B35856 /* exponential_backoff_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = B6D1B68420E2AB1A00B35856 /* exponential_backoff_test.cc */; };
211213
B6D9649121544D4F00EB9CFB /* grpc_connection_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = B6D9649021544D4F00EB9CFB /* grpc_connection_test.cc */; };
@@ -307,7 +309,7 @@
307309
2A0CF41BA5AED6049B0BEB2C /* type_traits_apple_test.mm */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.cpp.objcpp; path = type_traits_apple_test.mm; sourceTree = "<group>"; };
308310
2B50B3A0DF77100EEE887891 /* Pods_Firestore_Tests_iOS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Firestore_Tests_iOS.framework; sourceTree = BUILT_PRODUCTS_DIR; };
309311
332485C4DCC6BA0DBB5E31B7 /* leveldb_util_test.cc */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.cpp.cpp; path = leveldb_util_test.cc; sourceTree = "<group>"; };
310-
353EEE078EF3F39A9B7279F6 /* nanopb_string_test.cc */ = {isa = PBXFileReference; includeInIndex = 1; name = nanopb_string_test.cc; path = nanopb/nanopb_string_test.cc; sourceTree = "<group>"; };
312+
353EEE078EF3F39A9B7279F6 /* nanopb_string_test.cc */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.cpp.cpp; name = nanopb_string_test.cc; path = nanopb/nanopb_string_test.cc; sourceTree = "<group>"; };
311313
358C3B5FE573B1D60A4F7592 /* strerror_test.cc */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.cpp.cpp; path = strerror_test.cc; sourceTree = "<group>"; };
312314
3B843E4A1F3930A400548890 /* remote_store_spec_test.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = remote_store_spec_test.json; sourceTree = "<group>"; };
313315
3C81DE3772628FE297055662 /* Pods-Firestore_Example_iOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Firestore_Example_iOS.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Firestore_Example_iOS/Pods-Firestore_Example_iOS.debug.xcconfig"; sourceTree = "<group>"; };
@@ -524,6 +526,10 @@
524526
B67BF448216EB43000CA9097 /* create_noop_connectivity_monitor.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = create_noop_connectivity_monitor.cc; sourceTree = "<group>"; };
525527
B686F2AD2023DDB20028D6BE /* field_path_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = field_path_test.cc; sourceTree = "<group>"; };
526528
B686F2B02024FFD70028D6BE /* resource_path_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = resource_path_test.cc; sourceTree = "<group>"; };
529+
B69CF058219B9105004C434D /* FSTFirestoreClient+Testing.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "FSTFirestoreClient+Testing.mm"; sourceTree = "<group>"; };
530+
B69CF059219B9105004C434D /* FIRFirestore+Testing.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "FIRFirestore+Testing.mm"; sourceTree = "<group>"; };
531+
B69CF05A219B9105004C434D /* FIRFirestore+Testing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "FIRFirestore+Testing.h"; sourceTree = "<group>"; };
532+
B69CF05B219B9105004C434D /* FSTFirestoreClient+Testing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "FSTFirestoreClient+Testing.h"; sourceTree = "<group>"; };
527533
B6BBE42F21262CF400C6A53E /* grpc_stream_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = grpc_stream_test.cc; sourceTree = "<group>"; };
528534
B6D1B68420E2AB1A00B35856 /* exponential_backoff_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = exponential_backoff_test.cc; sourceTree = "<group>"; };
529535
B6D9649021544D4F00EB9CFB /* grpc_connection_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = grpc_connection_test.cc; sourceTree = "<group>"; };
@@ -1159,6 +1165,10 @@
11591165
DE51B1851F0D48AC0013853F /* Util */ = {
11601166
isa = PBXGroup;
11611167
children = (
1168+
B69CF05A219B9105004C434D /* FIRFirestore+Testing.h */,
1169+
B69CF059219B9105004C434D /* FIRFirestore+Testing.mm */,
1170+
B69CF05B219B9105004C434D /* FSTFirestoreClient+Testing.h */,
1171+
B69CF058219B9105004C434D /* FSTFirestoreClient+Testing.mm */,
11621172
54E9281C1F33950B00C1953E /* FSTEventAccumulator.h */,
11631173
5492E0392021401F00B64F25 /* FSTEventAccumulator.mm */,
11641174
DE51B1881F0D48AC0013853F /* FSTHelpers.h */,
@@ -2023,6 +2033,7 @@
20232033
files = (
20242034
73866AA12082B0A5009BB4FF /* FIRArrayTransformTests.mm in Sources */,
20252035
5492E079202154D600B64F25 /* FIRCursorTests.mm in Sources */,
2036+
B69CF05D219B9106004C434D /* FIRFirestore+Testing.mm in Sources */,
20262037
5492E075202154D600B64F25 /* FIRDatabaseTests.mm in Sources */,
20272038
5492E073202154D600B64F25 /* FIRFieldsTests.mm in Sources */,
20282039
6161B5032047140C00A99DBB /* FIRFirestoreSourceTests.mm in Sources */,
@@ -2038,6 +2049,7 @@
20382049
5491BC731FB44593008B3588 /* FSTIntegrationTestCase.mm in Sources */,
20392050
5492E080202154EC00B64F25 /* FSTSmokeTests.mm in Sources */,
20402051
5492E07F202154EC00B64F25 /* FSTTransactionTests.mm in Sources */,
2052+
B69CF05C219B9106004C434D /* FSTFirestoreClient+Testing.mm in Sources */,
20412053
5492E0442021457E00B64F25 /* XCTestCase+Await.mm in Sources */,
20422054
B67BF44A216EB43000CA9097 /* create_noop_connectivity_monitor.cc in Sources */,
20432055
EBFC611B1BF195D0EC710AF4 /* app_testing.mm in Sources */,

Firestore/Example/Tests/Util/FSTIntegrationTestCase.mm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#import "Firestore/Source/Local/FSTLevelDB.h"
5050

5151
#import "Firestore/Example/Tests/Util/FSTEventAccumulator.h"
52+
#import "Firestore/Example/Tests/Util/FIRFirestore+Testing.h"
5253

5354
#include "Firestore/core/src/firebase/firestore/util/async_queue.h"
5455
#include "Firestore/core/src/firebase/firestore/util/executor_libdispatch.h"

Firestore/Source/API/FIRFirestore.mm

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,14 @@ @interface FIRFirestore () {
8181
@end
8282

8383
@implementation FIRFirestore {
84+
// Ownership will be transferred to `FSTFirestoreClient` as soon as the client is created.
8485
std::unique_ptr<AsyncQueue> _workerQueue;
8586

8687
// All guarded by @synchronized(self)
8788
FIRFirestoreSettings *_settings;
8889
FSTFirestoreClient *_client;
8990
}
9091

91-
- (AsyncQueue *)workerQueue {
92-
return _workerQueue.get();
93-
}
94-
9592
+ (NSMutableDictionary<NSString *, FIRFirestore *> *)instances {
9693
static dispatch_once_t token = 0;
9794
static NSMutableDictionary<NSString *, FIRFirestore *> *instances;
@@ -267,7 +264,7 @@ const DatabaseInfo database_info(*self.databaseID, util::MakeString(_persistence
267264
usePersistence:_settings.persistenceEnabled
268265
credentialsProvider:_credentialsProvider.get()
269266
userExecutor:std::move(userExecutor)
270-
workerQueue:_workerQueue.get()];
267+
workerQueue:std::move(_workerQueue)];
271268
}
272269
}
273270
}

Firestore/Source/Core/FSTFirestoreClient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ NS_ASSUME_NONNULL_BEGIN
6161
credentialsProvider // no passing ownership
6262
userExecutor:
6363
(std::unique_ptr<firebase::firestore::util::Executor>)userExecutor
64-
workerQueue:(firebase::firestore::util::AsyncQueue *)workerQueue;
64+
workerQueue:(std::unique_ptr<firebase::firestore::util::AsyncQueue>)workerQueue;
6565

6666
- (instancetype)init __attribute__((unavailable("Use static constructor method.")));
6767

Firestore/Source/Core/FSTFirestoreClient.mm

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ - (instancetype)initWithDatabaseInfo:(const DatabaseInfo &)databaseInfo
7373
credentialsProvider:
7474
(CredentialsProvider *)credentialsProvider // no passing ownership
7575
userExecutor:(std::unique_ptr<Executor>)userExecutor
76-
workerQueue:(AsyncQueue *)queue NS_DESIGNATED_INITIALIZER;
76+
workerQueue:(std::unique_ptr<AsyncQueue>)queue NS_DESIGNATED_INITIALIZER;
7777

7878
@property(nonatomic, assign, readonly) const DatabaseInfo *databaseInfo;
7979
@property(nonatomic, strong, readonly) FSTEventManager *eventManager;
@@ -89,12 +89,12 @@ - (instancetype)initWithDatabaseInfo:(const DatabaseInfo &)databaseInfo
8989

9090
@implementation FSTFirestoreClient {
9191
/**
92-
* Dispatch queue responsible for all of our internal processing. When we get incoming work from
92+
* Async queue responsible for all of our internal processing. When we get incoming work from
9393
* the user (via public API) or the network (incoming gRPC messages), we should always dispatch
9494
* onto this queue. This ensures our internal data structures are never accessed from multiple
9595
* threads simultaneously.
9696
*/
97-
AsyncQueue *_workerQueue;
97+
std::unique_ptr<AsyncQueue> _workerQueue;
9898

9999
std::unique_ptr<Executor> _userExecutor;
100100
}
@@ -108,40 +108,39 @@ + (instancetype)clientWithDatabaseInfo:(const DatabaseInfo &)databaseInfo
108108
credentialsProvider:
109109
(CredentialsProvider *)credentialsProvider // no passing ownership
110110
userExecutor:(std::unique_ptr<Executor>)userExecutor
111-
workerQueue:(AsyncQueue *)workerQueue {
111+
workerQueue:(std::unique_ptr<AsyncQueue>)workerQueue {
112112
return [[FSTFirestoreClient alloc] initWithDatabaseInfo:databaseInfo
113113
usePersistence:usePersistence
114114
credentialsProvider:credentialsProvider
115115
userExecutor:std::move(userExecutor)
116-
workerQueue:workerQueue];
116+
workerQueue:std::move(workerQueue)];
117117
}
118118

119119
- (instancetype)initWithDatabaseInfo:(const DatabaseInfo &)databaseInfo
120120
usePersistence:(BOOL)usePersistence
121121
credentialsProvider:
122122
(CredentialsProvider *)credentialsProvider // no passing ownership
123123
userExecutor:(std::unique_ptr<Executor>)userExecutor
124-
workerQueue:(AsyncQueue *)workerQueue {
124+
workerQueue:(std::unique_ptr<AsyncQueue>)workerQueue {
125125
if (self = [super init]) {
126126
_databaseInfo = databaseInfo;
127127
_credentialsProvider = credentialsProvider;
128128
_userExecutor = std::move(userExecutor);
129-
_workerQueue = workerQueue;
129+
_workerQueue = std::move(workerQueue);
130130

131131
auto userPromise = std::make_shared<std::promise<User>>();
132132
bool initialized = false;
133133

134134
__weak __typeof__(self) weakSelf = self;
135-
auto credentialChangeListener = [self, initialized, userPromise, weakSelf,
136-
workerQueue](User user) mutable {
135+
auto credentialChangeListener = [initialized, userPromise, weakSelf](User user) mutable {
137136
__typeof__(self) strongSelf = weakSelf;
138137
if (!strongSelf) return;
139138

140139
if (!initialized) {
141140
initialized = true;
142141
userPromise->set_value(user);
143142
} else {
144-
_workerQueue->Enqueue([=] { [strongSelf credentialDidChangeWithUser:user]; });
143+
strongSelf->_workerQueue->Enqueue([=] { [strongSelf credentialDidChangeWithUser:user]; });
145144
}
146145
};
147146

@@ -193,12 +192,12 @@ - (void)initializeWithUser:(const User &)user usePersistence:(BOOL)usePersistenc
193192
_localStore = [[FSTLocalStore alloc] initWithPersistence:_persistence initialUser:user];
194193

195194
FSTDatastore *datastore = [FSTDatastore datastoreWithDatabase:self.databaseInfo
196-
workerQueue:_workerQueue
195+
workerQueue:_workerQueue.get()
197196
credentials:_credentialsProvider];
198197

199198
_remoteStore = [[FSTRemoteStore alloc] initWithLocalStore:_localStore
200199
datastore:datastore
201-
workerQueue:_workerQueue];
200+
workerQueue:_workerQueue.get()];
202201

203202
_syncEngine = [[FSTSyncEngine alloc] initWithLocalStore:_localStore
204203
remoteStore:_remoteStore
@@ -366,7 +365,7 @@ - (void)transactionWithRetries:(int)retries
366365
_workerQueue->Enqueue([=] {
367366
[self.syncEngine
368367
transactionWithRetries:retries
369-
workerQueue:_workerQueue
368+
workerQueue:_workerQueue.get()
370369
updateBlock:updateBlock
371370
completion:^(id _Nullable result, NSError *_Nullable error) {
372371
// Dispatch the result back onto the user dispatch queue.

0 commit comments

Comments
 (0)