Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenhuy committed Mar 7, 2019
1 parent 6a1f368 commit d7413c8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 29 deletions.
24 changes: 10 additions & 14 deletions Source/ASMultiplexImageNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ @interface ASMultiplexImageNode ()

//set on init only
BOOL _cacheSupportsClearing;
BOOL _isInImageDownloaderPriorityExperiment;
}

//! @abstract Read-write redeclaration of property declared in ASMultiplexImageNode.h.
Expand Down Expand Up @@ -184,8 +183,6 @@ - (instancetype)initWithCache:(id<ASImageCacheProtocol>)cache downloader:(id<ASI

_shouldRenderProgressImages = YES;

_isInImageDownloaderPriorityExperiment = ASActivateExperimentalFeature(ASExperimentalImageDownloaderPriority);

self.shouldBypassEnsureDisplay = YES;

return self;
Expand Down Expand Up @@ -302,7 +299,7 @@ - (void)didExitVisibleState
- (void)didExitDisplayState
{
[super didExitDisplayState];
if (_isInImageDownloaderPriorityExperiment) {
if (ASActivateExperimentalFeature(ASExperimentalImageDownloaderPriority)) {
[self _updatePriorityOnDownloaderIfNeededWithDefaultPriority:ASImageDownloaderPriorityPreload];
}
}
Expand Down Expand Up @@ -488,20 +485,19 @@ - (UIImage *)_bestImmediatelyAvailableImageFromDataSource:(id *)imageIdentifierO
- (void)_updatePriorityOnDownloaderIfNeededWithDefaultPriority:(ASImageDownloaderPriority)defaultPriority
{
ASAssertUnlocked(_downloadIdentifierLock);

if (_downloaderFlags.downloaderImplementsSetPriority) {
id downloadIdentifier;
{
ASDN::MutexLocker l(_downloadIdentifierLock);
downloadIdentifier = _downloadIdentifier;
}
// Read our interface state before locking so that we don't lock super while holding our lock.
ASInterfaceState interfaceState = self.interfaceState;
ASDN::MutexLocker l(_downloadIdentifierLock);

if (downloadIdentifier != nil) {
if (_downloadIdentifier != nil) {
ASImageDownloaderPriority priority = defaultPriority;
if (_isInImageDownloaderPriorityExperiment) {
priority = ASImageDownloaderPriorityWithInterfaceState(self.interfaceState);
if (ASActivateExperimentalFeature(ASExperimentalImageDownloaderPriority)) {
priority = ASImageDownloaderPriorityWithInterfaceState(interfaceState);
}

[_downloader setPriority:priority withDownloadIdentifier:downloadIdentifier];
[_downloader setPriority:priority withDownloadIdentifier:_downloadIdentifier];
}
}
}
Expand Down Expand Up @@ -875,7 +871,7 @@ - (void)_downloadImageWithIdentifier:(id)imageIdentifier URL:(NSURL *)imageURL c

id downloadIdentifier;
if (strongSelf->_downloaderFlags.downloaderImplementsDownloadWithPriority
&& strongSelf->_isInImageDownloaderPriorityExperiment) {
&& ASActivateExperimentalFeature(ASExperimentalImageDownloaderPriority)) {

/*
Decide a priority based on the current interface state of this node.
Expand Down
22 changes: 7 additions & 15 deletions Source/ASNetworkImageNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ @interface ASNetworkImageNode ()
CGFloat _currentImageQuality;
CGFloat _renderedImageQuality;
BOOL _shouldRenderProgressImages;
BOOL _isInImageDownloaderPriorityExperiment;

struct {
unsigned int delegateWillStartDisplayAsynchronously:1;
Expand Down Expand Up @@ -107,7 +106,6 @@ - (instancetype)initWithCache:(id<ASImageCacheProtocol>)cache downloader:(id<ASI

_shouldCacheImage = YES;
_shouldRenderProgressImages = YES;
_isInImageDownloaderPriorityExperiment = ASActivateExperimentalFeature(ASExperimentalImageDownloaderPriority);
self.shouldBypassEnsureDisplay = YES;

return self;
Expand Down Expand Up @@ -397,7 +395,7 @@ - (void)didExitVisibleState
- (void)didExitDisplayState
{
[super didExitDisplayState];
if (_isInImageDownloaderPriorityExperiment) {
if (ASActivateExperimentalFeature(ASExperimentalImageDownloaderPriority)) {
[self _updatePriorityOnDownloaderIfNeededWithDefaultPriority:ASImageDownloaderPriorityPreload];
}
}
Expand Down Expand Up @@ -451,21 +449,15 @@ - (void)handleProgressImage:(UIImage *)progressImage progress:(CGFloat)progress
- (void)_updatePriorityOnDownloaderIfNeededWithDefaultPriority:(ASImageDownloaderPriority)defaultPriority
{
if (_downloaderFlags.downloaderImplementsSetPriority) {
id downloadIdentifier;
ASInterfaceState interfaceState;
{
ASLockScopeSelf();
downloadIdentifier = _downloadIdentifier;
interfaceState = _interfaceState;
}
ASLockScopeSelf();

if (downloadIdentifier != nil) {
if (_downloadIdentifier != nil) {
ASImageDownloaderPriority priority = defaultPriority;
if (_isInImageDownloaderPriorityExperiment) {
priority = ASImageDownloaderPriorityWithInterfaceState(interfaceState);
if (ASActivateExperimentalFeature(ASExperimentalImageDownloaderPriority)) {
priority = ASImageDownloaderPriorityWithInterfaceState(_interfaceState);
}

[_downloader setPriority:priority withDownloadIdentifier:downloadIdentifier];
[_downloader setPriority:priority withDownloadIdentifier:_downloadIdentifier];
}
}
}
Expand Down Expand Up @@ -607,7 +599,7 @@ - (void)_downloadImageWithCompletion:(void (^)(id <ASImageContainerProtocol> ima
};

if (self->_downloaderFlags.downloaderImplementsDownloadWithPriority
&& self->_isInImageDownloaderPriorityExperiment) {
&& ASActivateExperimentalFeature(ASExperimentalImageDownloaderPriority)) {
/*
Decide a priority based on the current interface state of this node.
It can happen that this method was called when the node entered preload state
Expand Down

0 comments on commit d7413c8

Please sign in to comment.