Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a method for setting preconfigured PINRemoteImageManager #1124

Merged
merged 10 commits into from
Sep 18, 2018
Merged

Add a method for setting preconfigured PINRemoteImageManager #1124

merged 10 commits into from
Sep 18, 2018

Conversation

ernestmama
Copy link
Contributor

Add a method for setting preconfigured PINRemoteImageManager instead of using the self-created ASPINRemoteImageManager.

In this way, we can add custom configuration to the PINRemoteImageManager such as request configuration/url configuration.

…of using the self-created ASPINRemoteImageManager
@CLAassistant
Copy link

CLAassistant commented Sep 17, 2018

CLA assistant check
All committers have signed the CLA.

@@ -155,9 +159,18 @@ + (PINRemoteImageManager *)sharedPINRemoteImageManagerWithConfiguration:(NSURLSe

- (PINRemoteImageManager *)sharedPINRemoteImageManager
{
if (_preconfiguredPINRemoteImageManager) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this thread safe? Do we have to lock this?

return [ASPINRemoteImageDownloader sharedPINRemoteImageManagerWithConfiguration:nil];
}

- (PINRemoteImageManager *)setPreconfiguredPINRemoteImageManager:(PINRemoteImageManager *)preconfiguredPINRemoteImageManager
{
_preconfiguredPINRemoteImageManager = preconfiguredPINRemoteImageManager;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should add a lock here. Furthermore why do we return the same object here and od not make it a regular setter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I was going to make it return a void since it is setting.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me make it thread safe.

@nguyenhuy
Copy link
Member

nguyenhuy commented Sep 17, 2018

It's a valid concern that the new addition should be thread-safe. However, I'm not sure about adding a lock around -sharedPINRemoteImageManager. Almost every method of the downloader hits it eventually, and since the downloader is shared between all nodes, it's a very hot code path and there'll be lock contention.

How about we use the same pattern as -setSharedImageManagerWithConfiguration: to allow users to set the class of sharedPINRemoteImageManager? The class is required to be set very early on, even before +setSharedImageManagerWithConfiguration: which then will be picked up by +sharedPINRemoteImageManagerWithConfiguration:.

@maicki
Copy link
Contributor

maicki commented Sep 17, 2018

The suggestion from @nguyenhuy sounds good to me.

@ghost
Copy link

ghost commented Sep 17, 2018

🚫 CI failed with log

@ernestmama
Copy link
Contributor Author

@nguyenhuy Shouldn't Texture knows nothing about the custom image manager except it is a subclass of PINRemoteImageMager to keep the abstraction? The subclass is in a higher level app/library.

@nguyenhuy
Copy link
Member

@ernestmama Yes, and with the new API, it still wouldn't know anything, does it?

@ernestmama
Copy link
Contributor Author

ernestmama commented Sep 17, 2018

@nguyenhuy How about this update? This will essentially change that the RemoteImageManager can only be set once (same as previous with configuration) instead of able to swapping it in runtime. It will need to be set before the first time ImageManager is being used.

@ernestmama ernestmama changed the title add a method for setting preconfigured PINRemoteImageManager add a method for setting preconfigured PINRemoteImageManager #trivial Sep 17, 2018
Copy link
Member

@nguyenhuy nguyenhuy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's a better idea.

* Sets a custom perconconfigured PINRemoteImageManager that will be used by @c ASNetworkImageNodes and @c ASMultiplexImageNodes
* while loading images off the network. This must be specified early in the application lifecycle before
* `sharedDownloader` is accessed. If nil is passed in as the PINRemoteImageManager, it will call
* setSharedImageManagerWithConfiguration with nil configuration.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it will call setSharedImageManagerWithConfiguration with nil configuration.

Does it? How about:

it will create a default image manager with a nil session configuration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are rrright.

Copy link
Member

@nguyenhuy nguyenhuy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nearly there.

Also, this diff is not trivial. It introduces a new API, please update changelog.


+ (PINRemoteImageManager *)sharedPINRemoteImageManagerWithConfiguration:(NSURLSessionConfiguration *)configuration preconfiguredPINRemoteImageManager:(PINRemoteImageManager *)preconfiguredPINRemoteImageManager
{
NSAssert(configuration != nil && preconfiguredPINRemoteImageManager != nil, @"Either configuration or preconfigured image manager can be set at a time.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assertion means both configuration and preconfigured manager must not be nil. I don't think it's right.

dispatch_once(&onceToken, ^{

if (preconfiguredPINRemoteImageManager) {
sharedPINRemoteImageManager = preconfiguredPINRemoteImageManager;
} else {
#if PIN_ANIMATED_AVAILABLE
// Check that Carthage users have linked both PINRemoteImage & PINCache by testing for one file each
if (!(NSClassFromString(@"PINRemoteImageManager"))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentation seems to be off. The whole else body here should be indented.

@nguyenhuy nguyenhuy changed the title add a method for setting preconfigured PINRemoteImageManager #trivial Add a method for setting preconfigured PINRemoteImageManager Sep 17, 2018
@nguyenhuy nguyenhuy merged commit 1452b31 into TextureGroup:master Sep 18, 2018
@ernestmama ernestmama deleted the injectedRemoteImageManager branch September 18, 2018 00:22
mikezucc pushed a commit to mikezucc/Texture that referenced this pull request Oct 2, 2018
…RemoteImageManager (TextureGroup#1124)

* add a method for setting preconfigured PINRemoteImageManager instead of using the self-created ASPINRemoteImageManager

* update preconfigured image manager where it can only be set once

* fix spacing in downloader

* Fix doc/comments on new api

* adding assertion to ensure either only configuration or preconfigure image manager can be set at a time

* adding assertion to ensure either only configuration or preconfigure image manager can be set at a time

* fix assertion condition

* Update CHANGELOG.md

* Remove unnecessary change
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants