| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #import <assert.h> | |
| 6 | |
| 7 #import "DownloadDelegate.h" | |
| 8 #import "Downloader.h" | |
| 9 | |
| 10 @implementation DownloadDelegate : NSObject | |
| 11 | |
| 12 // Skeleton of delegate method to provide download progress updates. | |
| 13 // TODO: Make use of (totalBytesWritten/totalBytesExpectedToWrite)*100 | |
| 14 // to generate download progress percentage. | |
| 15 - (void)URLSession:(NSURLSession*)session | |
| 16 downloadTask:(NSURLSessionDownloadTask*)downloadTask | |
| 17 didWriteData:(int64_t)bytesWritten | |
| 18 totalBytesWritten:(int64_t)totalBytesWritten | |
| 19 totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite { | |
| 20 } | |
| 21 | |
| 22 // Delegate method to move downloaded disk image to user's Download directory. | |
| 23 - (void)URLSession:(NSURLSession*)session | |
| 24 downloadTask:(NSURLSessionDownloadTask*)downloadTask | |
| 25 didFinishDownloadingToURL:(NSURL*)location { | |
| 26 assert([location isFileURL]); | |
| 27 NSFileManager* manager = [[NSFileManager alloc] init]; | |
| 28 NSURL* downloadsDirectory = | |
| 29 [[NSURL alloc] initFileURLWithPath:[Downloader getDownloadsFilePath]]; | |
| 30 if ([manager fileExistsAtPath:location.path]) { | |
| 31 [manager copyItemAtURL:location toURL:downloadsDirectory error:nil]; | |
| 32 } else { | |
| 33 // TODO: Error Handling | |
| 34 } | |
| 35 } | |
| 36 | |
| 37 - (void)URLSession:(NSURLSession*)session | |
| 38 task:(NSURLSessionTask*)task | |
| 39 didCompleteWithError:(NSError*)error { | |
| 40 // TODO: Error Handling | |
| 41 } | |
| 42 @end | |
| OLD | NEW |