Clean up and correct codeless indexer type

Summary:
* Correct dependency attributes
* Rename `store` to `dataStore`
* Add missing dependency mutators
* Use properties instead of cvars
* Correct configuration method name in Swift

Reviewed By: joesus

Differential Revision: D32583062

fbshipit-source-id: 93ad40a5665295197f36bcdacd70beba7a54b615
This commit is contained in:
Sam Odom
2021-11-22 16:38:39 -08:00
committed by Facebook GitHub Bot
parent 26bd7d920f
commit 34cf89b3f6
6 changed files with 103 additions and 65 deletions

View File

@@ -26,13 +26,16 @@ NS_ASSUME_NONNULL_BEGIN
@interface FBSDKCodelessIndexer (Internal) <FBSDKCodelessIndexing>
// UNCRUSTIFY_FORMAT_OFF
+ (void)configureWithGraphRequestFactory:(id<FBSDKGraphRequestFactory>)graphRequestFactory
serverConfigurationProvider:(id<FBSDKServerConfigurationProviding>)serverConfigurationProvider
store:(id<FBSDKDataPersisting>)store
dataStore:(id<FBSDKDataPersisting>)dataStore
graphRequestConnectionFactory:(id<FBSDKGraphRequestConnectionFactory>)graphRequestConnectionFactory
swizzler:(Class<FBSDKSwizzling>)swizzler
settings:(id<FBSDKSettings>)settings
advertiserIDProvider:(id<FBSDKAdvertiserIDProviding>)advertisingIDProvider;
advertiserIDProvider:(id<FBSDKAdvertiserIDProviding>)advertisingIDProvider
NS_SWIFT_NAME(configure(graphRequestFactory:serverConfigurationProvider:dataStore:graphRequestConnectionFactory:swizzler:settings:advertiserIDProvider:));
// UNCRUSTIFY_FORMAT_ON
@end

View File

@@ -40,13 +40,13 @@
@interface FBSDKCodelessIndexer ()
@property (class, nullable, nonatomic, readonly) id<FBSDKGraphRequestFactory> graphRequestFactory;
@property (class, nullable, nonatomic, readonly) id<FBSDKServerConfigurationProviding> serverConfigurationProvider;
@property (class, nullable, nonatomic, readonly) id<FBSDKDataPersisting> store;
@property (class, nullable, nonatomic, readonly, copy) id<FBSDKGraphRequestConnectionFactory> graphRequestConnectionFactory;
@property (class, nullable, nonatomic, readonly, copy) Class<FBSDKSwizzling> swizzler;
@property (class, nullable, nonatomic, readonly) id<FBSDKSettings> settings;
@property (class, nullable, nonatomic, readonly) id<FBSDKAdvertiserIDProviding> advertiserIDProvider;
@property (class, nullable, nonatomic) id<FBSDKGraphRequestFactory> graphRequestFactory;
@property (class, nullable, nonatomic) id<FBSDKServerConfigurationProviding> serverConfigurationProvider;
@property (class, nullable, nonatomic) id<FBSDKDataPersisting> dataStore;
@property (class, nullable, nonatomic) id<FBSDKGraphRequestConnectionFactory> graphRequestConnectionFactory;
@property (class, nullable, nonatomic) Class<FBSDKSwizzling> swizzler;
@property (class, nullable, nonatomic) id<FBSDKSettings> settings;
@property (class, nullable, nonatomic) id<FBSDKAdvertiserIDProviding> advertiserIDProvider;
@end
@@ -65,7 +65,7 @@ static NSTimer *_appIndexingTimer;
static NSString *_lastTreeHash;
static id<FBSDKGraphRequestFactory> _graphRequestFactory;
static id<FBSDKServerConfigurationProviding> _serverConfigurationProvider;
static id<FBSDKDataPersisting> _store;
static id<FBSDKDataPersisting> _dataStore;
static id<FBSDKGraphRequestConnectionFactory> _graphRequestConnectionFactory;
static Class<FBSDKSwizzling> _swizzler;
static id<FBSDKSettings> _settings;
@@ -74,58 +74,93 @@ static id<FBSDKSettings> _settings;
+ (void)configureWithGraphRequestFactory:(id<FBSDKGraphRequestFactory>)graphRequestFactory
serverConfigurationProvider:(id<FBSDKServerConfigurationProviding>)serverConfigurationProvider
store:(id<FBSDKDataPersisting>)store
dataStore:(id<FBSDKDataPersisting>)dataStore
graphRequestConnectionFactory:(id<FBSDKGraphRequestConnectionFactory>)graphRequestConnectionFactory
swizzler:(Class<FBSDKSwizzling>)swizzler
settings:(id<FBSDKSettings>)settings
advertiserIDProvider:(id<FBSDKAdvertiserIDProviding>)advertiserIDProvider
{
if (self == FBSDKCodelessIndexer.class) {
_graphRequestFactory = graphRequestFactory;
_serverConfigurationProvider = serverConfigurationProvider;
_store = store;
_graphRequestConnectionFactory = graphRequestConnectionFactory;
_swizzler = swizzler;
_settings = settings;
_advertiserIDProvider = advertiserIDProvider;
self.graphRequestFactory = graphRequestFactory;
self.serverConfigurationProvider = serverConfigurationProvider;
self.dataStore = dataStore;
self.graphRequestConnectionFactory = graphRequestConnectionFactory;
self.swizzler = swizzler;
self.settings = settings;
self.advertiserIDProvider = advertiserIDProvider;
}
}
+ (id<FBSDKGraphRequestFactory>)graphRequestFactory
+ (nullable id<FBSDKGraphRequestFactory>)graphRequestFactory
{
return _graphRequestFactory;
}
+ (id<FBSDKServerConfigurationProviding>)serverConfigurationProvider
+ (void)setGraphRequestFactory:(nullable id<FBSDKGraphRequestFactory>)graphRequestFactory
{
_graphRequestFactory = graphRequestFactory;
}
+ (nullable id<FBSDKServerConfigurationProviding>)serverConfigurationProvider
{
return _serverConfigurationProvider;
}
+ (id<FBSDKDataPersisting>)store
+ (void)setServerConfigurationProvider:(nullable id<FBSDKServerConfigurationProviding>)serverConfigurationProvider
{
return _store;
_serverConfigurationProvider = serverConfigurationProvider;
}
+ (id<FBSDKGraphRequestConnectionFactory>)graphRequestConnectionFactory
+ (nullable id<FBSDKDataPersisting>)dataStore
{
return _dataStore;
}
+ (void)setDataStore:(nullable id<FBSDKDataPersisting>)dataStore
{
_dataStore = dataStore;
}
+ (nullable id<FBSDKGraphRequestConnectionFactory>)graphRequestConnectionFactory
{
return _graphRequestConnectionFactory;
}
+ (Class<FBSDKSwizzling>)swizzler
+ (void)setGraphRequestConnectionFactory:(nullable id<FBSDKGraphRequestConnectionFactory>)graphRequestConnectionFactory
{
_graphRequestConnectionFactory = graphRequestConnectionFactory;
}
+ (nullable Class<FBSDKSwizzling>)swizzler
{
return _swizzler;
}
+ (id<FBSDKSettings>)settings
+ (void)setSwizzler:(nullable Class<FBSDKSwizzling>)swizzler
{
_swizzler = swizzler;
}
+ (nullable id<FBSDKSettings>)settings
{
return _settings;
}
+ (id<FBSDKAdvertiserIDProviding>)advertiserIDProvider
+ (void)setSettings:(nullable id<FBSDKSettings>)settings
{
_settings = settings;
}
+ (nullable id<FBSDKAdvertiserIDProviding>)advertiserIDProvider
{
return _advertiserIDProvider;
}
+ (void)setAdvertiserIDProvider:(nullable id<FBSDKAdvertiserIDProviding>)advertiserIDProvider
{
_advertiserIDProvider = advertiserIDProvider;
}
+ (void)enable
{
if (_isGestureSet) {
@@ -163,7 +198,7 @@ static id<FBSDKSettings> _settings;
// load the defaults
NSString *defaultKey = [NSString stringWithFormat:CODELESS_SETTING_KEY, appID];
NSData *data = [self.store objectForKey:defaultKey];
NSData *data = [self.dataStore objectForKey:defaultKey];
if ([data isKindOfClass:NSData.class]) {
NSMutableDictionary<NSString *, id> *codelessSetting = nil;
id<FBSDKObjectDecoding> unarchiver = [FBSDKUnarchiverProvider createInsecureUnarchiverFor:data];
@@ -201,7 +236,7 @@ static id<FBSDKSettings> _settings;
[FBSDKTypeUtility dictionary:_codelessSetting setObject:@(isCodelessSetupEnabled) forKey:CODELESS_SETUP_ENABLED_KEY];
[FBSDKTypeUtility dictionary:_codelessSetting setObject:[NSDate date] forKey:CODELESS_SETTING_TIMESTAMP_KEY];
// update the cached copy in user defaults
[self.store setObject:[NSKeyedArchiver archivedDataWithRootObject:_codelessSetting] forKey:defaultKey];
[self.dataStore setObject:[NSKeyedArchiver archivedDataWithRootObject:_codelessSetting] forKey:defaultKey];
completionBlock(isCodelessSetupEnabled, codelessLoadingError);
}
}];
@@ -263,11 +298,11 @@ static id<FBSDKSettings> _settings;
CODELESS_INDEXING_SESSION_ID_KEY : [self currentSessionDeviceID],
CODELESS_INDEXING_EXT_INFO_KEY : [self extInfo]
};
id<FBSDKGraphRequest> request = [_graphRequestFactory createGraphRequestWithGraphPath:[NSString stringWithFormat:@"%@/%@",
[self.settings appID],
CODELESS_INDEXING_SESSION_ENDPOINT]
parameters:parameters
HTTPMethod:FBSDKHTTPMethodPOST];
id<FBSDKGraphRequest> request = [self.graphRequestFactory createGraphRequestWithGraphPath:[NSString stringWithFormat:@"%@/%@",
[self.settings appID],
CODELESS_INDEXING_SESSION_ENDPOINT]
parameters:parameters
HTTPMethod:FBSDKHTTPMethodPOST];
[request startWithCompletion:^(id<FBSDKGraphRequestConnecting> connection, id result, NSError *error) {
_isCheckingSession = NO;
if ([result isKindOfClass:[NSDictionary<NSString *, id> class]]) {
@@ -385,16 +420,16 @@ static id<FBSDKSettings> _settings;
NSBundle *mainBundle = NSBundle.mainBundle;
NSString *version = [mainBundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
id<FBSDKGraphRequest> request = [_graphRequestFactory createGraphRequestWithGraphPath:[NSString stringWithFormat:@"%@/%@",
[self.settings appID],
CODELESS_INDEXING_ENDPOINT]
parameters:@{
id<FBSDKGraphRequest> request = [self.graphRequestFactory createGraphRequestWithGraphPath:[NSString stringWithFormat:@"%@/%@",
[self.settings appID],
CODELESS_INDEXING_ENDPOINT]
parameters:@{
CODELESS_INDEXING_TREE_KEY : tree,
CODELESS_INDEXING_APP_VERSION_KEY : version ?: @"",
CODELESS_INDEXING_PLATFORM_KEY : @"iOS",
CODELESS_INDEXING_SESSION_ID_KEY : [self currentSessionDeviceID]
}
HTTPMethod:FBSDKHTTPMethodPOST];
HTTPMethod:FBSDKHTTPMethodPOST];
_isCodelessIndexing = YES;
[request startWithCompletion:^(id<FBSDKGraphRequestConnecting> connection, id result, NSError *error) {
_isCodelessIndexing = NO;
@@ -501,13 +536,13 @@ static id<FBSDKSettings> _settings;
_isCodelessIndexingEnabled = NO;
_isGestureSet = NO;
_codelessSetting = nil;
_graphRequestFactory = nil;
_serverConfigurationProvider = nil;
_store = nil;
_graphRequestConnectionFactory = nil;
_swizzler = nil;
_settings = nil;
_advertiserIDProvider = nil;
self.graphRequestFactory = nil;
self.serverConfigurationProvider = nil;
self.dataStore = nil;
self.graphRequestConnectionFactory = nil;
self.swizzler = nil;
self.settings = nil;
self.advertiserIDProvider = nil;
_deviceSessionID = nil;
_lastTreeHash = nil;
}

View File

@@ -800,7 +800,7 @@ static UIApplicationState _applicationState;
[FBSDKCodelessIndexer configureWithGraphRequestFactory:graphRequestFactory
serverConfigurationProvider:serverConfigurationProvider
store:store
dataStore:store
graphRequestConnectionFactory:graphRequestConnectionFactory
swizzler:FBSDKSwizzler.class
settings:sharedSettings

View File

@@ -1193,7 +1193,7 @@ class ApplicationDelegateTests: XCTestCase { // swiftlint:disable:this type_body
"Should be configured with the expected concrete server configuration provider"
)
XCTAssertTrue(
CodelessIndexer.store === UserDefaults.standard,
CodelessIndexer.dataStore === UserDefaults.standard,
"Should be configured with the standard user defaults"
)
XCTAssertTrue(

View File

@@ -14,9 +14,9 @@ NS_ASSUME_NONNULL_BEGIN
@property (class, nullable, nonatomic, readonly) id<FBSDKGraphRequestFactory> graphRequestFactory;
@property (class, nullable, nonatomic, readonly) id<FBSDKServerConfigurationProviding> serverConfigurationProvider;
@property (class, nullable, nonatomic, readonly) id<FBSDKDataPersisting> store;
@property (class, nullable, nonatomic, copy) id<FBSDKGraphRequestConnectionFactory> graphRequestConnectionFactory;
@property (class, nullable, nonatomic, copy) Class<FBSDKSwizzling> swizzler;
@property (class, nullable, nonatomic, readonly) id<FBSDKDataPersisting> dataStore;
@property (class, nullable, nonatomic, readonly) id<FBSDKGraphRequestConnectionFactory> graphRequestConnectionFactory;
@property (class, nullable, nonatomic, readonly) Class<FBSDKSwizzling> swizzler;
@property (class, nullable, nonatomic, readonly) id<FBSDKSettings> settings;
@property (class, nullable, nonatomic, readonly) id<FBSDKAdvertiserIDProviding> advertiserIDProvider;
@property (class, nullable, nonatomic, readonly) NSString *currentSessionDeviceID;

View File

@@ -12,7 +12,7 @@ import XCTest
class CodelessIndexerTests: XCTestCase { // swiftlint:disable:this type_body_length
let graphRequestFactory = TestGraphRequestFactory()
let store = UserDefaultsSpy()
let dataStore = UserDefaultsSpy()
let connection = TestGraphRequestConnection()
lazy var graphRequestConnectionFactory: TestGraphRequestConnectionFactory = {
TestGraphRequestConnectionFactory.create(withStubbedConnection: connection)
@@ -45,9 +45,9 @@ class CodelessIndexerTests: XCTestCase { // swiftlint:disable:this type_body_len
settings.appID = name
CodelessIndexer.configure(
with: graphRequestFactory,
graphRequestFactory: graphRequestFactory,
serverConfigurationProvider: serverConfigurationProvider,
store: store,
dataStore: dataStore,
graphRequestConnectionFactory: graphRequestConnectionFactory,
swizzler: TestSwizzler.self,
settings: settings,
@@ -80,7 +80,7 @@ class CodelessIndexerTests: XCTestCase { // swiftlint:disable:this type_body_len
"Should not have a server configuration provider by default"
)
XCTAssertNil(
CodelessIndexer.store,
CodelessIndexer.dataStore,
"Should not have a persistent data store by default"
)
XCTAssertNil(
@@ -112,8 +112,8 @@ class CodelessIndexerTests: XCTestCase { // swiftlint:disable:this type_body_len
"Should be able to configure with a server configuration provider"
)
XCTAssertEqual(
CodelessIndexer.store as? UserDefaultsSpy,
store,
CodelessIndexer.dataStore as? UserDefaultsSpy,
dataStore,
"Should be able to configure with a persistent data store"
)
XCTAssertEqual(
@@ -224,13 +224,13 @@ class CodelessIndexerTests: XCTestCase { // swiftlint:disable:this type_body_len
nil
)
XCTAssertNil(
store.capturedObjectRetrievalKey,
dataStore.capturedObjectRetrievalKey,
"Should not attempt to read the cached codeless setting when codeless events are disabled"
)
}
func testLoadingValidCachedSetting() throws {
store.set(archivedSetting(), forKey: codelessSettingStorageKey)
dataStore.set(archivedSetting(), forKey: codelessSettingStorageKey)
CodelessIndexer.loadCodelessSetting { isEnabled, potentialError in
self.capturedIsEnabled = isEnabled
@@ -240,7 +240,7 @@ class CodelessIndexerTests: XCTestCase { // swiftlint:disable:this type_body_len
serverConfigurationProvider.capturedCompletionBlock?(enabledConfiguration, nil)
XCTAssertEqual(
store.capturedObjectRetrievalKey,
dataStore.capturedObjectRetrievalKey,
codelessSettingStorageKey,
"Should read the cached codeless setting"
)
@@ -255,7 +255,7 @@ class CodelessIndexerTests: XCTestCase { // swiftlint:disable:this type_body_len
}
func testLoadingExpiredCachedSettingWithoutAdvertiserID() {
store.set(archivedSetting(date: .distantPast), forKey: codelessSettingStorageKey)
dataStore.set(archivedSetting(date: .distantPast), forKey: codelessSettingStorageKey)
CodelessIndexer.loadCodelessSetting { _, _ in
XCTFail("Should not invoke the completion")
@@ -271,7 +271,7 @@ class CodelessIndexerTests: XCTestCase { // swiftlint:disable:this type_body_len
func testLoadingExpiredCachedSettingWithAdvertiserID() {
advertiserIDProvider.advertiserID = name
store.set(archivedSetting(date: .distantPast), forKey: codelessSettingStorageKey)
dataStore.set(archivedSetting(date: .distantPast), forKey: codelessSettingStorageKey)
CodelessIndexer.loadCodelessSetting { _, _ in
XCTFail("Should not invoke the completion")
@@ -292,7 +292,7 @@ class CodelessIndexerTests: XCTestCase { // swiftlint:disable:this type_body_len
func testCompletingLoadingSettingWithOnlyError() {
advertiserIDProvider.advertiserID = name
store.set(archivedSetting(date: .distantPast), forKey: codelessSettingStorageKey)
dataStore.set(archivedSetting(date: .distantPast), forKey: codelessSettingStorageKey)
CodelessIndexer.loadCodelessSetting { _, _ in
XCTFail("Should not invoke the completion if the network call completes with an error")
@@ -365,7 +365,7 @@ class CodelessIndexerTests: XCTestCase { // swiftlint:disable:this type_body_len
"Should complete with the enabled value from the network result"
)
XCTAssertEqual(
store.capturedSetObjectKey,
dataStore.capturedSetObjectKey,
codelessSettingStorageKey,
"Should persist the fetched setting"
)
@@ -373,7 +373,7 @@ class CodelessIndexerTests: XCTestCase { // swiftlint:disable:this type_body_len
func testCompletingLoadingNewSettingWithExpiredCachedSetting() {
advertiserIDProvider.advertiserID = name
store.set(archivedSetting(date: .distantPast), forKey: codelessSettingStorageKey)
dataStore.set(archivedSetting(date: .distantPast), forKey: codelessSettingStorageKey)
CodelessIndexer.loadCodelessSetting { isEnabled, potentialError in
self.capturedIsEnabled = isEnabled
@@ -390,7 +390,7 @@ class CodelessIndexerTests: XCTestCase { // swiftlint:disable:this type_body_len
"Should complete with the enabled value from the network result"
)
XCTAssertEqual(
store.capturedSetObjectKey,
dataStore.capturedSetObjectKey,
codelessSettingStorageKey,
"Should persist the fetched setting"
)