RLMSyncUser_Private.hpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. ////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2016 Realm Inc.
  4. //
  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
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  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.
  16. //
  17. ////////////////////////////////////////////////////////////////////////////
  18. #import "RLMSyncUser.h"
  19. #import "RLMSyncConfiguration.h"
  20. #import "RLMSyncUtil_Private.h"
  21. #import "sync/sync_config.hpp"
  22. #import "sync/sync_user.hpp"
  23. #import "sync/impl/sync_metadata.hpp"
  24. @class RLMSyncConfiguration, RLMSyncSessionRefreshHandle;
  25. using namespace realm;
  26. typedef void(^RLMFetchedRealmCompletionBlock)(NSError * _Nullable, RLMRealm * _Nullable, BOOL * _Nonnull);
  27. NS_ASSUME_NONNULL_BEGIN
  28. class CocoaSyncUserContext : public SyncUserContext {
  29. public:
  30. void register_refresh_handle(const std::string& path, RLMSyncSessionRefreshHandle *handle);
  31. void unregister_refresh_handle(const std::string& path);
  32. void invalidate_all_handles();
  33. RLMUserErrorReportingBlock error_handler() const;
  34. void set_error_handler(RLMUserErrorReportingBlock);
  35. private:
  36. /**
  37. A map of paths to 'refresh handles'.
  38. A refresh handle is an object that encapsulates the concept of periodically
  39. refreshing the Realm's access token before it expires. Tokens are indexed by their
  40. paths (e.g. `/~/path/to/realm`).
  41. */
  42. std::unordered_map<std::string, RLMSyncSessionRefreshHandle *> m_refresh_handles;
  43. std::mutex m_mutex;
  44. /**
  45. An optional callback invoked when the authentication server reports the user as
  46. being in an expired state.
  47. */
  48. RLMUserErrorReportingBlock m_error_handler;
  49. mutable std::mutex m_error_handler_mutex;
  50. };
  51. @interface RLMSyncUser ()
  52. - (instancetype)initWithSyncUser:(std::shared_ptr<SyncUser>)user;
  53. - (NSURL *)defaultRealmURL;
  54. - (std::shared_ptr<SyncUser>)_syncUser;
  55. + (void)_setUpBindingContextFactory;
  56. @end
  57. using PermissionChangeCallback = std::function<void(std::exception_ptr)>;
  58. PermissionChangeCallback RLMWrapPermissionStatusCallback(RLMPermissionStatusBlock callback);
  59. NS_ASSUME_NONNULL_END