43
43
@class FSTMutationBatch;
44
44
@class FSTMutationBatchResult;
45
45
@class FSTQueryData;
46
+ @class FSTTransaction;
46
47
47
48
NS_ASSUME_NONNULL_BEGIN
48
49
@@ -112,48 +113,72 @@ class RemoteStore : public TargetMetadataProvider,
112
113
public WriteStreamCallback {
113
114
public:
114
115
RemoteStore (FSTLocalStore* local_store,
115
- Datastore* datastore,
116
+ std::shared_ptr< Datastore> datastore,
116
117
util::AsyncQueue* worker_queue,
117
118
std::function<void (model::OnlineState)> online_state_handler);
118
119
119
- // TODO(varconst): remove the getters and setters
120
-
121
- id <FSTRemoteSyncer> sync_engine () {
122
- return sync_engine_;
123
- }
124
120
void set_sync_engine (id <FSTRemoteSyncer> sync_engine) {
125
121
sync_engine_ = sync_engine;
126
122
}
127
123
128
- FSTLocalStore* local_store () {
129
- return local_store_;
130
- }
124
+ /* *
125
+ * Starts up the remote store, creating streams, restoring state from
126
+ * `FSTLocalStore`, etc.
127
+ */
128
+ void Start ();
131
129
132
- OnlineStateTracker& online_state_tracker () {
133
- return online_state_tracker_;
134
- }
130
+ /* *
131
+ * Shuts down the remote store, tearing down connections and otherwise
132
+ * cleaning up.
133
+ */
134
+ void Shutdown ();
135
135
136
- void set_is_network_enabled (bool value) {
137
- is_network_enabled_ = value;
138
- }
136
+ /* *
137
+ * Temporarily disables the network. The network can be re-enabled using
138
+ * 'EnableNetwork'.
139
+ */
140
+ void DisableNetwork ();
139
141
140
- WatchStream& watch_stream () {
141
- return *watch_stream_;
142
- }
143
- WriteStream& write_stream () {
144
- return *write_stream_;
145
- }
142
+ /* *
143
+ * Re-enables the network. Only to be called as the counterpart to
144
+ * 'DisableNetwork'.
145
+ */
146
+ void EnableNetwork ();
146
147
147
- std::vector<FSTMutationBatch*>& write_pipeline () {
148
- return write_pipeline_;
149
- }
148
+ /* *
149
+ * Tells the `RemoteStore` that the currently authenticated user has changed.
150
+ *
151
+ * In response the remote store tears down streams and clears up any tracked
152
+ * operations that should not persist across users. Restarts the streams if
153
+ * appropriate.
154
+ */
155
+ void HandleCredentialChange ();
150
156
151
157
/* * Listens to the target identified by the given `FSTQueryData`. */
152
158
void Listen (FSTQueryData* query_data);
153
159
154
160
/* * Stops listening to the target with the given target ID. */
155
161
void StopListening (model::TargetId target_id);
156
162
163
+ /* *
164
+ * Attempts to fill our write pipeline with writes from the `FSTLocalStore`.
165
+ *
166
+ * Called internally to bootstrap or refill the write pipeline and by
167
+ * `FSTSyncEngine` whenever there are new mutations to process.
168
+ *
169
+ * Starts the write stream if necessary.
170
+ */
171
+ void FillWritePipeline ();
172
+
173
+ /* *
174
+ * Queues additional writes to be sent to the write stream, sending them
175
+ * immediately if the write stream is established.
176
+ */
177
+ void AddToWritePipeline (FSTMutationBatch* batch);
178
+
179
+ /* * Returns a new transaction backed by this remote store. */
180
+ FSTTransaction* CreateTransaction ();
181
+
157
182
model::DocumentKeySet GetRemoteKeysForTarget (
158
183
model::TargetId target_id) const override;
159
184
FSTQueryData* GetQueryDataForTarget (model::TargetId target_id) const override;
@@ -171,37 +196,9 @@ class RemoteStore : public TargetMetadataProvider,
171
196
model::SnapshotVersion commit_version,
172
197
std::vector<FSTMutationResult*> mutation_results) override;
173
198
174
- // TODO(varconst): make the following methods private.
175
-
176
- bool CanUseNetwork () const ;
177
-
178
- void StartWatchStream ();
179
-
180
- /* *
181
- * Returns true if the network is enabled, the watch stream has not yet been
182
- * started and there are active watch targets.
183
- */
184
- bool ShouldStartWatchStream () const ;
185
-
186
- void CleanUpWatchStreamState ();
187
-
188
- /* *
189
- * Attempts to fill our write pipeline with writes from the `FSTLocalStore`.
190
- *
191
- * Called internally to bootstrap or refill the write pipeline and by
192
- * `FSTSyncEngine` whenever there are new mutations to process.
193
- *
194
- * Starts the write stream if necessary.
195
- */
196
- void FillWritePipeline ();
197
-
198
- /* *
199
- * Queues additional writes to be sent to the write stream, sending them
200
- * immediately if the write stream is established.
201
- */
202
- void AddToWritePipeline (FSTMutationBatch* batch);
203
-
204
199
private:
200
+ void DisableNetworkInternal ();
201
+
205
202
void SendWatchRequest (FSTQueryData* query_data);
206
203
void SendUnwatchRequest (model::TargetId target_id);
207
204
@@ -231,14 +228,29 @@ class RemoteStore : public TargetMetadataProvider,
231
228
void HandleHandshakeError (const util::Status& status);
232
229
void HandleWriteError (const util::Status& status);
233
230
231
+ bool CanUseNetwork () const ;
232
+
233
+ void StartWatchStream ();
234
+
235
+ /* *
236
+ * Returns true if the network is enabled, the watch stream has not yet been
237
+ * started and there are active watch targets.
238
+ */
239
+ bool ShouldStartWatchStream () const ;
240
+
241
+ void CleanUpWatchStreamState ();
242
+
234
243
id <FSTRemoteSyncer> sync_engine_ = nil ;
235
244
236
245
/* *
237
246
* The local store, used to fill the write pipeline with outbound mutations
238
- * and resolve existence filter mismatches. Immutable after initialization.
247
+ * and resolve existence filter mismatches.
239
248
*/
240
249
FSTLocalStore* local_store_ = nil ;
241
250
251
+ /* * The client-side proxy for interacting with the backend. */
252
+ std::shared_ptr<Datastore> datastore_;
253
+
242
254
/* *
243
255
* A mapping of watched targets that the client cares about tracking and the
244
256
* user has explicitly called a 'listen' for this target.
@@ -253,8 +265,8 @@ class RemoteStore : public TargetMetadataProvider,
253
265
OnlineStateTracker online_state_tracker_;
254
266
255
267
/* *
256
- * Set to true by `EnableNetwork` and false by `DisableNetworkInternal ` and
257
- * indicates the user-preferred network state.
268
+ * Set to true by `EnableNetwork` and false by `DisableNetwork ` and indicates
269
+ * the user-preferred network state.
258
270
*/
259
271
bool is_network_enabled_ = false ;
260
272
0 commit comments