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 "DownloadDelegate.h" | |
Mark Mentovai
2016/07/11 17:56:16
DownloadDelegate.m should #import/#include like th
| |
6 #import "downloader.h" | |
7 #import <assert.h> | |
8 | |
9 @implementation DownloadDelegate : NSObject | |
10 | |
11 // Skeleton of delegate method to provide download progress updates. | |
12 // TODO: Make use of (totalBytesWritten/totalBytesExpectedToWrite)*100 | |
13 // to generate download progress percentage. | |
14 - (void)URLSession:(NSURLSession*)session | |
15 downloadTask:(NSURLSessionDownloadTask*)downloadTask | |
16 didWriteData:(int64_t)bytesWritten | |
17 totalBytesWritten:(int64_t)totalBytesWritten | |
18 totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite { | |
19 } | |
20 | |
21 // Delegate method to move downloaded disk image to user's Download directory. | |
22 - (void)URLSession:(NSURLSession*)session | |
23 downloadTask:(NSURLSessionDownloadTask*)downloadTask | |
24 didFinishDownloadingToURL:(NSURL*)location { | |
25 assert([location isFileURL]); | |
26 NSFileManager* manager = [[NSFileManager alloc] init]; | |
27 NSURL* downloadsDirectory = | |
28 [[NSURL alloc] initFileURLWithPath:[Downloader getDownloadsFilePath]]; | |
29 if ([manager fileExistsAtPath:location.path]) { | |
30 [manager copyItemAtURL:location toURL:downloadsDirectory error:nil]; | |
31 } else { | |
32 // TODO: Error Handling | |
33 } | |
34 } | |
35 | |
36 - (void)URLSession:(NSURLSession*)session | |
37 task:(NSURLSessionTask*)task | |
38 didCompleteWithError:(NSError*)error { | |
39 // TODO: Error Handling | |
40 } | |
41 @end | |
OLD | NEW |