Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions Parse/Internal/File/PFFile_Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@

@class BFTask;

NS_ASSUME_NONNULL_BEGIN

@interface PFFile (Private)

@property (nonatomic, strong, readonly) PFFileState *state;

+ (instancetype)fileWithName:(NSString *)name url:(NSString *)url;
+ (instancetype)fileWithName:(nullable NSString *)name url:(nullable NSString *)url;

//
// Download
- (BFTask *)_getDataAsyncWithProgressBlock:(PFProgressBlock)block;
- (NSString *)_cachedFilePath;
- (nullable NSString *)_cachedFilePath;

@end

NS_ASSUME_NONNULL_END
42 changes: 12 additions & 30 deletions Parse/PFFile.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ @interface PFFile () {

@implementation PFFile

@synthesize stagedFilePath=_stagedFilePath;
@synthesize stagedFilePath = _stagedFilePath;

///--------------------------------------
#pragma mark - Public
Expand Down Expand Up @@ -114,14 +114,6 @@ + (instancetype)fileWithData:(NSData *)data contentType:(NSString *)contentType
return [self fileWithName:nil data:data contentType:contentType];
}

#pragma mark Dealloc

- (void)dealloc {
#if !OS_OBJECT_USE_OBJC
dispatch_release(_synchronizationQueue);
#endif
}

#pragma mark Uploading

- (BOOL)save {
Expand Down Expand Up @@ -315,13 +307,13 @@ - (BFTask *)_uploadFileAsyncWithSessionToken:(NSString *)sessionToken
#pragma mark Download

- (BFTask *)_getDataAsyncWithProgressBlock:(PFProgressBlock)progressBlock {
return [[self _downloadAsyncWithProgressBlock:progressBlock] continueAsyncWithSuccessBlock:^id(BFTask *task) {
return [[self _downloadAsyncWithProgressBlock:progressBlock] continueWithSuccessBlock:^id(BFTask *task) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this async before? Wasn't it to ensure that all the progress block ticks finished?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, not really... It was attached to PFTaskQueue vs PFAsyncTaskQueue, which was safer to use with async APIs.
It's no longer needed. downloadAsync already performs on the background thread, so there is basically no need to do this scheduling here.

return [self _cachedData];
}];
}

- (BFTask *)_getDataStreamAsyncWithProgressBlock:(PFProgressBlock)progressBlock {
return [[self _downloadAsyncWithProgressBlock:progressBlock] continueAsyncWithSuccessBlock:^id(BFTask *task) {
return [[self _downloadAsyncWithProgressBlock:progressBlock] continueWithSuccessBlock:^id(BFTask *task) {
return [self _cachedDataStream];
}];
}
Expand All @@ -335,23 +327,6 @@ - (BFTask *)_downloadAsyncWithProgressBlock:(PFProgressBlock)progressBlock {
cancellationToken = self.cancellationTokenSource.token;
}];

return [self _downloadAsyncWithCancellationToken:cancellationToken progressBlock:progressBlock];
}

- (BFTask *)_downloadStreamAsyncWithProgressBlock:(PFProgressBlock)progressBlock {
__block BFCancellationToken *cancellationToken = nil;
[self _performDataAccessBlock:^{
if (!self.cancellationTokenSource || self.cancellationTokenSource.cancellationRequested) {
self.cancellationTokenSource = [BFCancellationTokenSource cancellationTokenSource];
}
cancellationToken = self.cancellationTokenSource.token;
}];

return [self _downloadStreamAsyncWithCancellationToken:cancellationToken progressBlock:progressBlock];
}

- (BFTask *)_downloadAsyncWithCancellationToken:(BFCancellationToken *)cancellationToken
progressBlock:(PFProgressBlock)progressBlock {
@weakify(self);
return [self.taskQueue enqueue:^id(BFTask *task) {
@strongify(self);
Expand All @@ -372,8 +347,15 @@ - (BFTask *)_downloadAsyncWithCancellationToken:(BFCancellationToken *)cancellat
}];
}

- (BFTask *)_downloadStreamAsyncWithCancellationToken:(BFCancellationToken *)cancellationToken
progressBlock:(PFProgressBlock)progressBlock {
- (BFTask *)_downloadStreamAsyncWithProgressBlock:(PFProgressBlock)progressBlock {
__block BFCancellationToken *cancellationToken = nil;
[self _performDataAccessBlock:^{
if (!self.cancellationTokenSource || self.cancellationTokenSource.cancellationRequested) {
self.cancellationTokenSource = [BFCancellationTokenSource cancellationTokenSource];
}
cancellationToken = self.cancellationTokenSource.token;
}];

@weakify(self);
return [self.taskQueue enqueue:^id(BFTask *task) {
@strongify(self);
Expand Down