@@ -38,8 +38,9 @@ namespace app {
3838struct AppError ;
3939class MongoClient ;
4040} // namespace app
41- class SyncSession ;
4241class SyncManager ;
42+ class SyncSession ;
43+ class SyncUserMetadata ;
4344
4445// A superclass that bindings can inherit from in order to store information
4546// upon a `SyncUser` object.
@@ -179,10 +180,6 @@ class SyncUser : public std::enable_shared_from_this<SyncUser>, public Subscriba
179180 Removed,
180181 };
181182
182- // Don't use this directly; use the `SyncManager` APIs. Public for use with `make_shared`.
183- SyncUser (std::string refresh_token, std::string id, std::string access_token, SyncUser::State state,
184- std::string device_id, SyncManager* sync_manager);
185-
186183 // Return a list of all sessions belonging to this user.
187184 std::vector<std::shared_ptr<SyncSession>> all_sessions () REQUIRES(!m_mutex);
188185
@@ -192,28 +189,6 @@ class SyncUser : public std::enable_shared_from_this<SyncUser>, public Subscriba
192189 // for testing purposes, and for bindings for consumers that are servers or tools.
193190 std::shared_ptr<SyncSession> session_for_on_disk_path (const std::string& path) REQUIRES(!m_mutex);
194191
195- // Update the user's state and refresh/access tokens atomically in a Realm transaction.
196- // If the user is transitioning between LoggedIn and LoggedOut, then the access_token and
197- // refresh token must be empty, and likewise must not be empty if transitioning between
198- // logged out and logged in.
199- // Note that this is called by the SyncManager, and should not be directly called.
200- void update_state_and_tokens (SyncUser::State state, const std::string& access_token,
201- const std::string& refresh_token) REQUIRES(!m_mutex, !m_tokens_mutex);
202-
203- // Update the user's refresh token. If the user is logged out, it will log itself back in.
204- // Note that this is called by the SyncManager, and should not be directly called.
205- void update_refresh_token (std::string&& token) REQUIRES(!m_mutex, !m_tokens_mutex);
206-
207- // Update the user's access token. If the user is logged out, it will log itself back in.
208- // Note that this is called by the SyncManager, and should not be directly called.
209- void update_access_token (std::string&& token) REQUIRES(!m_mutex, !m_tokens_mutex);
210-
211- // Update the user's profile.
212- void update_user_profile (const SyncUserProfile& profile) REQUIRES(!m_mutex);
213-
214- // Update the user's identities.
215- void update_identities (std::vector<SyncUserIdentity> identities) REQUIRES(!m_mutex);
216-
217192 // Log the user out and mark it as such. This will also close its associated Sessions.
218193 void log_out () REQUIRES(!m_mutex, !m_tokens_mutex);
219194
@@ -234,36 +209,65 @@ class SyncUser : public std::enable_shared_from_this<SyncUser>, public Subscriba
234209 }
235210
236211 std::string access_token () const REQUIRES(!m_tokens_mutex);
237-
238212 std::string refresh_token () const REQUIRES(!m_tokens_mutex);
239-
240213 std::string device_id () const REQUIRES(!m_mutex);
241-
242214 bool has_device_id () const REQUIRES(!m_mutex);
243-
244215 SyncUserProfile user_profile () const REQUIRES(!m_mutex);
245-
246216 std::vector<SyncUserIdentity> identities () const REQUIRES(!m_mutex);
217+ State state () const REQUIRES(!m_mutex);
247218
248219 // Custom user data embedded in the access token.
249220 util::Optional<bson::BsonDocument> custom_data () const REQUIRES(!m_tokens_mutex);
250221
251- State state () const REQUIRES(!m_mutex);
252- void set_state (SyncUser::State state) REQUIRES(!m_mutex);
253-
254222 std::shared_ptr<SyncUserContext> binding_context () const
255223 {
256224 return m_binding_context.load ();
257225 }
258226
227+ // Optionally set a context factory. If so, must be set before any sessions are created.
228+ static void set_binding_context_factory (SyncUserContextFactory factory);
229+
230+ std::shared_ptr<SyncManager> sync_manager () const REQUIRES(!m_mutex);
231+
232+ // / Retrieves a general-purpose service client for the Realm Cloud service
233+ // / @param service_name The name of the cluster
234+ app::MongoClient mongo_client (const std::string& service_name) REQUIRES(!m_mutex);
235+
236+ // ------------------------------------------------------------------------
237+ // All of the following are called by `SyncManager` and are public only for
238+ // testing purposes. SDKs should not call these directly in non-test code
239+ // or expose them in the public API.
240+
241+ // Don't use this directly; use the `SyncManager` APIs. Public for use with `make_shared`.
242+ SyncUser (const std::string& refresh_token, const std::string& id, const std::string& access_token,
243+ const std::string& device_id, SyncManager* sync_manager);
244+ SyncUser (const SyncUserMetadata& data, SyncManager* sync_manager);
245+
246+ void set_state (SyncUser::State state) REQUIRES(!m_mutex);
247+
248+ // Update the user's state and refresh/access tokens atomically in a Realm transaction.
249+ // If the user is transitioning between LoggedIn and LoggedOut, then the access_token and
250+ // refresh token must be empty, and likewise must not be empty if transitioning between
251+ // logged out and logged in.
252+ // Note that this is called by the SyncManager, and should not be directly called.
253+ void update_state_and_tokens (SyncUser::State state, const std::string& access_token,
254+ const std::string& refresh_token) REQUIRES(!m_mutex, !m_tokens_mutex);
255+
256+ // Update the user's access token. If the user is logged out, it will log itself back in.
257+ // Note that this is called by the SyncManager, and should not be directly called.
258+ void update_access_token (std::string&& token) REQUIRES(!m_mutex, !m_tokens_mutex);
259+
260+ // Update the user's profile and identities.
261+ void update_user_profile (std::vector<SyncUserIdentity> identities, SyncUserProfile profile) REQUIRES(!m_mutex);
262+
259263 // Register a session to this user.
260264 // A registered session will be bound at the earliest opportunity: either
261265 // immediately, or upon the user becoming Active.
262266 // Note that this is called by the SyncManager, and should not be directly called.
263267 void register_session (std::shared_ptr<SyncSession>) REQUIRES(!m_mutex);
264268
265269 // / Refreshes the custom data for this user
266- // / If update_location is true, the location metadata will be queried before the request
270+ // / If ` update_location` is true, the location metadata will be queried before the request
267271 void refresh_custom_data (bool update_location,
268272 util::UniqueFunction<void (util::Optional<app::AppError>)> completion_block)
269273 REQUIRES(!m_mutex);
@@ -274,15 +278,7 @@ class SyncUser : public std::enable_shared_from_this<SyncUser>, public Subscriba
274278 // / true.
275279 bool access_token_refresh_required () const REQUIRES(!m_mutex, !m_tokens_mutex);
276280
277- // Optionally set a context factory. If so, must be set before any sessions are created.
278- static void set_binding_context_factory (SyncUserContextFactory factory);
279-
280- std::shared_ptr<SyncManager> sync_manager () const REQUIRES(!m_mutex);
281-
282- // / Retrieves a general-purpose service client for the Realm Cloud service
283- // / @param service_name The name of the cluster
284- app::MongoClient mongo_client (const std::string& service_name) REQUIRES(!m_mutex);
285-
281+ // Hook for testing access token timeouts
286282 void set_seconds_to_adjust_time_for_testing (int seconds)
287283 {
288284 m_seconds_to_adjust_time_for_testing.store (seconds);
0 commit comments