FIRAppAssociationRegistration.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <Foundation/Foundation.h>
  17. NS_ASSUME_NONNULL_BEGIN
  18. // TODO: Remove this once Auth moves over to Core's instance registration system.
  19. /** @class FIRAppAssociationRegistration
  20. @brief Manages object associations as a singleton-dependent: At most one object is
  21. registered for any given host/key pair, and the object shall be created on-the-fly when
  22. asked for.
  23. */
  24. @interface FIRAppAssociationRegistration<ObjectType> : NSObject
  25. /** @fn registeredObjectWithHost:key:creationBlock:
  26. @brief Retrieves the registered object with a particular host and key.
  27. @param host The host object.
  28. @param key The key to specify the registered object on the host.
  29. @param creationBlock The block to return the object to be registered if not already.
  30. The block is executed immediately before this method returns if it is executed at all.
  31. It can also be executed multiple times across different method invocations if previous
  32. execution of the block returns @c nil.
  33. @return The registered object for the host/key pair, or @c nil if no object is registered
  34. and @c creationBlock returns @c nil.
  35. @remarks The method is thread-safe but non-reentrant in the sense that attempting to call this
  36. method again within the @c creationBlock with the same host/key pair raises an exception.
  37. The registered object is retained by the host.
  38. */
  39. + (nullable ObjectType)registeredObjectWithHost:(id)host
  40. key:(NSString *)key
  41. creationBlock:(ObjectType _Nullable (^)(void))creationBlock;
  42. @end
  43. NS_ASSUME_NONNULL_END