Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 99da3bf

Browse files
committed
download-progress-perf
1 parent 4508f63 commit 99da3bf

File tree

4 files changed

+23
-27
lines changed

4 files changed

+23
-27
lines changed

ios/CodePush/CodePush.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@
5454
@property (strong) NSOutputStream *outputFileStream;
5555
@property long long expectedContentLength;
5656
@property long long receivedContentLength;
57-
@property dispatch_queue_t usingQueue;
57+
@property dispatch_queue_t operationQueue;
5858
@property (copy) void (^progressCallback)(long long, long long);
5959
@property (copy) void (^doneCallback)(BOOL);
6060
@property (copy) void (^failCallback)(NSError *err);
6161

6262
- (id)init:(NSString *)downloadFilePath
63-
usingQueue:(dispatch_queue_t)usingQueue
63+
operationQueue:(dispatch_queue_t)operationQueue
6464
progressCallback:(void (^)(long long, long long))progressCallback
6565
doneCallback:(void (^)(BOOL))doneCallback
6666
failCallback:(void (^)(NSError *err))failCallback;
@@ -80,7 +80,7 @@ failCallback:(void (^)(NSError *err))failCallback;
8080

8181
+ (void)downloadPackage:(NSDictionary *)updatePackage
8282
expectedBundleFileName:(NSString *)expectedBundleFileName
83-
usingQueue:(dispatch_queue_t)usingQueue
83+
operationQueue:(dispatch_queue_t)operationQueue
8484
progressCallback:(void (^)(long long, long long))progressCallback
8585
doneCallback:(void (^)())doneCallback
8686
failCallback:(void (^)(NSError *err))failCallback;

ios/CodePush/CodePush.m

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -495,37 +495,33 @@ - (void)applicationWillResignActive
495495
[CodePushPackage
496496
downloadPackage:mutableUpdatePackage
497497
expectedBundleFileName:[bundleResourceName stringByAppendingPathExtension:bundleResourceExtension]
498-
usingQueue:_methodQueue
498+
operationQueue:_methodQueue
499499
// The download is progressing forward
500500
progressCallback:^(long long expectedContentLength, long long receivedContentLength) {
501501
// Notify the script-side about the progress
502502
if (notifyProgress) {
503-
[self sendDownloadProgressDuringNextFrame:expectedContentLength
504-
receivedContentLength:receivedContentLength];
503+
[self updateDownloadProgressForNextFrame:expectedContentLength
504+
receivedContentLength:receivedContentLength];
505505
}
506506
}
507507
// The download completed
508508
doneCallback:^{
509-
dispatch_async(_methodQueue, ^{
510-
NSError *err;
511-
NSDictionary *newPackage = [CodePushPackage getPackage:mutableUpdatePackage[PackageHashKey] error:&err];
509+
NSError *err;
510+
NSDictionary *newPackage = [CodePushPackage getPackage:mutableUpdatePackage[PackageHashKey] error:&err];
512511

513-
if (err) {
514-
return reject([NSString stringWithFormat: @"%lu", (long)err.code], err.localizedDescription, err);
515-
}
512+
if (err) {
513+
return reject([NSString stringWithFormat: @"%lu", (long)err.code], err.localizedDescription, err);
514+
}
516515

517-
resolve(newPackage);
518-
});
516+
resolve(newPackage);
519517
}
520518
// The download failed
521519
failCallback:^(NSError *err) {
522-
dispatch_async(_methodQueue, ^{
523-
if ([CodePushErrorUtils isCodePushError:err]) {
524-
[self saveFailedUpdate:mutableUpdatePackage];
525-
}
520+
if ([CodePushErrorUtils isCodePushError:err]) {
521+
[self saveFailedUpdate:mutableUpdatePackage];
522+
}
526523

527-
reject([NSString stringWithFormat: @"%lu", (long)err.code], err.localizedDescription, err);
528-
});
524+
reject([NSString stringWithFormat: @"%lu", (long)err.code], err.localizedDescription, err);
529525
}];
530526
}
531527

@@ -777,8 +773,8 @@ - (void)didUpdateFrame:(RCTFrameUpdate *)update
777773
_paused = YES;
778774
}
779775

780-
- (void)sendDownloadProgressDuringNextFrame:(long long)expectedContentLength
781-
receivedContentLength:(long long)receivedContentLength
776+
- (void)updateDownloadProgressForNextFrame:(long long)expectedContentLength
777+
receivedContentLength:(long long)receivedContentLength
782778
{
783779
latestExpectedContentLength = expectedContentLength;
784780
latestReceivedConentLength = receivedContentLength;

ios/CodePush/CodePushDownloadHandler.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ @implementation CodePushDownloadHandler {
66
}
77

88
- (id)init:(NSString *)downloadFilePath
9-
usingQueue:(dispatch_queue_t)usingQueue
9+
operationQueue:(dispatch_queue_t)operationQueue
1010
progressCallback:(void (^)(long long, long long))progressCallback
1111
doneCallback:(void (^)(BOOL))doneCallback
1212
failCallback:(void (^)(NSError *err))failCallback {
1313
self.outputFileStream = [NSOutputStream outputStreamToFileAtPath:downloadFilePath
1414
append:NO];
1515
self.receivedContentLength = 0;
16-
self.usingQueue = usingQueue;
16+
self.operationQueue = operationQueue;
1717
self.progressCallback = progressCallback;
1818
self.doneCallback = doneCallback;
1919
self.failCallback = failCallback;
@@ -25,7 +25,7 @@ -(void)download:(NSString*)url {
2525
cachePolicy:NSURLRequestUseProtocolCachePolicy
2626
timeoutInterval:60.0];
2727
NSOperationQueue *delegateQueue = [NSOperationQueue new];
28-
delegateQueue.underlyingQueue = self.usingQueue;
28+
delegateQueue.underlyingQueue = self.operationQueue;
2929
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request
3030
delegate:self
3131
startImmediately:NO];

ios/CodePush/CodePushPackage.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ + (void)downloadAndReplaceCurrentBundle:(NSString *)remoteBundleUrl
4141

4242
+ (void)downloadPackage:(NSDictionary *)updatePackage
4343
expectedBundleFileName:(NSString *)expectedBundleFileName
44-
usingQueue:(dispatch_queue_t)usingQueue
44+
operationQueue:(dispatch_queue_t)operationQueue
4545
progressCallback:(void (^)(long long, long long))progressCallback
4646
doneCallback:(void (^)())doneCallback
4747
failCallback:(void (^)(NSError *err))failCallback
@@ -72,7 +72,7 @@ + (void)downloadPackage:(NSDictionary *)updatePackage
7272

7373
CodePushDownloadHandler *downloadHandler = [[CodePushDownloadHandler alloc]
7474
init:downloadFilePath
75-
usingQueue:usingQueue
75+
operationQueue:operationQueue
7676
progressCallback:progressCallback
7777
doneCallback:^(BOOL isZip) {
7878
NSError *error = nil;

0 commit comments

Comments
 (0)