| 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 "Downloader.h" | 5 #import "Downloader.h" |
| 6 | 6 |
| 7 #include <assert.h> | 7 #include <assert.h> |
| 8 | 8 |
| 9 @implementation Downloader | 9 @implementation Downloader |
| 10 | 10 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 - (void)URLSession:(NSURLSession*)session | 26 - (void)URLSession:(NSURLSession*)session |
| 27 downloadTask:(NSURLSessionDownloadTask*)downloadTask | 27 downloadTask:(NSURLSessionDownloadTask*)downloadTask |
| 28 didWriteData:(int64_t)bytesWritten | 28 didWriteData:(int64_t)bytesWritten |
| 29 totalBytesWritten:(int64_t)totalBytesWritten | 29 totalBytesWritten:(int64_t)totalBytesWritten |
| 30 totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite { | 30 totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite { |
| 31 double downloadProgressPercentage = | 31 double downloadProgressPercentage = |
| 32 (double)totalBytesWritten / totalBytesExpectedToWrite * 100.0; | 32 (double)totalBytesWritten / totalBytesExpectedToWrite * 100.0; |
| 33 [delegate_ downloader:self percentProgress:downloadProgressPercentage]; | 33 [delegate_ downloader:self percentProgress:downloadProgressPercentage]; |
| 34 } | 34 } |
| 35 | 35 |
| 36 // Delegate method to move downloaded disk image to user's Download directory. | |
| 37 - (void)URLSession:(NSURLSession*)session | 36 - (void)URLSession:(NSURLSession*)session |
| 38 downloadTask:(NSURLSessionDownloadTask*)downloadTask | 37 downloadTask:(NSURLSessionDownloadTask*)downloadTask |
| 39 didFinishDownloadingToURL:(NSURL*)location { | 38 didFinishDownloadingToURL:(NSURL*)location { |
| 40 assert([location isFileURL]); | 39 assert([location isFileURL]); |
| 41 [delegate_ downloader:self onSuccess:location]; | 40 [delegate_ downloader:self onSuccess:location]; |
| 42 } | 41 } |
| 43 | 42 |
| 44 - (void)URLSession:(NSURLSession*)session | 43 - (void)URLSession:(NSURLSession*)session |
| 45 task:(NSURLSessionTask*)task | 44 task:(NSURLSessionTask*)task |
| 46 didCompleteWithError:(NSError*)error { | 45 didCompleteWithError:(NSError*)error { |
| 47 if (error) { | 46 if (error) { |
| 48 [delegate_ downloader:self onFailure:error]; | 47 [delegate_ downloader:self onFailure:error]; |
| 49 } | 48 } |
| 50 } | 49 } |
| 51 | 50 |
| 52 @end | 51 @end |
| OLD | NEW |