aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/Source/API
diff options
context:
space:
mode:
authorGravatar zxu <zxu@google.com>2018-02-27 14:04:39 -0500
committerGravatar GitHub <noreply@github.com>2018-02-27 14:04:39 -0500
commit3e7c062f3baca83fae1937bf60865be0cd18f96d (patch)
treeb9816a635f0deda9601496b0d41f6b064f99d838 /Firestore/Source/API
parent13aeb61de4fac4c0239bcf44a98a7d3aa9203963 (diff)
replacing Auth by C++ auth implementation (#802)
* lazy replacing FST(Firebase)CredentialsProvider by (Firebase)CredentialsProvider * lazy replacing FSTUser by User * adding error-code parameter to TokenListener * actually use const user& instead of pointer; also add an error util * add HashUser and pass into the unordered_map * use User in test * use c++ CredentialsProvider and subclass in test * fix unit test * use explicit capture in lambda instead of capture all by reference * cache currentUser explicitly when reset sync engineer test driver * objc object should be captured by value in lambda * replacing Auth/FSTUser by C++ auth implementation * address changes * replacing FSTGetTokenResult by C++ Token implementation * address changes * fix unintentional change in merging * patch the change in objc Auth up-stream * somehow, the lambda-version of set-user-change-listener does not work... fallback to block * address changes * fix another const& v.s. dispatch bug * fix more const& v.s. dispatch bug zxu123 committed * fix a bad sync line * address changes * address change * address change * fix upstream change from merge * fix upstream changes * Suggested fixes for cpp/port_auth (#846) * Get rid of MockDatastore factory This avoids the need to statically allocate (and leak) a credentials provider * Use absl::make_unique std::make_unique technically does not exist until C++14. * #include <utility> for std::move * Use std::future for the initial user * fix style
Diffstat (limited to 'Firestore/Source/API')
-rw-r--r--Firestore/Source/API/FIRFirestore+Internal.h7
-rw-r--r--Firestore/Source/API/FIRFirestore.mm24
2 files changed, 21 insertions, 10 deletions
diff --git a/Firestore/Source/API/FIRFirestore+Internal.h b/Firestore/Source/API/FIRFirestore+Internal.h
index 7bc419a..a52533d 100644
--- a/Firestore/Source/API/FIRFirestore+Internal.h
+++ b/Firestore/Source/API/FIRFirestore+Internal.h
@@ -16,6 +16,9 @@
#import "FIRFirestore.h"
+#include <memory>
+
+#include "Firestore/core/src/firebase/firestore/auth/credentials_provider.h"
#include "Firestore/core/src/firebase/firestore/model/database_id.h"
#include "absl/strings/string_view.h"
@@ -24,7 +27,6 @@ NS_ASSUME_NONNULL_BEGIN
@class FSTDispatchQueue;
@class FSTFirestoreClient;
@class FSTUserDataConverter;
-@protocol FSTCredentialsProvider;
@interface FIRFirestore (/* Init */)
@@ -35,7 +37,8 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)initWithProjectID:(const absl::string_view)projectID
database:(const absl::string_view)database
persistenceKey:(NSString *)persistenceKey
- credentialsProvider:(id<FSTCredentialsProvider>)credentialsProvider
+ credentialsProvider:(std::unique_ptr<firebase::firestore::auth::CredentialsProvider>)
+ credentialsProvider
workerDispatchQueue:(FSTDispatchQueue *)workerDispatchQueue
firebaseApp:(FIRApp *)app;
diff --git a/Firestore/Source/API/FIRFirestore.mm b/Firestore/Source/API/FIRFirestore.mm
index ce8f8ab..eff0605 100644
--- a/Firestore/Source/API/FIRFirestore.mm
+++ b/Firestore/Source/API/FIRFirestore.mm
@@ -16,6 +16,10 @@
#import "FIRFirestore.h"
+#include <memory>
+#include <utility>
+
+#import <FirebaseCore/FIRApp.h>
#import <FirebaseCore/FIRAppInternal.h>
#import <FirebaseCore/FIRLogger.h>
#import <FirebaseCore/FIROptions.h>
@@ -28,7 +32,6 @@
#import "Firestore/Source/API/FIRWriteBatch+Internal.h"
#import "Firestore/Source/API/FSTUserDataConverter.h"
-#import "Firestore/Source/Auth/FSTCredentialsProvider.h"
#import "Firestore/Source/Core/FSTFirestoreClient.h"
#import "Firestore/Source/Model/FSTDocumentKey.h"
#import "Firestore/Source/Model/FSTPath.h"
@@ -37,11 +40,16 @@
#import "Firestore/Source/Util/FSTLogger.h"
#import "Firestore/Source/Util/FSTUsageValidation.h"
+#include "Firestore/core/src/firebase/firestore/auth/credentials_provider.h"
+#include "Firestore/core/src/firebase/firestore/auth/firebase_credentials_provider_apple.h"
#include "Firestore/core/src/firebase/firestore/core/database_info.h"
#include "Firestore/core/src/firebase/firestore/model/database_id.h"
#include "Firestore/core/src/firebase/firestore/util/string_apple.h"
+#include "absl/memory/memory.h"
namespace util = firebase::firestore::util;
+using firebase::firestore::auth::CredentialsProvider;
+using firebase::firestore::auth::FirebaseCredentialsProvider;
using firebase::firestore::core::DatabaseInfo;
using firebase::firestore::model::DatabaseId;
@@ -52,10 +60,10 @@ extern "C" NSString *const FIRFirestoreErrorDomain = @"FIRFirestoreErrorDomain";
@interface FIRFirestore () {
/** The actual owned DatabaseId instance is allocated in FIRFirestore. */
DatabaseId _databaseID;
+ std::unique_ptr<CredentialsProvider> _credentialsProvider;
}
@property(nonatomic, strong) NSString *persistenceKey;
-@property(nonatomic, strong) id<FSTCredentialsProvider> credentialsProvider;
@property(nonatomic, strong) FSTDispatchQueue *workerDispatchQueue;
// Note that `client` is updated after initialization, but marking this readwrite would generate an
@@ -152,15 +160,15 @@ extern "C" NSString *const FIRFirestoreErrorDomain = @"FIRFirestoreErrorDomain";
FSTDispatchQueue *workerDispatchQueue = [FSTDispatchQueue
queueWith:dispatch_queue_create("com.google.firebase.firestore", DISPATCH_QUEUE_SERIAL)];
- id<FSTCredentialsProvider> credentialsProvider;
- credentialsProvider = [[FSTFirebaseCredentialsProvider alloc] initWithApp:app];
+ std::unique_ptr<CredentialsProvider> credentials_provider =
+ absl::make_unique<FirebaseCredentialsProvider>(app);
NSString *persistenceKey = app.name;
firestore = [[FIRFirestore alloc] initWithProjectID:util::MakeStringView(projectID)
database:util::MakeStringView(database)
persistenceKey:persistenceKey
- credentialsProvider:credentialsProvider
+ credentialsProvider:std::move(credentials_provider)
workerDispatchQueue:workerDispatchQueue
firebaseApp:app];
instances[key] = firestore;
@@ -173,7 +181,7 @@ extern "C" NSString *const FIRFirestoreErrorDomain = @"FIRFirestoreErrorDomain";
- (instancetype)initWithProjectID:(const absl::string_view)projectID
database:(const absl::string_view)database
persistenceKey:(NSString *)persistenceKey
- credentialsProvider:(id<FSTCredentialsProvider>)credentialsProvider
+ credentialsProvider:(std::unique_ptr<CredentialsProvider>)credentialsProvider
workerDispatchQueue:(FSTDispatchQueue *)workerDispatchQueue
firebaseApp:(FIRApp *)app {
if (self = [super init]) {
@@ -190,7 +198,7 @@ extern "C" NSString *const FIRFirestoreErrorDomain = @"FIRFirestoreErrorDomain";
_dataConverter =
[[FSTUserDataConverter alloc] initWithDatabaseID:&_databaseID preConverter:block];
_persistenceKey = persistenceKey;
- _credentialsProvider = credentialsProvider;
+ _credentialsProvider = std::move(credentialsProvider);
_workerDispatchQueue = workerDispatchQueue;
_app = app;
_settings = [[FIRFirestoreSettings alloc] init];
@@ -241,7 +249,7 @@ extern "C" NSString *const FIRFirestoreErrorDomain = @"FIRFirestoreErrorDomain";
_client = [FSTFirestoreClient clientWithDatabaseInfo:database_info
usePersistence:_settings.persistenceEnabled
- credentialsProvider:_credentialsProvider
+ credentialsProvider:_credentialsProvider.get()
userDispatchQueue:userDispatchQueue
workerDispatchQueue:_workerDispatchQueue];
}