Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5050)

Unified Diff: chrome/installer/mac/app/delegate.m

Issue 2094583004: Initial commit for Chrome metainstaller on Mac. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fully addressed making the .dmg download asynchronously Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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
+

Powered by Google App Engine
This is Rietveld 408576698