| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "OmahaXMLParser.h" | 5 #import "OmahaXMLParser.h" |
| 6 | 6 |
| 7 @interface OmahaXMLParser ()<NSXMLParserDelegate> | 7 @interface OmahaXMLParser ()<NSXMLParserDelegate> |
| 8 @end | 8 @end |
| 9 | 9 |
| 10 @implementation OmahaXMLParser { | 10 @implementation OmahaXMLParser { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 } | 25 } |
| 26 | 26 |
| 27 NSMutableArray* completeDownloadURLs = [[NSMutableArray alloc] init]; | 27 NSMutableArray* completeDownloadURLs = [[NSMutableArray alloc] init]; |
| 28 for (NSString* URL in omahaParser->chromeIncompleteDownloadURLs_) { | 28 for (NSString* URL in omahaParser->chromeIncompleteDownloadURLs_) { |
| 29 [completeDownloadURLs | 29 [completeDownloadURLs |
| 30 addObject:[NSURL URLWithString:omahaParser->chromeImageFilename_ | 30 addObject:[NSURL URLWithString:omahaParser->chromeImageFilename_ |
| 31 relativeToURL:[NSURL URLWithString:URL]]]; | 31 relativeToURL:[NSURL URLWithString:URL]]]; |
| 32 } | 32 } |
| 33 | 33 |
| 34 if ([completeDownloadURLs count] < 1) { | 34 if ([completeDownloadURLs count] < 1) { |
| 35 // TODO: currently whatever error is passed in doesn't matter... we should | 35 // TODO: The below error exists only so the caller of this method would |
| 36 // make it so that the type of error informs what the installer will do | 36 // catch the error created here. A better way to handle this is to make the |
| 37 // about the error | 37 // error's contents inform what the installer will try next when it attempts |
| 38 // to recover from an issue. |
| 38 *error = [NSError errorWithDomain:@"ChromeErrorDomain" code:1 userInfo:nil]; | 39 *error = [NSError errorWithDomain:@"ChromeErrorDomain" code:1 userInfo:nil]; |
| 39 return nil; | 40 return nil; |
| 40 } | 41 } |
| 41 | 42 |
| 42 return completeDownloadURLs; | 43 return completeDownloadURLs; |
| 43 } | 44 } |
| 44 | 45 |
| 45 // Method implementation for XMLParserDelegate. | |
| 46 // Searches the XML data for the tag "URL" and the subsequent "codebase" | 46 // Searches the XML data for the tag "URL" and the subsequent "codebase" |
| 47 // attribute that indicates a URL follows. Copies each URL into an array. | 47 // attribute that indicates a URL follows. Copies each URL into an array. |
| 48 // Note that the URLs in the XML file are incomplete. They need the filename | 48 // NOTE: The URLs in the XML file are incomplete. They need the filename |
| 49 // appended to end. The second if statement checks for the tag "package" which | 49 // appended to end. The second if statement checks for the tag "package" which |
| 50 // contains the filename needed to complete the URLs. | 50 // contains the filename needed to complete the URLs. |
| 51 - (void)parser:(NSXMLParser*)parser | 51 - (void)parser:(NSXMLParser*)parser |
| 52 didStartElement:(NSString*)elementName | 52 didStartElement:(NSString*)elementName |
| 53 namespaceURI:(NSString*)namespaceURI | 53 namespaceURI:(NSString*)namespaceURI |
| 54 qualifiedName:(NSString*)qName | 54 qualifiedName:(NSString*)qName |
| 55 attributes:(NSDictionary*)attributeDict { | 55 attributes:(NSDictionary*)attributeDict { |
| 56 if ([elementName isEqualToString:@"url"]) { | 56 if ([elementName isEqualToString:@"url"]) { |
| 57 if (!chromeIncompleteDownloadURLs_) { | 57 if (!chromeIncompleteDownloadURLs_) { |
| 58 chromeIncompleteDownloadURLs_ = [[NSMutableArray alloc] init]; | 58 chromeIncompleteDownloadURLs_ = [[NSMutableArray alloc] init]; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 69 // If either component of the URL is empty then the complete URL cannot | 69 // If either component of the URL is empty then the complete URL cannot |
| 70 // be generated so both variables are set to nil to flag errors. | 70 // be generated so both variables are set to nil to flag errors. |
| 71 - (void)parserDidEndDocument:(NSXMLParser*)parser { | 71 - (void)parserDidEndDocument:(NSXMLParser*)parser { |
| 72 if (!chromeIncompleteDownloadURLs_ || !chromeImageFilename_) { | 72 if (!chromeIncompleteDownloadURLs_ || !chromeImageFilename_) { |
| 73 chromeIncompleteDownloadURLs_ = nil; | 73 chromeIncompleteDownloadURLs_ = nil; |
| 74 chromeImageFilename_ = nil; | 74 chromeImageFilename_ = nil; |
| 75 } | 75 } |
| 76 } | 76 } |
| 77 | 77 |
| 78 @end | 78 @end |
| OLD | NEW |