Authored by Matias Pequeno

Adds setter to override default SDWebImageDownloaderOperation.

@@ -140,6 +140,16 @@ typedef NSDictionary *(^SDWebImageDownloaderHeadersFilterBlock)(NSURL *url, NSDi @@ -140,6 +140,16 @@ typedef NSDictionary *(^SDWebImageDownloaderHeadersFilterBlock)(NSURL *url, NSDi
140 - (NSString *)valueForHTTPHeaderField:(NSString *)field; 140 - (NSString *)valueForHTTPHeaderField:(NSString *)field;
141 141
142 /** 142 /**
  143 + * Sets a subclass of `SDWebImageDownloaderOperation` as the default
  144 + * `NSOperation` to be used each time SDWebImage constructs a request
  145 + * operation to download an image.
  146 + *
  147 + * @param operationClass The subclass of `SDWebImageDownloaderOperation` to set
  148 + * as default. Passing `nil` will revert to `SDWebImageDownloaderOperation`.
  149 + */
  150 +- (void)setOperationClass:(Class)operationClass;
  151 +
  152 +/**
143 * Creates a SDWebImageDownloader async downloader instance with a given URL 153 * Creates a SDWebImageDownloader async downloader instance with a given URL
144 * 154 *
145 * The delegate will be informed when the image is finish downloaded or an error has happen. 155 * The delegate will be informed when the image is finish downloaded or an error has happen.
@@ -20,6 +20,7 @@ static NSString *const kCompletedCallbackKey = @"completed"; @@ -20,6 +20,7 @@ static NSString *const kCompletedCallbackKey = @"completed";
20 20
21 @property (strong, nonatomic) NSOperationQueue *downloadQueue; 21 @property (strong, nonatomic) NSOperationQueue *downloadQueue;
22 @property (weak, nonatomic) NSOperation *lastAddedOperation; 22 @property (weak, nonatomic) NSOperation *lastAddedOperation;
  23 +@property (assign, nonatomic) Class operationClass;
23 @property (strong, nonatomic) NSMutableDictionary *URLCallbacks; 24 @property (strong, nonatomic) NSMutableDictionary *URLCallbacks;
24 @property (strong, nonatomic) NSMutableDictionary *HTTPHeaders; 25 @property (strong, nonatomic) NSMutableDictionary *HTTPHeaders;
25 // This queue is used to serialize the handling of the network responses of all the download operation in a single queue 26 // This queue is used to serialize the handling of the network responses of all the download operation in a single queue
@@ -63,6 +64,7 @@ static NSString *const kCompletedCallbackKey = @"completed"; @@ -63,6 +64,7 @@ static NSString *const kCompletedCallbackKey = @"completed";
63 64
64 - (id)init { 65 - (id)init {
65 if ((self = [super init])) { 66 if ((self = [super init])) {
  67 + _operationClass = [SDWebImageDownloaderOperation class];
66 _executionOrder = SDWebImageDownloaderFIFOExecutionOrder; 68 _executionOrder = SDWebImageDownloaderFIFOExecutionOrder;
67 _downloadQueue = [NSOperationQueue new]; 69 _downloadQueue = [NSOperationQueue new];
68 _downloadQueue.maxConcurrentOperationCount = 2; 70 _downloadQueue.maxConcurrentOperationCount = 2;
@@ -104,6 +106,10 @@ static NSString *const kCompletedCallbackKey = @"completed"; @@ -104,6 +106,10 @@ static NSString *const kCompletedCallbackKey = @"completed";
104 return _downloadQueue.maxConcurrentOperationCount; 106 return _downloadQueue.maxConcurrentOperationCount;
105 } 107 }
106 108
  109 +- (void)setOperationClass:(Class)operationClass {
  110 + _operationClass = operationClass ?: [SDWebImageDownloaderOperation class];
  111 +}
  112 +
107 - (id <SDWebImageOperation>)downloadImageWithURL:(NSURL *)url options:(SDWebImageDownloaderOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageDownloaderCompletedBlock)completedBlock { 113 - (id <SDWebImageOperation>)downloadImageWithURL:(NSURL *)url options:(SDWebImageDownloaderOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageDownloaderCompletedBlock)completedBlock {
108 __block SDWebImageDownloaderOperation *operation; 114 __block SDWebImageDownloaderOperation *operation;
109 __weak SDWebImageDownloader *wself = self; 115 __weak SDWebImageDownloader *wself = self;
@@ -124,7 +130,7 @@ static NSString *const kCompletedCallbackKey = @"completed"; @@ -124,7 +130,7 @@ static NSString *const kCompletedCallbackKey = @"completed";
124 else { 130 else {
125 request.allHTTPHeaderFields = wself.HTTPHeaders; 131 request.allHTTPHeaderFields = wself.HTTPHeaders;
126 } 132 }
127 - operation = [[SDWebImageDownloaderOperation alloc] initWithRequest:request 133 + operation = [[wself.operationClass alloc] initWithRequest:request
128 options:options 134 options:options
129 progress:^(NSInteger receivedSize, NSInteger expectedSize) { 135 progress:^(NSInteger receivedSize, NSInteger expectedSize) {
130 SDWebImageDownloader *sself = wself; 136 SDWebImageDownloader *sself = wself;