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
9 changes: 9 additions & 0 deletions Source/Details/ASPINRemoteImageDownloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ NS_ASSUME_NONNULL_BEGIN
*/
+ (void)setSharedImageManagerWithConfiguration:(nullable NSURLSessionConfiguration *)configuration;

/**
* Sets a custom perconconfigured PINRemoteImageManager that will be used by @c ASNetworkImageNodes and @c ASMultiplexImageNodes
* while loading images off the network. This can be called at anytime. Once this is set, it will always be used with priority.
* If this is not set, it will call setSharedImageManagerWithConfiguration with nil.
*
* @param PINRemoteImageManager the preconfigured remote image manager that will be used by `sharedDownloader`
*/
- (void)setPreconfiguredPINRemoteImageManager:(PINRemoteImageManager *)preconfiguredPINRemoteImageManager;

/**
* The shared instance of a @c PINRemoteImageManager used by all @c ASPINRemoteImageDownloaders
*
Expand Down
13 changes: 13 additions & 0 deletions Source/Details/ASPINRemoteImageDownloader.m
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ @interface ASPINRemoteImageManager : PINRemoteImageManager
@end

@implementation ASPINRemoteImageManager
{
@private
PINRemoteImageManager *_preconfiguredPINRemoteImageManager;
}

//Share image cache with sharedImageManager image cache.
- (id <PINRemoteImageCaching>)defaultImageCache
Expand Down Expand Up @@ -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 _preconfiguredPINRemoteImageManager;
}
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.

return _preconfiguredPINRemoteImageManager;
}

- (BOOL)sharedImageManagerSupportsMemoryRemoval
{
static BOOL sharedImageManagerSupportsMemoryRemoval = NO;
Expand Down