Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 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 <Foundation/Foundation.h> | |
| 6 #import "downloader.h" | |
| 7 #import "parser.h" | |
| 8 | |
| 9 NSURL* getChromeImageURL(NSData* someData) { | |
| 10 Parser *parser = [[Parser alloc] init]; | |
| 11 [parser parseXML:someData]; | |
| 12 [parser appendFilenameToURL]; | |
| 13 | |
| 14 NSArray *downloadLinks = [NSArray arrayWithArray: parser.chromeDownloadURLs]; | |
|
Elly Fong-Jones
2016/06/24 17:26:01
no space after colon
| |
| 15 NSString *chromeURLString = [downloadLinks firstObject]; | |
|
Elly Fong-Jones
2016/06/24 17:26:01
can downloadLinks ever be empty? What if parser fa
| |
| 16 | |
| 17 return [NSURL URLWithString: chromeURLString]; | |
| 18 } | |
| 19 | |
| 20 NSData* downloadChromeAsData(NSURL* chromeURL) { | |
| 21 return [NSData dataWithContentsOfURL:chromeURL]; | |
|
Elly Fong-Jones
2016/06/24 17:26:01
[NSData dataWithContentsOfURL:] will do the entire
| |
| 22 } | |
| 23 | |
| 24 NSString* getDownloadsFilePath() { | |
| 25 NSArray *downloadPaths = NSSearchPathForDirectoriesInDomains( | |
| 26 NSDownloadsDirectory, NSUserDomainMask, YES); | |
| 27 NSString *downloadDirectory = [downloadPaths objectAtIndex:0]; | |
| 28 NSString *filePath = [NSString stringWithFormat:@"%@/%@", | |
| 29 downloadDirectory, @"GoogleChrome.dmg"]; | |
|
Elly Fong-Jones
2016/06/24 17:26:01
I think it would be nicer to use [NSString pathWit
| |
| 30 return filePath; | |
| 31 } | |
| 32 | |
| 33 void writeDataToDisk(NSData* topSecretData) { | |
|
Elly Fong-Jones
2016/06/24 17:26:01
is it really top secret? :)
| |
| 34 if (topSecretData) { | |
| 35 NSString *filePath = getDownloadsFilePath(); | |
| 36 [topSecretData writeToFile:filePath atomically:YES]; | |
| 37 NSLog(@"File was downloaded to %@.", filePath); | |
| 38 } else { | |
| 39 NSLog(@"Error downloading file."); | |
| 40 } | |
| 41 } | |
| OLD | NEW |