1 ////////////////////////////////////////////////////////////////////////////
3 // Copyright 2016 Realm Inc.
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
17 ////////////////////////////////////////////////////////////////////////////
19 #import "RLMSyncUser.h"
21 #import "RLMSyncConfiguration.h"
22 #import "RLMSyncUtil_Private.h"
24 #import "sync/sync_config.hpp"
25 #import "sync/sync_user.hpp"
26 #import "sync/impl/sync_metadata.hpp"
28 @class RLMSyncConfiguration, RLMSyncSessionRefreshHandle;
30 using namespace realm;
32 typedef void(^RLMFetchedRealmCompletionBlock)(NSError * _Nullable, RLMRealm * _Nullable, BOOL * _Nonnull);
34 NS_ASSUME_NONNULL_BEGIN
36 class CocoaSyncUserContext : public SyncUserContext {
38 void register_refresh_handle(const std::string& path, RLMSyncSessionRefreshHandle *handle);
39 void unregister_refresh_handle(const std::string& path);
40 void invalidate_all_handles();
42 RLMUserErrorReportingBlock error_handler() const;
43 void set_error_handler(RLMUserErrorReportingBlock);
47 A map of paths to 'refresh handles'.
49 A refresh handle is an object that encapsulates the concept of periodically
50 refreshing the Realm's access token before it expires. Tokens are indexed by their
51 paths (e.g. `/~/path/to/realm`).
53 std::unordered_map<std::string, RLMSyncSessionRefreshHandle *> m_refresh_handles;
57 An optional callback invoked when the authentication server reports the user as
58 being in an expired state.
60 RLMUserErrorReportingBlock m_error_handler;
61 mutable std::mutex m_error_handler_mutex;
64 @interface RLMSyncUser ()
66 - (instancetype)initWithSyncUser:(std::shared_ptr<SyncUser>)user;
67 - (std::shared_ptr<SyncUser>)_syncUser;
68 - (nullable NSString *)_refreshToken;
69 + (void)_setUpBindingContextFactory;
72 using PermissionChangeCallback = std::function<void(std::exception_ptr)>;
74 PermissionChangeCallback RLMWrapPermissionStatusCallback(RLMPermissionStatusBlock callback);