Files
firebase-ios-sdk/Firestore/Source/Remote/FSTDatastore.h
T
zxu 3e7c062f3b 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
2018-02-27 14:04:39 -05:00

111 lines
4.2 KiB
Objective-C

/*
* Copyright 2017 Google
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#import <Foundation/Foundation.h>
#import "Firestore/Source/Core/FSTTypes.h"
#include "Firestore/core/src/firebase/firestore/auth/credentials_provider.h"
#include "Firestore/core/src/firebase/firestore/core/database_info.h"
#include "Firestore/core/src/firebase/firestore/model/database_id.h"
#include "absl/strings/string_view.h"
@class FSTDocumentKey;
@class FSTDispatchQueue;
@class FSTMutation;
@class FSTMutationResult;
@class FSTQueryData;
@class FSTSerializerBeta;
@class FSTSnapshotVersion;
@class FSTWatchChange;
@class FSTWatchStream;
@class FSTWriteStream;
@class GRPCCall;
@class GRXWriter;
NS_ASSUME_NONNULL_BEGIN
/**
* FSTDatastore represents a proxy for the remote server, hiding details of the RPC layer. It:
*
* - Manages connections to the server
* - Authenticates to the server
* - Manages threading and keeps higher-level code running on the worker queue
* - Serializes internal model objects to and from protocol buffers
*
* The FSTDatastore is generally not responsible for understanding the higher-level protocol
* involved in actually making changes or reading data, and aside from the connections it manages
* is otherwise stateless.
*/
@interface FSTDatastore : NSObject
/** Creates a new Datastore instance with the given database info. */
+ (instancetype)datastoreWithDatabase:(const firebase::firestore::core::DatabaseInfo *)databaseInfo
workerDispatchQueue:(FSTDispatchQueue *)workerDispatchQueue
credentials:(firebase::firestore::auth::CredentialsProvider *)
credentials; // no passing ownership
- (instancetype)init __attribute__((unavailable("Use a static constructor method.")));
- (instancetype)initWithDatabaseInfo:(const firebase::firestore::core::DatabaseInfo *)databaseInfo
workerDispatchQueue:(FSTDispatchQueue *)workerDispatchQueue
credentials:(firebase::firestore::auth::CredentialsProvider *)
credentials // no passing ownership
NS_DESIGNATED_INITIALIZER;
/**
* Takes a dictionary of (HTTP) response headers and returns the set of whitelisted headers
* (for logging purposes).
*/
+ (NSDictionary<NSString *, NSString *> *)extractWhiteListedHeaders:
(NSDictionary<NSString *, NSString *> *)header;
/** Converts the error to a FIRFirestoreErrorDomain error. */
+ (NSError *)firestoreErrorForError:(NSError *)error;
/** Returns YES if the given error is a GRPC ABORTED error. **/
+ (BOOL)isAbortedError:(NSError *)error;
/** Returns YES if the given error indicates the RPC associated with it may not be retried. */
+ (BOOL)isPermanentWriteError:(NSError *)error;
/** Adds headers to the RPC including any OAuth access token if provided .*/
+ (void)prepareHeadersForRPC:(GRPCCall *)rpc
databaseID:(const firebase::firestore::model::DatabaseId *)databaseID
token:(const absl::string_view)token;
/** Looks up a list of documents in datastore. */
- (void)lookupDocuments:(NSArray<FSTDocumentKey *> *)keys
completion:(FSTVoidMaybeDocumentArrayErrorBlock)completion;
/** Commits data to datastore. */
- (void)commitMutations:(NSArray<FSTMutation *> *)mutations
completion:(FSTVoidErrorBlock)completion;
/** Creates a new watch stream. */
- (FSTWatchStream *)createWatchStream;
/** Creates a new write stream. */
- (FSTWriteStream *)createWriteStream;
/** The name of the database and the backend. */
// Does not own this DatabaseInfo.
@property(nonatomic, assign, readonly) const firebase::firestore::core::DatabaseInfo *databaseInfo;
@end
NS_ASSUME_NONNULL_END