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

Unified Diff: chrome/installer/mac/app/downloader.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/downloader.m
diff --git a/chrome/installer/mac/app/downloader.m b/chrome/installer/mac/app/downloader.m
new file mode 100644
index 0000000000000000000000000000000000000000..c7ec390b173be2050ee70449023604ff5890cf66
--- /dev/null
+++ b/chrome/installer/mac/app/downloader.m
@@ -0,0 +1,67 @@
+// 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 <Foundation/Foundation.h>
+#import "downloader.h"
+#import "parser.h"
+#import "NetworkCommunication.h"
+#import "delegate.h"
+
+@implementation Downloader
+
+// The URLs extracted from parseXML are incomplete and need the filename (which
+// is the same for all the links) appended to the end. Iterates through
+// chromeIncompleteDownloadURLs_ and appends chromeImageFilename_ to each URL.
+- (NSMutableArray*)appendFilename:(NSString*)filename
+ toURLs:(NSArray*)incompleteURLs {
+ NSMutableArray* completeURLs = [[NSMutableArray alloc] init];
+
+ for (NSString* URL in incompleteURLs) {
+ [completeURLs addObject: [NSString stringWithFormat:@"%@%@",URL,filename]];
Elly Fong-Jones 2016/07/06 15:22:02 no space after : (in the rest of this file, too)
+ }
+ return completeURLs;
+}
+
+// Calls parseXML to extract URLs and the filename. Then calls appenFilename to
Elly Fong-Jones 2016/07/06 15:22:02 It's better for the comment to describe what the f
+// complete the URLs and returns the first complete URL.
+- (NSURL*)parseOhamaResponseForChromeImageURLAndFilename:(NSData*)omahaResponseXML {
Elly Fong-Jones 2016/07/06 15:22:02 getChromeImageURLFromOmahaResponse:?
+ Parser* parser = [[Parser alloc] initWithXML: omahaResponseXML];
+ [parser parseXML];
+
+ NSMutableArray* completeURLs =
+ [self appendFilename:parser.chromeImageFilename
+ toURLs:parser.chromeIncompleteDownloadURLs];
+ // TODO: Error handling and implement way to verify URL is working
+ if(!completeURLs || [completeURLs count] < 1) {
+ NSLog(@"There were no download links found.");
+ return nil;
+ }
+ NSString* chromeURLString = [completeURLs firstObject];
+ return [NSURL URLWithString:chromeURLString];
+}
+
+// Downloads contents of chromeURL to downloads folders and delegates the work
+// to the DownloadDelegate class.
+- (void)writeChromeImageToDownloadsDirectory:(NSURL*)chromeURL {
+ DownloadDelegate *delegate = [[DownloadDelegate alloc] init];
+ NetworkCommunication* downloadTask = [[NetworkCommunication alloc]
+ initWithDelegate: delegate];
+
+ // TODO: What if file already exists?
+ [downloadTask createRequestWithURLasString:[NSString
+ stringWithFormat:@"%@",chromeURL] andXMLBody: nil];
+ [downloadTask sendDownloadRequest];
+
+ NSLog(@"File was downloaded to Downloads.");
+}
+
+// Pieces together the getting the URL portion and downloading the contents of
+// URL portion.
+- (void)downloadChromeImageToDownloadsDirectory: (NSData*)responseXMLData {
+ NSURL* chromeURL = [self
+ parseOhamaResponseForChromeImageURLAndFilename: responseXMLData];
+ [self writeChromeImageToDownloadsDirectory: chromeURL];
+}
+
+@end

Powered by Google App Engine
This is Rietveld 408576698