Skip to content

Commit 7f17739

Browse files
committed
Address review feedback
1 parent fc0421f commit 7f17739

File tree

14 files changed

+63
-64
lines changed

14 files changed

+63
-64
lines changed

Example/Core/Tests/FIRAppTest.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -778,23 +778,23 @@ - (void)testIsDefaultAppConfigured {
778778
}
779779

780780
- (void)testIllegalLibraryName {
781-
[FIRApp registerLibrary:nil withName:@"Oops>" withVersion:@"1.0.0"];
781+
[FIRApp registerLibrary:@"Oops>" withVersion:@"1.0.0"];
782782
XCTAssertTrue([[FIRApp firebaseUserAgent] isEqualToString:@""]);
783783
}
784784

785785
- (void)testIllegalLibraryVersion {
786-
[FIRApp registerLibrary:nil withName:@"LegalName" withVersion:@"1.0.0+"];
786+
[FIRApp registerLibrary:@"LegalName" withVersion:@"1.0.0+"];
787787
XCTAssertTrue([[FIRApp firebaseUserAgent] isEqualToString:@""]);
788788
}
789789

790790
- (void)testSingleLibrary {
791-
[FIRApp registerLibrary:nil withName:@"LegalName" withVersion:@"1.0.0"];
791+
[FIRApp registerLibrary:@"LegalName" withVersion:@"1.0.0"];
792792
XCTAssertTrue([[FIRApp firebaseUserAgent] containsString:@"LegalName/1.0.0"]);
793793
}
794794

795795
- (void)testMultipleLibraries {
796-
[FIRApp registerLibrary:nil withName:@"LegalName" withVersion:@"1.0.0"];
797-
[FIRApp registerLibrary:nil withName:@"LegalName2" withVersion:@"2.0.0"];
796+
[FIRApp registerLibrary:@"LegalName" withVersion:@"1.0.0"];
797+
[FIRApp registerLibrary:@"LegalName2" withVersion:@"2.0.0"];
798798
XCTAssertTrue([[FIRApp firebaseUserAgent] containsString:@"LegalName/1.0.0 LegalName2/2.0.0"]);
799799
}
800800

Firebase/Auth/Source/FIRAuth.m

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,9 @@ @implementation FIRAuth {
311311
}
312312

313313
+ (void)load {
314-
[FIRApp registerLibrary:(id<FIRLibrary>)self
315-
withName:@"auth"
314+
[FIRApp registerInternalLibrary:(Class<FIRLibrary>)self
315+
withName:@"fire-auth"
316316
withVersion:[NSString stringWithUTF8String:FirebaseAuthVersionStr]];
317-
[FIRApp registerAsConfigurable:self];
318317
}
319318

320319
+ (void)initialize {

Firebase/Core/FIRApp.m

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#import "Private/FIRAnalyticsConfiguration+Internal.h"
1818
#import "Private/FIRAppInternal.h"
1919
#import "Private/FIRBundleUtil.h"
20-
#import "Private/FIRComponentContainerInternal.h"
20+
#import "FIRComponentContainerInternal.h"
2121
#import "Private/FIRLibrary.h"
2222
#import "Private/FIRLogger.h"
2323
#import "Private/FIROptionsInternal.h"
@@ -81,7 +81,7 @@
8181
* An array of all classes that registered as `FIRCoreConfigurable` in order to receive lifecycle
8282
* events from Core.
8383
*/
84-
static NSMutableArray<Class<FIRLibrary>> *gRegisteredAsConfigurable;
84+
static NSMutableArray<Class<FIRLibrary>> *sRegisteredAsConfigurable;
8585

8686
@interface FIRApp ()
8787

@@ -431,7 +431,7 @@ + (void)sendNotificationsToSDKs:(FIRApp *)app {
431431

432432
// This is the new way of sending information to SDKs.
433433
// TODO: Do we want this on a background thread, maybe?
434-
for (Class<FIRLibrary> library in gRegisteredAsConfigurable) {
434+
for (Class<FIRLibrary> library in sRegisteredAsConfigurable) {
435435
[library configureWithApp:app];
436436
}
437437
}
@@ -471,28 +471,11 @@ + (NSError *)errorForInvalidAppID {
471471
userInfo:errorDict];
472472
}
473473

474-
+ (void)registerAsConfigurable:(Class<FIRLibrary>)klass {
475-
// This is called at +load time, keep the work to a minimum.
476-
static dispatch_once_t onceToken;
477-
dispatch_once(&onceToken, ^{
478-
gRegisteredAsConfigurable = [[NSMutableArray alloc] initWithCapacity:1];
479-
});
480-
NSAssert([(Class)klass conformsToProtocol:@protocol(FIRLibrary)] &&
481-
[(Class)klass respondsToSelector:@selector(configureWithApp:)],
482-
@"The class being registered (%@) must conform to `FIRLibrary`.", klass);
483-
[gRegisteredAsConfigurable addObject:klass];
484-
}
485-
486474
+ (BOOL)isDefaultAppConfigured {
487475
return (sDefaultApp != nil);
488476
}
489477

490-
+ (void)registerLibrary:(nullable id<FIRLibrary>)library
491-
withName:(nonnull NSString *)name
492-
withVersion:(nonnull NSString *)version {
493-
if (library) {
494-
[FIRComponentContainer registerAsComponentRegistrant:library];
495-
}
478+
+ (void)registerLibrary:(nonnull NSString *)name withVersion:(nonnull NSString *)version {
496479
// Create the set of characters which aren't allowed, only if this feature is used.
497480
NSMutableCharacterSet *allowedSet = [NSMutableCharacterSet alphanumericCharacterSet];
498481
[allowedSet addCharactersInString:@"-_."];
@@ -513,6 +496,21 @@ + (void)registerLibrary:(nullable id<FIRLibrary>)library
513496
}
514497
}
515498

499+
+ (void)registerInternalLibrary:(nonnull Class<FIRLibrary>)library
500+
withName:(nonnull NSString *)name
501+
withVersion:(nonnull NSString *)version {
502+
// This is called at +load time, keep the work to a minimum.
503+
[FIRComponentContainer registerAsComponentRegistrant:library];
504+
if ([(Class)library respondsToSelector:@selector(configureWithApp:)]) {
505+
static dispatch_once_t onceToken;
506+
dispatch_once(&onceToken, ^{
507+
sRegisteredAsConfigurable = [[NSMutableArray alloc] init];
508+
});
509+
[sRegisteredAsConfigurable addObject:library];
510+
}
511+
[self registerLibrary:name withVersion:version];
512+
}
513+
516514
+ (NSString *)firebaseUserAgent {
517515
NSMutableArray<NSString *> *libraries =
518516
[[NSMutableArray<NSString *> alloc] initWithCapacity:sLibraryVersions.count];

Firebase/Core/FIRComponentContainer.m

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,17 @@ @interface FIRComponentContainer ()
3737
@implementation FIRComponentContainer
3838

3939
// Collection of all classes that register to provide components.
40-
static NSMutableSet<Class> *gFIRComponentRegistrants;
40+
static NSMutableSet<Class> *sFIRComponentRegistrants;
4141

4242
#pragma mark - Public Registration
4343

44-
+ (void)registerAsComponentRegistrant:(id<FIRLibrary>)klass {
44+
+ (void)registerAsComponentRegistrant:(Class<FIRLibrary>)klass {
4545
static dispatch_once_t onceToken;
4646
dispatch_once(&onceToken, ^{
47-
gFIRComponentRegistrants = [[NSMutableSet<Class> alloc] init];
47+
sFIRComponentRegistrants = [[NSMutableSet<Class> alloc] init];
4848
});
4949

50-
[self registerAsComponentRegistrant:(Class)klass inSet:gFIRComponentRegistrants];
50+
[self registerAsComponentRegistrant:klass inSet:sFIRComponentRegistrants];
5151
}
5252

5353
+ (void)registerAsComponentRegistrant:(Class)klass inSet:(NSMutableSet<Class> *)allRegistrants {
@@ -59,7 +59,8 @@ + (void)registerAsComponentRegistrant:(Class)klass inSet:(NSMutableSet<Class> *)
5959
}
6060

6161
// Ensure the class given conforms to the proper protocol.
62-
if (![klass conformsToProtocol:@protocol(FIRLibrary)] ||
62+
// TODO restore protocol check after new code propagates internally
63+
if ( //![klass conformsToProtocol:@protocol(FIRLibrary)] ||
6364
![klass respondsToSelector:@selector(componentsToRegister)]) {
6465
[NSException raise:NSInvalidArgumentException
6566
format:
@@ -74,7 +75,7 @@ + (void)registerAsComponentRegistrant:(Class)klass inSet:(NSMutableSet<Class> *)
7475
#pragma mark - Internal Initialization
7576

7677
- (instancetype)initWithApp:(FIRApp *)app {
77-
return [self initWithApp:app registrants:gFIRComponentRegistrants];
78+
return [self initWithApp:app registrants:sFIRComponentRegistrants];
7879
}
7980

8081
- (instancetype)initWithApp:(FIRApp *)app registrants:(NSMutableSet<Class> *)allRegistrants {

Firebase/Core/FIRComponentType.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#import "Private/FIRComponentType.h"
1818

19-
#import "Private/FIRComponentContainerInternal.h"
19+
#import "FIRComponentContainerInternal.h"
2020

2121
@implementation FIRComponentType
2222

Firebase/Core/FIROptions.m

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ + (void)initialize {
114114
NSRange minor = NSMakeRange(1, 2);
115115
NSRange patch = NSMakeRange(3, 2);
116116
[FIRApp
117-
registerLibrary:nil
118-
withName:@"fire-ios"
117+
registerLibrary:@"fire-ios"
119118
withVersion:[NSString stringWithFormat:@"%@.%d.%d",
120119
[kFIRLibraryVersionID substringWithRange:major],
121120
[[kFIRLibraryVersionID substringWithRange:minor]
@@ -126,10 +125,10 @@ + (void)initialize {
126125
NSString *xcodeVersion = info[@"DTXcodeBuild"];
127126
NSString *sdkVersion = info[@"DTSDKBuild"];
128127
if (xcodeVersion) {
129-
[FIRApp registerLibrary:nil withName:@"xcode" withVersion:xcodeVersion];
128+
[FIRApp registerLibrary:@"xcode" withVersion:xcodeVersion];
130129
}
131130
if (sdkVersion) {
132-
[FIRApp registerLibrary:nil withName:@"apple-sdk" withVersion:sdkVersion];
131+
[FIRApp registerLibrary:@"apple-sdk" withVersion:sdkVersion];
133132
}
134133
}
135134

Firebase/Core/Private/FIRAppInternal.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -164,23 +164,25 @@ typedef NSString *_Nullable (^FIRAppGetUIDImplementation)(void);
164164
+ (BOOL)isDefaultAppConfigured;
165165

166166
/**
167-
* Register a class that conforms to `FIRCoreConfigurable`. Each SDK should have one class that
168-
* registers in order to provide critical information for interoperability and lifecycle events.
169-
* TODO(wilsonryan): Write more documentation.
167+
* Registers a given third-party library with the given version number to be reported for
168+
* analytics.
169+
*
170+
* @param name Name of the library.
171+
* @param version Version of the library.
170172
*/
171-
+ (void)registerAsConfigurable:(Class<FIRLibrary>)klass;
173+
+ (void)registerLibrary:(nonnull NSString *)name withVersion:(nonnull NSString *)version;
172174

173175
/**
174-
* Registers a given third-party library with the given version number to be reported for
176+
* Registers a given internal library with the given version number to be reported for
175177
* analytics.
176178
*
177179
* @param library Optional parameter for component registration.
178-
* @param name Name of the library. It's typically the CocoaPod name.
180+
* @param name Name of the library.
179181
* @param version Version of the library.
180182
*/
181-
+ (void)registerLibrary:(nullable id<FIRLibrary>)library
182-
withName:(nonnull NSString *)name
183-
withVersion:(nonnull NSString *)version;
183+
+ (void)registerInternalLibrary:(nonnull Class<FIRLibrary>)library
184+
withName:(nonnull NSString *)name
185+
withVersion:(nonnull NSString *)version;
184186

185187
/**
186188
* A concatenated string representing all the third-party libraries and version numbers.

Firebase/Core/Private/FIRComponentContainer.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ NS_SWIFT_NAME(FirebaseComponentContainer)
3939
/// Unavailable. Use the `container` property on `FIRApp`.
4040
- (instancetype)init NS_UNAVAILABLE;
4141

42-
/// Register a class to provide components for the interoperability system. The class should conform
43-
/// to `FIRComponentRegistrant` and provide an array of `FIRComponent` objects.
44-
+ (void)registerAsComponentRegistrant:(id<FIRLibrary>)klass;
45-
4642
@end
4743

4844
NS_ASSUME_NONNULL_END

Firebase/Core/Private/FIRComponentContainerInternal.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ NS_ASSUME_NONNULL_BEGIN
3434
/// Remove all of the cached instances stored and allow them to clean up after themselves.
3535
- (void)removeAllCachedInstances;
3636

37+
/// Register a class to provide components for the interoperability system. The class should conform
38+
/// to `FIRComponentRegistrant` and provide an array of `FIRComponent` objects.
39+
+ (void)registerAsComponentRegistrant:(Class<FIRLibrary>)klass;
40+
3741
@end
3842

3943
NS_ASSUME_NONNULL_END

Firebase/Core/Private/FIRLibrary.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,13 @@ NS_ASSUME_NONNULL_BEGIN
2828
NS_SWIFT_NAME(Library)
2929
@protocol FIRLibrary
3030

31-
//@optional
3231
/// Returns one or more FIRComponents that will be registered in
3332
/// FIRApp and participate in dependency resolution and injection.
3433
+ (NSArray<FIRComponent *> *)componentsToRegister;
3534

3635
@optional
37-
/// Configure the SDK if needed ahead of time. This method is called when the developer calls
38-
/// `FirebaseApp.configure()`.
36+
/// Implement this method if the library needs notifications for lifecycle events. This method is
37+
/// called when the developer calls `FirebaseApp.configure()`.
3938
+ (void)configureWithApp:(FIRApp *)app;
4039

4140
@end

Firebase/Database/Api/FIRDatabaseComponent.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ - (instancetype)initWithApp:(FIRApp *)app {
5555
#pragma mark - Lifecycle
5656

5757
+ (void)load {
58-
[FIRApp registerLibrary:(id<FIRLibrary>)self withName:@"db" withVersion:[FIRDatabase sdkVersion]];
58+
[FIRApp registerInternalLibrary:(Class<FIRLibrary>)self
59+
withName:@"fire-db"
60+
withVersion:[FIRDatabase sdkVersion]];
5961
}
6062

6163
#pragma mark - FIRComponentRegistrant

Firebase/DynamicLinks/FIRDynamicLinks.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ @implementation FIRDynamicLinks {
115115
#ifdef FIRDynamicLinks3P
116116

117117
+ (void)load {
118-
[FIRApp registerLibrary:(id<FIRLibrary>)self withName:@"dynlinks" withVersion:kFIRDLVersion];
118+
[FIRApp registerInternalLibrary:self withName:@"fire-dynlinks" withVersion:kFIRDLVersion];
119119
}
120120

121121
+ (nonnull NSArray<FIRComponent *> *)componentsToRegister {

Firebase/Messaging/FIRMessaging.m

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,9 @@ - (void)dealloc {
212212
#pragma mark - Config
213213

214214
+ (void)load {
215-
[FIRApp registerLibrary:(id<FIRLibrary>)self
216-
withName:@"msg"
215+
[FIRApp registerInternalLibrary:(Class<FIRLibrary>)self
216+
withName:@"fire-msg"
217217
withVersion:FIRMessagingCurrentLibraryVersion()];
218-
[FIRApp registerAsConfigurable:self];
219218
}
220219

221220
+ (nonnull NSArray<FIRComponent *> *)componentsToRegister {

Firebase/Storage/FIRStorageComponent.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ - (instancetype)initWithApp:(FIRApp *)app {
5252
#pragma mark - Lifecycle
5353

5454
+ (void)load {
55-
[FIRApp registerLibrary:(id<FIRLibrary>)self
56-
withName:@"stor"
57-
withVersion:[NSString stringWithUTF8String:FIRStorageVersionString]];
55+
[FIRApp registerInternalLibrary:(Class<FIRLibrary>)self
56+
withName:@"fire-storage"
57+
withVersion:[NSString stringWithUTF8String:FIRStorageVersionString]];
5858
}
5959

6060
#pragma mark - FIRComponentRegistrant

0 commit comments

Comments
 (0)