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