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 "delegate.h" | |
| 6 | |
| 7 @implementation DownloadDelegate : NSObject | |
| 8 // Returns a path to a user's home download folder. | |
| 9 - (NSString*)getDownloadsFilePath { | |
|
Elly Fong-Jones
2016/07/06 15:22:02
This should probably be override-able somehow (com
| |
| 10 NSArray* downloadPaths = NSSearchPathForDirectoriesInDomains( | |
| 11 NSDownloadsDirectory, NSUserDomainMask, YES); | |
| 12 NSString* filePathToDownloads = [downloadPaths objectAtIndex:0]; | |
| 13 NSArray* filenameComposition = @[filePathToDownloads, @"GoogleChrome.dmg"]; | |
| 14 NSString* completeFilePath = [NSString pathWithComponents: | |
| 15 filenameComposition]; | |
| 16 return completeFilePath; | |
| 17 } | |
| 18 | |
| 19 // Skeleton of delegate method to provide download progress updates. | |
| 20 // TODO: Make use of (totalBytesWritten/totalBytesExpectedToWrite)*100 | |
| 21 // to generate download progress percentage. | |
| 22 - (void)URLSession:(NSURLSession*)session | |
| 23 downloadTask:(NSURLSessionDownloadTask*)downloadTask | |
| 24 didWriteData:(int64_t)bytesWritten | |
| 25 totalBytesWritten:(int64_t)totalBytesWritten | |
| 26 totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite{ | |
| 27 | |
| 28 } | |
| 29 | |
| 30 // Delegate method to move downloaded disk image to user's Download directory. | |
| 31 - (void)URLSession:(NSURLSession*)session | |
| 32 downloadTask:(NSURLSessionDownloadTask*)downloadTask | |
| 33 didFinishDownloadingToURL:(NSURL*)location{ | |
| 34 NSFileManager* manager = [[NSFileManager alloc] init]; | |
| 35 NSString* temporaryDownloadDirectory = [NSString | |
| 36 stringWithFormat:@"%@",location.path]; | |
| 37 NSURL* downloadsDirectory = [[NSURL alloc] | |
| 38 initFileURLWithPath:[self getDownloadsFilePath]]; | |
| 39 | |
| 40 if ( [manager isReadableFileAtPath:temporaryDownloadDirectory] ) | |
| 41 [manager copyItemAtURL:location toURL:downloadsDirectory error:nil]; | |
|
Elly Fong-Jones
2016/07/06 15:22:02
What do we do if it's not?
| |
| 42 } | |
| 43 @end | |
| 44 | |
| OLD | NEW |