Skip to content

Commit 839f408

Browse files
committed
gRPC: make gRPC calls using the C++ implementation:
* make `FSTRemoteStore` create C++ streams instead of their Objective-C counterparts; * port firebase/firebase-js-sdk#1041: streams are never recreated, only restarted. * make `FSTDatastore` delegate server calls to the C++ implementation.
1 parent 805b673 commit 839f408

File tree

7 files changed

+109
-278
lines changed

7 files changed

+109
-278
lines changed

Firestore/Example/Tests/Integration/FSTDatastoreTests.mm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
using firebase::firestore::model::DocumentKeySet;
5353
using firebase::firestore::model::Precondition;
5454
using firebase::firestore::model::TargetId;
55+
using firebase::firestore::remote::GrpcConnection;
5556

5657
NS_ASSUME_NONNULL_BEGIN
5758

@@ -162,7 +163,7 @@ - (void)setUp {
162163
NSString *projectID = [FSTIntegrationTestCase projectID];
163164
FIRFirestoreSettings *settings = [FSTIntegrationTestCase settings];
164165
if (!settings.sslEnabled) {
165-
[GRPCCall useInsecureConnectionsForHost:settings.host];
166+
GrpcConnection::UseInsecureChannel(util::MakeString(settings.host));
166167
}
167168

168169
DatabaseId database_id(util::MakeString(projectID), DatabaseId::kDefault);

Firestore/Example/Tests/Util/FSTIntegrationTestCase.mm

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,6 @@ - (void)tearDown {
9898
[self shutdownFirestore:firestore];
9999
}
100100
} @finally {
101-
#pragma clang diagnostic push
102-
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
103-
[GRPCCall closeOpenConnections];
104-
#pragma clang diagnostic pop
105101
_firestores = nil;
106102
[super tearDown];
107103
}
@@ -165,9 +161,9 @@ + (void)setUpDefaults {
165161
"Alternatively, if you're a Googler with a Hexa preproduction environment, run "
166162
"setup_integration_tests.py to properly configure testing SSL certificates.");
167163
}
168-
[GRPCCall useTestCertsPath:certsPath testName:@"test_cert_2" forHost:defaultSettings.host];
169-
GrpcConnection::UseTestCertificate([certsPath cStringUsingEncoding:NSASCIIStringEncoding],
170-
"test_cert_2");
164+
GrpcConnection::UseTestCertificate(
165+
util::MakeString(defaultSettings.host),
166+
util::MakeString(certsPath), "test_cert_2");
171167
}
172168

173169
+ (NSString *)projectID {

Firestore/Source/Remote/FSTDatastore.h

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,19 @@
1616

1717
#import <Foundation/Foundation.h>
1818

19+
#include <memory>
1920
#include <vector>
2021

2122
#import "Firestore/Source/Core/FSTTypes.h"
2223

24+
#include "Firestore/core/src/firebase/firestore//remote/watch_stream.h"
25+
#include "Firestore/core/src/firebase/firestore//remote/write_stream.h"
2326
#include "Firestore/core/src/firebase/firestore/auth/credentials_provider.h"
2427
#include "Firestore/core/src/firebase/firestore/core/database_info.h"
2528
#include "Firestore/core/src/firebase/firestore/model/database_id.h"
2629
#include "Firestore/core/src/firebase/firestore/model/document_key.h"
30+
#include "Firestore/core/src/firebase/firestore/remote/datastore.h"
31+
#include "absl/memory/memory.h"
2732
#include "absl/strings/string_view.h"
2833

2934
@class FSTDispatchQueue;
@@ -32,9 +37,6 @@
3237
@class FSTQueryData;
3338
@class FSTSerializerBeta;
3439
@class FSTWatchChange;
35-
@class FSTWatchStream;
36-
@class FSTWriteStream;
37-
@class GRPCCall;
3840
@class GRXWriter;
3941

4042
NS_ASSUME_NONNULL_BEGIN
@@ -67,12 +69,7 @@ NS_ASSUME_NONNULL_BEGIN
6769
credentials // no passing ownership
6870
NS_DESIGNATED_INITIALIZER;
6971

70-
/**
71-
* Takes a dictionary of (HTTP) response headers and returns the set of whitelisted headers
72-
* (for logging purposes).
73-
*/
74-
+ (NSDictionary<NSString *, NSString *> *)extractWhiteListedHeaders:
75-
(NSDictionary<NSString *, NSString *> *)header;
72+
- (void)shutdown;
7673

7774
/** Converts the error to a FIRFirestoreErrorDomain error. */
7875
+ (NSError *)firestoreErrorForError:(NSError *)error;
@@ -83,11 +80,6 @@ NS_ASSUME_NONNULL_BEGIN
8380
/** Returns YES if the given error indicates the RPC associated with it may not be retried. */
8481
+ (BOOL)isPermanentWriteError:(NSError *)error;
8582

86-
/** Adds headers to the RPC including any OAuth access token if provided .*/
87-
+ (void)prepareHeadersForRPC:(GRPCCall *)rpc
88-
databaseID:(const firebase::firestore::model::DatabaseId *)databaseID
89-
token:(const absl::string_view)token;
90-
9183
/** Looks up a list of documents in datastore. */
9284
- (void)lookupDocuments:(const std::vector<firebase::firestore::model::DocumentKey> &)keys
9385
completion:(FSTVoidMaybeDocumentArrayErrorBlock)completion;
@@ -97,10 +89,12 @@ NS_ASSUME_NONNULL_BEGIN
9789
completion:(FSTVoidErrorBlock)completion;
9890

9991
/** Creates a new watch stream. */
100-
- (FSTWatchStream *)createWatchStream;
92+
- (std::shared_ptr<firebase::firestore::remote::WatchStream>)createWatchStreamWithDelegate:
93+
(id<FSTWatchStreamDelegate>)delegate;
10194

10295
/** Creates a new write stream. */
103-
- (FSTWriteStream *)createWriteStream;
96+
- (std::shared_ptr<firebase::firestore::remote::WriteStream>)createWriteStreamWithDelegate:
97+
(id<FSTWriteStreamDelegate>)delegate;
10498

10599
/** The name of the database and the backend. */
106100
// Does not own this DatabaseInfo.

0 commit comments

Comments
 (0)