2 * Copyright 2017 Google
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #import <Foundation/Foundation.h>
19 NS_ASSUME_NONNULL_BEGIN
21 // TODO: Remove this once Auth moves over to Core's instance registration system.
22 /** @class FIRAppAssociationRegistration
23 @brief Manages object associations as a singleton-dependent: At most one object is
24 registered for any given host/key pair, and the object shall be created on-the-fly when
27 @interface FIRAppAssociationRegistration<ObjectType> : NSObject
29 /** @fn registeredObjectWithHost:key:creationBlock:
30 @brief Retrieves the registered object with a particular host and key.
31 @param host The host object.
32 @param key The key to specify the registered object on the host.
33 @param creationBlock The block to return the object to be registered if not already.
34 The block is executed immediately before this method returns if it is executed at all.
35 It can also be executed multiple times across different method invocations if previous
36 execution of the block returns @c nil.
37 @return The registered object for the host/key pair, or @c nil if no object is registered
38 and @c creationBlock returns @c nil.
39 @remarks The method is thread-safe but non-reentrant in the sense that attempting to call this
40 method again within the @c creationBlock with the same host/key pair raises an exception.
41 The registered object is retained by the host.
43 + (nullable ObjectType)registeredObjectWithHost:(id)host
45 creationBlock:(ObjectType _Nullable (^)(void))creationBlock;