Skip to content

Commit 4415bee

Browse files
author
Evadne Wu
committed
WIP for code modernization
- uses Automatic Reference Counting - fixes several issues - removes Cappuccino variant - removes Twitter / Google Reader / TwitPic interfaces - fixes several other semantic issues
1 parent 6be393b commit 4415bee

51 files changed

Lines changed: 279 additions & 3607 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎IRRemoteResourceDownloadOperation.m‎

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ - (void) onOriginalQueue:(void(^)(void))aBlock;
4141
@implementation IRRemoteResourceDownloadOperation
4242

4343
@synthesize path, mimeType, url, processedBytes, totalBytes, preferredByteOffset, executing, finished, cancelled;
44-
@synthesize fileHandle, connection;
44+
@synthesize fileHandle = _fileHandle;
45+
@synthesize connection = _connection;
4546
@synthesize actualDispatchQueue;
4647
@synthesize onMain;
4748
@synthesize appendedCompletionBlocks;
@@ -52,34 +53,21 @@ + (IRRemoteResourceDownloadOperation *) operationWithURL:(NSURL *)aRemoteURL pat
5253
NSParameterAssert(aRemoteURL);
5354
NSParameterAssert(aLocalPath);
5455

55-
IRRemoteResourceDownloadOperation *returnedOperation = [[[self alloc] init] autorelease];
56+
IRRemoteResourceDownloadOperation *returnedOperation = [[self alloc] init];
5657

5758
returnedOperation.url = aRemoteURL;
5859
returnedOperation.path = aLocalPath;
5960
returnedOperation.onMain = aPrelude;
6061
returnedOperation.completionBlock = aBlock;
62+
6163
return returnedOperation;
6264

6365
}
6466

6567
- (void) dealloc {
6668

67-
[mimeType release];
68-
69-
[path release];
70-
[url release];
71-
[fileHandle release];
72-
73-
__block NSURLConnection *nrConnection = connection;
74-
dispatch_async(dispatch_get_main_queue(), ^ {
75-
[nrConnection release];
76-
});
77-
78-
[onMain release];
79-
[appendedCompletionBlocks release];
69+
[_connection cancel];
8070

81-
[super dealloc];
82-
8371
}
8472

8573
- (void) onMainQueue:(void(^)(void))aBlock {
@@ -135,18 +123,19 @@ - (void) main {
135123

136124
[self onMainQueue: ^ {
137125

138-
NSMutableURLRequest *usedRequest = [NSMutableURLRequest requestWithURL:self.url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10];
139-
NSURLConnection *usedConnection = [[[NSURLConnection alloc] initWithRequest:usedRequest delegate:self startImmediately:NO] autorelease];
126+
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:self.url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10];
127+
128+
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:NO];
140129

141-
objc_setAssociatedObject(usedConnection, &kIRRemoteResourcesDownloadOperation_connectionRequest, usedRequest, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
142-
self.connection = usedConnection;
130+
objc_setAssociatedObject(connection, &kIRRemoteResourcesDownloadOperation_connectionRequest, request, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
131+
self.connection = connection;
143132

144133
[self.delegate remoteResourceDownloadOperationWillBegin:self];
145134

146-
usedConnection = [[[NSURLConnection alloc] initWithRequest:usedRequest delegate:self startImmediately:NO] autorelease];
135+
connection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:NO];
147136

148-
objc_setAssociatedObject(usedConnection, &kIRRemoteResourcesDownloadOperation_connectionRequest, usedRequest, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
149-
self.connection = usedConnection;
137+
objc_setAssociatedObject(connection, &kIRRemoteResourcesDownloadOperation_connectionRequest, request, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
138+
self.connection = connection;
150139

151140
// Do not mutate the URL
152141
// self.url = usedRequest.URL;
@@ -248,13 +237,16 @@ - (void) connectionDidFinishLoading:(NSURLConnection *)connection {
248237

249238
// If there is a MIME type available, rename the underlying file
250239

251-
NSFileManager *fm = [NSFileManager defaultManager];
240+
CFStringRef const tag = (__bridge CFStringRef)self.mimeType;
241+
NSString *utiType = (NSString *)CFBridgingRelease(UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, tag, NULL));
252242

253-
NSString *utiType = [(NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, (CFStringRef)self.mimeType, NULL) autorelease];
254-
NSString *pathExtension = [(NSString *)UTTypeCopyPreferredTagWithClass((CFStringRef)utiType, kUTTagClassFilenameExtension) autorelease];
243+
CFStringRef const tagClass = kUTTagClassFilenameExtension;
244+
NSString *pathExtension = (NSString *)CFBridgingRelease(UTTypeCopyPreferredTagWithClass((__bridge CFStringRef)utiType, tagClass));
255245

256246
if (pathExtension) {
257247

248+
NSFileManager * const fm = [NSFileManager defaultManager];
249+
258250
NSString *fromPath = self.path;
259251
NSString *toPath = [[self.path stringByDeletingPathExtension] stringByAppendingPathExtension:pathExtension];
260252
NSError *error = nil;
@@ -305,8 +297,9 @@ - (NSURLRequest *) connection:(NSURLConnection *)connection willSendRequest:(NSU
305297
if (!aRedirectResponse)
306298
return aRequest;
307299

308-
NSMutableURLRequest *mutatedRequest = [[[self underlyingRequest] mutableCopy] autorelease];
300+
NSMutableURLRequest *mutatedRequest = [[self underlyingRequest] mutableCopy];
309301
mutatedRequest.URL = [aRequest URL];
302+
310303
return mutatedRequest;
311304

312305
}
@@ -382,25 +375,25 @@ - (NSString *) description {
382375

383376
- (NSMutableArray *) appendedCompletionBlocks {
384377

385-
if (appendedCompletionBlocks)
386-
return appendedCompletionBlocks;
378+
if (!appendedCompletionBlocks) {
379+
appendedCompletionBlocks = [NSMutableArray array];
380+
}
387381

388-
appendedCompletionBlocks = [[NSMutableArray array] retain];
389382
return appendedCompletionBlocks;
390383

391384
}
392385

393386
- (void) appendCompletionBlock:(void (^)(void))aBlock {
394387

395-
[self.appendedCompletionBlocks addObject:[[aBlock copy] autorelease]];
388+
[self.appendedCompletionBlocks addObject:[aBlock copy]];
396389

397390
}
398391

399392
- (void) invokeCompletionBlocks {
400393

401394
@synchronized (self) {
402395

403-
for (void(^aBlock)(void) in [[self.appendedCompletionBlocks copy] autorelease])
396+
for (void(^aBlock)(void) in self.appendedCompletionBlocks)
404397
aBlock();
405398

406399
self.appendedCompletionBlocks = [NSMutableArray array];
@@ -414,7 +407,7 @@ - (IRRemoteResourceDownloadOperation *) continuationOperationCancellingCurrentOp
414407
if (!self.path || !self.url)
415408
return nil;
416409

417-
__block IRRemoteResourceDownloadOperation *continuationOperation = [[[[self class] alloc] init] autorelease];
410+
__block IRRemoteResourceDownloadOperation *continuationOperation = [[[self class] alloc] init];
418411
continuationOperation.path = self.path;
419412
continuationOperation.url = self.url;
420413
continuationOperation.preferredByteOffset = self.processedBytes;

‎IRRemoteResourcesManager.m‎

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ - (id) init {
8181
queue = [[NSOperationQueue alloc] init];
8282
queue.maxConcurrentOperationCount = 1;
8383
operationQueue = dispatch_queue_create("iridia.remoteResourcesManager.operationQueue", DISPATCH_QUEUE_SERIAL);
84-
enqueuedOperations = [[NSMutableArray array] retain];
84+
enqueuedOperations = [NSMutableArray array];
8585

86-
allOperations = [[NSMutableDictionary dictionary] retain];
86+
allOperations = [NSMutableDictionary dictionary];
8787
allOperationsQueue = dispatch_queue_create("iridia.remoteResourcesManager.operationsManagingQueue", DISPATCH_QUEUE_SERIAL);
8888

8989
return self;
@@ -96,20 +96,10 @@ - (void) dealloc {
9696

9797
if (operationQueue)
9898
dispatch_release(operationQueue);
99-
100-
[queue release];
101-
[enqueuedOperations release];
102-
[cacheDirectoryPath release];
103-
104-
[onRemoteResourceDownloadOperationWillBegin release];
105-
106-
[allOperations release];
107-
99+
108100
if (allOperationsQueue)
109101
dispatch_release(allOperationsQueue);
110102

111-
[super dealloc];
112-
113103
}
114104

115105

@@ -290,12 +280,12 @@ - (IRRemoteResourceDownloadOperation *) enqueuedOperationForURL:(NSURL *)anURL {
290280

291281
- (IRRemoteResourceDownloadOperation *) prospectiveOperationForURL:(NSURL *)anURL enqueue:(BOOL)enqueuesOperation {
292282

293-
__block __typeof__(self) nrSelf = self;
283+
__weak IRRemoteResourcesManager *wSelf = self;
294284
__block IRRemoteResourceDownloadOperation *operation = nil;
295285

296286
operation = [IRRemoteResourceDownloadOperation operationWithURL:anURL path:[self pathForCachedContentsOfRemoteURL:anURL usedProspectiveURL:NULL] prelude: ^ {
297287

298-
[nrSelf.delegate remoteResourcesManager:nrSelf didBeginDownloadingResourceAtURL:operation.url];
288+
[wSelf.delegate remoteResourcesManager:wSelf didBeginDownloadingResourceAtURL:operation.url];
299289

300290
} completion: ^ {
301291

@@ -305,39 +295,39 @@ - (IRRemoteResourceDownloadOperation *) prospectiveOperationForURL:(NSURL *)anUR
305295

306296
if (didFinish) {
307297

308-
[operation retain];
309-
310298
dispatch_async(dispatch_get_main_queue(), ^ {
311299

312300
[operation invokeCompletionBlocks];
313-
[operation autorelease];
301+
operation = nil;
314302

315-
[nrSelf notifyUpdatedResourceForRemoteURL:operationURL];
316-
[nrSelf.delegate remoteResourcesManager:nrSelf didFinishDownloadingResourceAtURL:operationURL];
303+
[wSelf notifyUpdatedResourceForRemoteURL:operationURL];
304+
[wSelf.delegate remoteResourcesManager:wSelf didFinishDownloadingResourceAtURL:operationURL];
317305

318306
});
319307

320308
} else {
321309

322310
dispatch_async(dispatch_get_main_queue(), ^ {
323311

324-
[nrSelf.delegate remoteResourcesManager:nrSelf didFailDownloadingResourceAtURL:operationURL];
312+
[wSelf.delegate remoteResourcesManager:wSelf didFailDownloadingResourceAtURL:operationURL];
325313

314+
operation = nil;
315+
326316
});
327317

328318
}
329319

330320
dispatch_async(dispatch_get_main_queue(), ^{
331321

332-
[nrSelf beginSuspendingOperationQueue];
322+
[wSelf beginSuspendingOperationQueue];
333323

334-
[nrSelf performInBackground: ^ {
324+
[wSelf performInBackground: ^ {
335325

336-
[nrSelf enqueueOperationsIfNeeded];
326+
[wSelf enqueueOperationsIfNeeded];
337327

338328
dispatch_async(dispatch_get_main_queue(), ^{
339329

340-
[nrSelf endSuspendingOperationQueue];
330+
[wSelf endSuspendingOperationQueue];
341331

342332
});
343333

@@ -461,7 +451,6 @@ - (void) retrieveResourceAtURL:(NSURL *)anURL usingPriority:(NSOperationQueuePri
461451

462452
// Hoist it — This is last come, first serve
463453

464-
[[operation retain] autorelease];
465454
[self.enqueuedOperations removeObject:operation];
466455
[self.enqueuedOperations insertObject:operation atIndex:0];
467456

@@ -545,18 +534,20 @@ - (void) enqueueOperationsIfNeeded {
545534

546535
- (NSString *) cacheDirectoryPath {
547536

548-
if (cacheDirectoryPath)
549-
return cacheDirectoryPath;
537+
if (!cacheDirectoryPath) {
538+
539+
NSString *prospectivePath = [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:NSStringFromClass([self class])];
550540

551-
NSString *prospectivePath = [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:NSStringFromClass([self class])];
541+
NSError *cacheDirectoryCreationError;
542+
if (![[NSFileManager defaultManager] createDirectoryAtPath:prospectivePath withIntermediateDirectories:YES attributes:nil error:&cacheDirectoryCreationError]) {
543+
NSLog(@"Error occurred while creating or assuring cache directory: %@", cacheDirectoryCreationError);
544+
return nil;
545+
}
546+
547+
cacheDirectoryPath = [prospectivePath copy];
552548

553-
NSError *cacheDirectoryCreationError;
554-
if (![[NSFileManager defaultManager] createDirectoryAtPath:prospectivePath withIntermediateDirectories:YES attributes:nil error:&cacheDirectoryCreationError]) {
555-
NSLog(@"Error occurred while creating or assuring cache directory: %@", cacheDirectoryCreationError);
556-
return nil;
557549
}
558550

559-
cacheDirectoryPath = [prospectivePath retain];
560551
return cacheDirectoryPath;
561552

562553
}
@@ -580,7 +571,7 @@ - (BOOL) clearCacheDirectory {
580571

581572
- (void) notifyUpdatedResourceForRemoteURL:(NSURL *)inRemoteURL {
582573

583-
inRemoteURL = [[inRemoteURL copy] autorelease];
574+
inRemoteURL = [inRemoteURL copy];
584575

585576
dispatch_async(dispatch_get_main_queue(), ^ {
586577

‎IRSiteReachability.j‎

Lines changed: 0 additions & 33 deletions
This file was deleted.

‎IRWebAPIAuthenticator.m‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,6 @@ - (void) createTransformerBlocks {
3838

3939
}
4040

41-
- (void) dealloc {
42-
43-
self.globalRequestPreTransformerBlock = nil;
44-
self.globalRequestPostTransformerBlock = nil;
45-
self.globalResponsePreTransformerBlock = nil;
46-
self.globalResponsePostTransformerBlock = nil;
47-
48-
self.currentCredentials = nil;
49-
50-
[super dealloc];
51-
52-
}
53-
5441
- (void) associateWithEngine:(IRWebAPIEngine *)inEngine {
5542

5643
if (self.globalRequestPreTransformerBlock)

0 commit comments

Comments
 (0)