Chromium Code Reviews| 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" | |
| 6 #import "downloader.h" | |
| 7 | |
| 8 @implementation DownloadDelegate : NSObject | |
| 9 | |
| 10 // Skeleton of delegate method to provide download progress updates. | |
| 11 // TODO: Make use of (totalBytesWritten/totalBytesExpectedToWrite)*100 | |
| 12 // to generate download progress percentage. | |
| 13 - (void)URLSession:(NSURLSession*)session | |
| 14 downloadTask:(NSURLSessionDownloadTask*)downloadTask | |
| 15 didWriteData:(int64_t)bytesWritten | |
| 16 totalBytesWritten:(int64_t)totalBytesWritten | |
| 17 totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite{ | |
| 18 | |
| 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 NSFileManager* manager = [[NSFileManager alloc] init]; | |
|
Mark Mentovai
2016/07/07 17:53:48
Background reading on scoped_nsobject<>, although
| |
| 26 NSString* temporaryDownloadDirectory = [NSString stringWithFormat:@"%@", | |
|
Mark Mentovai
2016/07/07 17:53:48
location.path should give you an NSString*, you do
| |
| 27 location.path]; | |
| 28 NSURL* downloadsDirectory = [[NSURL alloc] initFileURLWithPath:[Downloader | |
| 29 getDownloadsFi lePath]]; | |
| 30 if ( [manager fileExistsAtPath:temporaryDownloadDirectory] ){ | |
| 31 [manager copyItemAtURL:location toURL:downloadsDirectory error:nil]; | |
|
Mark Mentovai
2016/07/07 17:53:48
What happens to the original temporary copy?
| |
| 32 NSLog(@"File was downloaded to Downloads."); | |
|
Mark Mentovai
2016/07/07 17:53:48
We shouldn’t check in logging like this.
| |
| 33 } else { | |
| 34 // TODO: Error Handling | |
| 35 } | |
| 36 | |
| 37 } | |
| 38 | |
| 39 - (void)URLSession:(NSURLSession *)session | |
| 40 task:(NSURLSessionTask *)task | |
| 41 didCompleteWithError:(NSError *)error{ | |
| 42 // TODO: Error Handling | |
| 43 } | |
| 44 @end | |
| 45 | |
| OLD | NEW |