Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Minor improvements to bandwidth logic

  • Loading branch information...
commit 9fec2637f6741f571388435bef60e020ebf103a6 1 parent 8ab73d8
Marcus S. Zarra authored
Showing with 28 additions and 12 deletions.
  1. +0 −8 ZSAssetManager.h
  2. +28 −4 ZSAssetManager.m
8 ZSAssetManager.h
View
@@ -31,16 +31,8 @@
*
*/
-#define kAssetManager @"kAssetManager"
#define kImageDownloadComplete @"kImageDownloadComplete"
-#define kRemainingCacheItems @"kRemainingCacheItems"
-#define kTotalRequestedCacheItems @"kTotalRequestedCacheItems"
-#define kCurrentCacheState @"kCurrentCacheState"
-#define kLastSampledDownloadSpeed @"kLastSampledDownloadSpeed"
-#define kCurrentNetworkState @"kCurrentNetworkState"
-#define kBookCacheCompleted @"kBookCacheCompleted"
-
@class ZSURLConnectionDelegate;
@interface ZSAssetManager : NSObject
32 ZSAssetManager.m
View
@@ -255,6 +255,31 @@ - (void)calculateBandwidthForDelegate:(ZSURLConnectionDelegate*)delegate
} else if (currentNetworkState > ZSNetworkStatePoor) {
++currentNetworkState;
}
+
+ if (currentNetworkState == ZSNetworkStateOptimal) {
+ [[self assetQueue] setSuspended:NO];
+ [[self assetQueue] setMaxConcurrentOperationCount:4];
+ return;
+ }
+
+ [[self assetQueue] setMaxConcurrentOperationCount:1];
+
+ if (currentNetworkState == ZSNetworkStateAverage) {
+ [[self assetQueue] setSuspended:NO];
+ return;
+ }
+
+ for (ZSURLConnectionDelegate *nextOperation in [[self assetQueue] operations]) {
+ if ([nextOperation isExecuting] || [nextOperation isFinished] || [nextOperation isCancelled]) {
+ DLog(@"skipping operation");
+ continue;
+ }
+ if ([nextOperation queuePriority] == NSOperationQueuePriorityVeryHigh) {
+ DLog(@"still busy with user requests");
+ return;
+ }
+ [[self assetQueue] setSuspended:YES];
+ }
}
- (void)cacheOperationCompleted:(ZSURLConnectionDelegate*)delegate
@@ -304,6 +329,8 @@ - (void)downloadImage:(NSURL*)url
if (CACHE_TEST) DLog(@"activating cache");
}
+ [[self assetQueue] setSuspended:NO];
+
//If it is currently in the cache queue, promote it
for (ZSURLConnectionDelegate *operation in [[self assetQueue] operations]) {
if (![[operation myURL] isEqual:url]) continue;
@@ -320,7 +347,6 @@ - (void)downloadImage:(NSURL*)url
[delegate setSuccessSelector:@selector(dataReceived:)];
[delegate setFailureSelector:@selector(requestFailedForDelegate:)];
[delegate setQueuePriority:NSOperationQueuePriorityNormal];
- [delegate setThreadPriority:0.0f];
[[self assetQueue] addOperation:delegate];
@@ -337,9 +363,7 @@ - (void)dataReceived:(ZSURLConnectionDelegate*)delegate
return;
}
- NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
- [userInfo setObject:self forKey:kAssetManager];
- NSNotification *notification = [NSNotification notificationWithName:kImageDownloadComplete object:[delegate myURL] userInfo:userInfo];
+ NSNotification *notification = [NSNotification notificationWithName:kImageDownloadComplete object:[delegate myURL] userInfo:nil];
[[NSNotificationQueue defaultQueue] enqueueNotification:notification postingStyle:NSPostWhenIdle coalesceMask:NSNotificationCoalescingOnSender forModes:nil];
Please sign in to comment.
Something went wrong with that request. Please try again.