|
16 | 16 |
|
17 | 17 | #include "Firestore/core/src/firebase/firestore/api/firestore.h"
|
18 | 18 |
|
19 |
| -#import "FIRFirestoreSettings.h" |
20 | 19 | #import "Firestore/Source/API/FIRCollectionReference+Internal.h"
|
21 | 20 | #import "Firestore/Source/API/FIRDocumentReference+Internal.h"
|
22 | 21 | #import "Firestore/Source/API/FIRFirestore+Internal.h"
|
|
27 | 26 | #import "Firestore/Source/Core/FSTQuery.h"
|
28 | 27 |
|
29 | 28 | #include "Firestore/core/src/firebase/firestore/api/document_reference.h"
|
| 29 | +#include "Firestore/core/src/firebase/firestore/api/settings.h" |
30 | 30 | #include "Firestore/core/src/firebase/firestore/auth/firebase_credentials_provider_apple.h"
|
31 | 31 | #include "Firestore/core/src/firebase/firestore/core/transaction.h"
|
32 | 32 | #include "Firestore/core/src/firebase/firestore/model/document_key.h"
|
|
61 | 61 | persistence_key_{std::move(persistence_key)},
|
62 | 62 | worker_queue_{std::move(worker_queue)},
|
63 | 63 | extension_{extension} {
|
64 |
| - settings_ = [[FIRFirestoreSettings alloc] init]; |
65 | 64 | }
|
66 | 65 |
|
67 | 66 | AsyncQueue* Firestore::worker_queue() {
|
68 | 67 | return [client_ workerQueue];
|
69 | 68 | }
|
70 | 69 |
|
71 |
| -FIRFirestoreSettings* Firestore::settings() const { |
| 70 | +const Settings& Firestore::settings() const { |
72 | 71 | std::lock_guard<std::mutex> lock{mutex_};
|
73 |
| - // Disallow mutation of our internal settings |
74 |
| - return [settings_ copy]; |
| 72 | + return settings_; |
75 | 73 | }
|
76 | 74 |
|
77 |
| -void Firestore::set_settings(FIRFirestoreSettings* settings) { |
| 75 | +void Firestore::set_settings(const Settings& settings) { |
78 | 76 | std::lock_guard<std::mutex> lock{mutex_};
|
79 |
| - // As a special exception, don't throw if the same settings are passed |
80 |
| - // repeatedly. This should make it more friendly to create a Firestore |
81 |
| - // instance. |
82 |
| - if (client_ && ![settings_ isEqual:settings]) { |
| 77 | + if (client_) { |
83 | 78 | HARD_FAIL(
|
84 | 79 | "Firestore instance has already been started and its settings can "
|
85 | 80 | "no longer be changed. You can only set settings before calling any "
|
86 | 81 | "other methods on a Firestore instance.");
|
87 | 82 | }
|
88 |
| - settings_ = [settings copy]; |
| 83 | + settings_ = settings; |
| 84 | +} |
| 85 | + |
| 86 | +void Firestore::set_user_executor( |
| 87 | + std::unique_ptr<util::Executor> user_executor) { |
| 88 | + std::lock_guard<std::mutex> lock{mutex_}; |
| 89 | + HARD_ASSERT(!client_ && user_executor, |
| 90 | + "set_user_executor() must be called with a valid executor, " |
| 91 | + "before the client is initialized."); |
| 92 | + user_executor_ = std::move(user_executor); |
89 | 93 | }
|
90 | 94 |
|
91 | 95 | FIRCollectionReference* Firestore::GetCollection(
|
|
175 | 179 | std::lock_guard<std::mutex> lock{mutex_};
|
176 | 180 |
|
177 | 181 | if (!client_) {
|
178 |
| - // These values are validated elsewhere; this is just double-checking: |
179 |
| - HARD_ASSERT(settings_.host, "FirestoreSettings.host cannot be nil."); |
180 |
| - HARD_ASSERT(settings_.dispatchQueue, |
181 |
| - "FirestoreSettings.dispatchQueue cannot be nil."); |
182 |
| - |
183 |
| - DatabaseInfo database_info(database_id_, persistence_key_, |
184 |
| - util::MakeString(settings_.host), |
185 |
| - settings_.sslEnabled); |
186 |
| - |
187 |
| - std::unique_ptr<Executor> user_executor = |
188 |
| - absl::make_unique<ExecutorLibdispatch>(settings_.dispatchQueue); |
| 182 | + DatabaseInfo database_info(database_id_, persistence_key_, settings_.host(), |
| 183 | + settings_.ssl_enabled()); |
189 | 184 |
|
190 | 185 | HARD_ASSERT(worker_queue_, "Expected non-null worker queue");
|
191 | 186 | client_ =
|
192 | 187 | [FSTFirestoreClient clientWithDatabaseInfo:database_info
|
193 | 188 | settings:settings_
|
194 | 189 | credentialsProvider:credentials_provider_.get()
|
195 |
| - userExecutor:std::move(user_executor) |
| 190 | + userExecutor:std::move(user_executor_) |
196 | 191 | workerQueue:std::move(worker_queue_)];
|
197 | 192 | }
|
198 | 193 | }
|
|
0 commit comments