diff options
Diffstat (limited to 'Firebase/Core/Private')
-rw-r--r-- | Firebase/Core/Private/FIRAppAssociationRegistration.h | 1 | ||||
-rw-r--r-- | Firebase/Core/Private/FIRAppInternal.h | 20 | ||||
-rw-r--r-- | Firebase/Core/Private/FIRComponent.h | 91 | ||||
-rw-r--r-- | Firebase/Core/Private/FIRComponentContainer.h | 47 | ||||
-rw-r--r-- | Firebase/Core/Private/FIRComponentContainerInternal.h | 39 | ||||
-rw-r--r-- | Firebase/Core/Private/FIRComponentRegistrant.h | 38 | ||||
-rw-r--r-- | Firebase/Core/Private/FIRComponentType.h | 35 | ||||
-rw-r--r-- | Firebase/Core/Private/FIRCoreConfigurable.h | 38 | ||||
-rw-r--r-- | Firebase/Core/Private/FIRDependency.h | 45 |
9 files changed, 354 insertions, 0 deletions
diff --git a/Firebase/Core/Private/FIRAppAssociationRegistration.h b/Firebase/Core/Private/FIRAppAssociationRegistration.h index a1f8c41..007e2bf 100644 --- a/Firebase/Core/Private/FIRAppAssociationRegistration.h +++ b/Firebase/Core/Private/FIRAppAssociationRegistration.h @@ -18,6 +18,7 @@ NS_ASSUME_NONNULL_BEGIN +// TODO: Remove this once Auth moves over to Core's instance registration system. /** @class FIRAppAssociationRegistration @brief Manages object associations as a singleton-dependent: At most one object is registered for any given host/key pair, and the object shall be created on-the-fly when diff --git a/Firebase/Core/Private/FIRAppInternal.h b/Firebase/Core/Private/FIRAppInternal.h index 66979eb..45de2ba 100644 --- a/Firebase/Core/Private/FIRAppInternal.h +++ b/Firebase/Core/Private/FIRAppInternal.h @@ -17,6 +17,9 @@ #import "FIRApp.h" #import "FIRErrors.h" +@class FIRComponentContainer; +@protocol FIRCoreConfigurable; + /** * The internal interface to FIRApp. This is meant for first-party integrators, who need to receive * FIRApp notifications, log info about the success or failure of their configuration, and access @@ -126,6 +129,11 @@ typedef NSString *_Nullable (^FIRAppGetUIDImplementation)(void); @interface FIRApp () +/** + * A flag indicating if this is the default app. + */ +@property(nonatomic, readonly) BOOL isDefaultApp; + /** @property getTokenImplementation @brief Gets or sets the block to use for the implementation of @c getTokenForcingRefresh:withCallback: @@ -137,6 +145,11 @@ typedef NSString *_Nullable (^FIRAppGetUIDImplementation)(void); */ @property(nonatomic, copy) FIRAppGetUIDImplementation getUIDImplementation; +/* + * The container of interop SDKs for this app. + */ +@property(nonatomic) FIRComponentContainer *container; + /** * Creates an error for failing to configure a subspec service. This method is called by each * FIRApp notification listener. @@ -151,6 +164,13 @@ typedef NSString *_Nullable (^FIRAppGetUIDImplementation)(void); + (BOOL)isDefaultAppConfigured; /** + * Register a class that conforms to `FIRCoreConfigurable`. Each SDK should have one class that + * registers in order to provide critical information for interoperability and lifecycle events. + * TODO(wilsonryan): Write more documentation. + */ ++ (void)registerAsConfigurable:(Class<FIRCoreConfigurable>)klass; + +/** * Registers a given third-party library with the given version number to be reported for * analyitcs. * diff --git a/Firebase/Core/Private/FIRComponent.h b/Firebase/Core/Private/FIRComponent.h new file mode 100644 index 0000000..cb51ee7 --- /dev/null +++ b/Firebase/Core/Private/FIRComponent.h @@ -0,0 +1,91 @@ +/* + * Copyright 2018 Google + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import <Foundation/Foundation.h> + +@class FIRApp; +@class FIRComponentContainer; + +NS_ASSUME_NONNULL_BEGIN + +/// Provides a system to clean up cached instances returned from the component system. +NS_SWIFT_NAME(ComponentLifecycleMaintainer) +@protocol FIRComponentLifecycleMaintainer +/// The associated app will be deleted, clean up any resources as they are about to be deallocated. +- (void)appWillBeDeleted:(FIRApp *)app; +@end + +typedef _Nullable id (^FIRComponentCreationBlock)(FIRComponentContainer *container, + BOOL *isCacheable) + NS_SWIFT_NAME(ComponentCreationBlock); + +@class FIRDependency; + +/// Describes the timing of instantiation. Note: new components should default to lazy unless there +/// is a strong reason to be eager. +typedef NS_ENUM(NSInteger, FIRInstantiationTiming) { + FIRInstantiationTimingLazy, + FIRInstantiationTimingAlwaysEager, + FIRInstantiationTimingEagerInDefaultApp +} NS_SWIFT_NAME(InstantiationTiming); + +/// A component that can be used from other Firebase SDKs. +NS_SWIFT_NAME(Component) +@interface FIRComponent : NSObject + +/// The protocol describing functionality provided from the Component. +@property(nonatomic, strong, readonly) Protocol *protocol; + +/// The timing of instantiation. +@property(nonatomic, readonly) FIRInstantiationTiming instantiationTiming; + +/// An array of dependencies for the component. +@property(nonatomic, copy, readonly) NSArray<FIRDependency *> *dependencies; + +/// A block to instantiate an instance of the component with the appropriate dependencies. +@property(nonatomic, copy, readonly) FIRComponentCreationBlock creationBlock; + +// There's an issue with long NS_SWIFT_NAMES that causes compilation to fail, disable clang-format +// for the next two methods. +// clang-format off + +/// Creates a component with no dependencies that will be lazily initialized. ++ (instancetype)componentWithProtocol:(Protocol *)protocol + creationBlock:(FIRComponentCreationBlock)creationBlock +NS_SWIFT_NAME(init(_:creationBlock:)); + +/// Creates a component to be registered with the component container. +/// +/// @param protocol - The protocol describing functionality provided by the component. +/// @param instantiationTiming - When the component should be initialized. Use .lazy unless there's +/// a good reason to be instantiated earlier. +/// @param dependencies - Any dependencies the `implementingClass` has, optional or required. +/// @param creationBlock - A block to instantiate the component with a container, and if +/// @return A component that can be registered with the component container. ++ (instancetype)componentWithProtocol:(Protocol *)protocol + instantiationTiming:(FIRInstantiationTiming)instantiationTiming + dependencies:(NSArray<FIRDependency *> *)dependencies + creationBlock:(FIRComponentCreationBlock)creationBlock +NS_SWIFT_NAME(init(_:instantiationTiming:dependencies:creationBlock:)); + +// clang-format on + +/// Unavailable. +- (instancetype)init NS_UNAVAILABLE; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Firebase/Core/Private/FIRComponentContainer.h b/Firebase/Core/Private/FIRComponentContainer.h new file mode 100644 index 0000000..10e2255 --- /dev/null +++ b/Firebase/Core/Private/FIRComponentContainer.h @@ -0,0 +1,47 @@ +/* + * Copyright 2018 Google + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#import <Foundation/Foundation.h> + +#import "FIRComponentType.h" + +NS_ASSUME_NONNULL_BEGIN + +/// A type-safe macro to retrieve a component from a container. This should be used to retrieve +/// components instead of using the container directly. +#define FIR_COMPONENT(type, container) \ + [FIRComponentType<id<type>> instanceForProtocol:@protocol(type) inContainer:container] + +@class FIRApp; + +/// A container that holds different components that are registered via the +/// `registerAsComponentRegistrant:` call. These classes should conform to `FIRComponentRegistrant` +/// in order to properly register components for Core. +NS_SWIFT_NAME(FirebaseComponentContainer) +@interface FIRComponentContainer : NSObject + +/// A weak reference to the app that an instance of the container belongs to. +@property(nonatomic, weak, readonly) FIRApp *app; + +/// Unavailable. Use the `container` property on `FIRApp`. +- (instancetype)init NS_UNAVAILABLE; + +/// Register a class to provide components for the interoperability system. The class should conform +/// to `FIRComponentRegistrant` and provide an array of `FIRComponent` objects. ++ (void)registerAsComponentRegistrant:(Class)klass; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Firebase/Core/Private/FIRComponentContainerInternal.h b/Firebase/Core/Private/FIRComponentContainerInternal.h new file mode 100644 index 0000000..bb73e7b --- /dev/null +++ b/Firebase/Core/Private/FIRComponentContainerInternal.h @@ -0,0 +1,39 @@ +/* + * Copyright 2018 Google + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#import <Foundation/Foundation.h> + +#import "FIRComponent.h" +#import "FIRComponentContainer.h" + +@class FIRApp; + +NS_ASSUME_NONNULL_BEGIN + +@interface FIRComponentContainer (Private) + +/// Initializes a contain for a given app. This should only be called by the app itself. +- (instancetype)initWithApp:(FIRApp *)app; + +/// Retrieves an instance that conforms to the specified protocol. This will return `nil` if the +/// protocol wasn't registered, or if the instance couldn't instantiate for the provided app. +- (nullable id)instanceForProtocol:(Protocol *)protocol NS_SWIFT_NAME(instance(for:)); + +/// Remove all of the cached instances stored and allow them to clean up after themselves. +- (void)removeAllCachedInstances; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Firebase/Core/Private/FIRComponentRegistrant.h b/Firebase/Core/Private/FIRComponentRegistrant.h new file mode 100644 index 0000000..ad2cad2 --- /dev/null +++ b/Firebase/Core/Private/FIRComponentRegistrant.h @@ -0,0 +1,38 @@ +/* + * Copyright 2018 Google + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FIRComponentRegistrant_h +#define FIRComponentRegistrant_h + +#import <Foundation/Foundation.h> + +@class FIRComponent; + +NS_ASSUME_NONNULL_BEGIN + +/// Describes functionality for SDKs registering components in the `FIRComponentContainer`. +NS_SWIFT_NAME(ComponentRegistrant) +@protocol FIRComponentRegistrant + +/// Returns one or more FIRComponents that will be registered in +/// FIRApp and participate in dependency resolution and injection. ++ (NSArray<FIRComponent *> *)componentsToRegister; + +@end + +NS_ASSUME_NONNULL_END + +#endif /* FIRComponentRegistrant_h */ diff --git a/Firebase/Core/Private/FIRComponentType.h b/Firebase/Core/Private/FIRComponentType.h new file mode 100644 index 0000000..3254835 --- /dev/null +++ b/Firebase/Core/Private/FIRComponentType.h @@ -0,0 +1,35 @@ +/* + * Copyright 2018 Google + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import <Foundation/Foundation.h> + +@class FIRComponentContainer; + +NS_ASSUME_NONNULL_BEGIN + +/// Do not use directly. A placeholder type in order to provide a macro that will warn users of +/// mis-matched protocols. +NS_SWIFT_NAME(ComponentType) +@interface FIRComponentType <__covariant T> : NSObject + +/// Do not use directly. A factory method to retrieve an instance that provides a specific +/// functionality. ++ (T)instanceForProtocol:(Protocol *)protocol + inContainer:(FIRComponentContainer *)container; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Firebase/Core/Private/FIRCoreConfigurable.h b/Firebase/Core/Private/FIRCoreConfigurable.h new file mode 100644 index 0000000..6c2b077 --- /dev/null +++ b/Firebase/Core/Private/FIRCoreConfigurable.h @@ -0,0 +1,38 @@ +/* + * Copyright 2018 Google + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FIRCoreConfigurable_h +#define FIRCoreConfigurable_h + +#import <Foundation/Foundation.h> + +@class FIRApp; + +NS_ASSUME_NONNULL_BEGIN + +/// Provides an interface to set up an SDK once a `FIRApp` is configured. +NS_SWIFT_NAME(CoreConfigurable) +@protocol FIRCoreConfigurable + +/// Configure the SDK if needed ahead of time. This method is called when the developer calls +/// `FirebaseApp.configure()`. ++ (void)configureWithApp:(FIRApp *)app; + +@end + +NS_ASSUME_NONNULL_END + +#endif /* FIRCoreConfigurable_h */ diff --git a/Firebase/Core/Private/FIRDependency.h b/Firebase/Core/Private/FIRDependency.h new file mode 100644 index 0000000..46e9b7e --- /dev/null +++ b/Firebase/Core/Private/FIRDependency.h @@ -0,0 +1,45 @@ +/* + * Copyright 2018 Google + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import <Foundation/Foundation.h> + +NS_ASSUME_NONNULL_BEGIN + +/// A dependency on a specific protocol's functionality. +NS_SWIFT_NAME(Dependency) +@interface FIRDependency : NSObject + +/// The protocol describing functionality being depended on. +@property(nonatomic, strong, readonly) Protocol *protocol; + +/// A flag to specify if the dependency is required or not. +@property(nonatomic, readonly) BOOL isRequired; + +/// Initializes a dependency that is required. Calls `initWithProtocol:isRequired` with `YES` for +/// the required parameter. +/// Creates a required dependency on the specified protocol's functionality. ++ (instancetype)dependencyWithProtocol:(Protocol *)protocol; + +/// Creates a dependency on the specified protocol's functionality and specify if it's required for +/// the class's functionality. ++ (instancetype)dependencyWithProtocol:(Protocol *)protocol isRequired:(BOOL)required; + +/// Use `dependencyWithProtocol:isRequired:` instead. +- (instancetype)init NS_UNAVAILABLE; + +@end + +NS_ASSUME_NONNULL_END |