Chromium Code Reviews| Index: chrome/installer/mac/app/delegate.m |
| diff --git a/chrome/installer/mac/app/delegate.m b/chrome/installer/mac/app/delegate.m |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3e520a1f2b7ed2a37e793b558dccbaec39cfc4ac |
| --- /dev/null |
| +++ b/chrome/installer/mac/app/delegate.m |
| @@ -0,0 +1,44 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#import "delegate.h" |
| + |
| +@implementation DownloadDelegate : NSObject |
| +// Returns a path to a user's home download folder. |
| +- (NSString*)getDownloadsFilePath { |
|
Elly Fong-Jones
2016/07/06 15:22:02
This should probably be override-able somehow (com
|
| + NSArray* downloadPaths = NSSearchPathForDirectoriesInDomains( |
| + NSDownloadsDirectory, NSUserDomainMask, YES); |
| + NSString* filePathToDownloads = [downloadPaths objectAtIndex:0]; |
| + NSArray* filenameComposition = @[filePathToDownloads, @"GoogleChrome.dmg"]; |
| + NSString* completeFilePath = [NSString pathWithComponents: |
| + filenameComposition]; |
| + return completeFilePath; |
| +} |
| + |
| +// Skeleton of delegate method to provide download progress updates. |
| +// TODO: Make use of (totalBytesWritten/totalBytesExpectedToWrite)*100 |
| +// to generate download progress percentage. |
| +- (void)URLSession:(NSURLSession*)session |
| + downloadTask:(NSURLSessionDownloadTask*)downloadTask |
| + didWriteData:(int64_t)bytesWritten |
| + totalBytesWritten:(int64_t)totalBytesWritten |
| +totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite{ |
| + |
| +} |
| + |
| +// Delegate method to move downloaded disk image to user's Download directory. |
| +- (void)URLSession:(NSURLSession*)session |
| + downloadTask:(NSURLSessionDownloadTask*)downloadTask |
| +didFinishDownloadingToURL:(NSURL*)location{ |
| + NSFileManager* manager = [[NSFileManager alloc] init]; |
| + NSString* temporaryDownloadDirectory = [NSString |
| + stringWithFormat:@"%@",location.path]; |
| + NSURL* downloadsDirectory = [[NSURL alloc] |
| + initFileURLWithPath:[self getDownloadsFilePath]]; |
| + |
| + if ( [manager isReadableFileAtPath:temporaryDownloadDirectory] ) |
| + [manager copyItemAtURL:location toURL:downloadsDirectory error:nil]; |
|
Elly Fong-Jones
2016/07/06 15:22:02
What do we do if it's not?
|
| +} |
| +@end |
| + |