Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #import <Foundation/Foundation.h> | |
| 6 #include "OmahaCommunication.h" | |
| 7 | |
| 8 @implementation OmahaCommunication : NSObject | |
| 9 | |
| 10 @synthesize requestXMLBody; | |
| 11 @synthesize sessionHelper; | |
| 12 | |
| 13 - (id)init { | |
| 14 return [self initWithBody:[[NSXMLDocument alloc] init]]; | |
| 15 } | |
| 16 - (id)initWithBody:(NSXMLDocument*) xmlBody { | |
| 17 if ((self = [super init])) { | |
| 18 sessionHelper = [[NetworkCommunication alloc] init]; | |
| 19 requestXMLBody = xmlBody; | |
| 20 } | |
| 21 return self; | |
| 22 } | |
| 23 | |
| 24 - (NSURLRequest*)createOmahaRequest { | |
| 25 NSMutableURLRequest* request = [sessionHelper | |
|
Elly Fong-Jones
2016/07/06 15:22:01
Hm, is there a reason for this function to be sepa
| |
| 26 createRequestWithURLasString:@"https://tools.google.com/service/update2" | |
|
Elly Fong-Jones
2016/07/06 15:22:02
this should probably be a constant somewhere, and
Anna Zeng
2016/07/07 15:24:53
how do we accomplish this?
| |
| 27 andXMLBody:requestXMLBody]; | |
| 28 request.HTTPMethod = @"POST"; | |
| 29 return request; | |
| 30 } | |
| 31 | |
| 32 - (void)setResponseHandlingWithBlock:(AfterBlock)blockToRunAfter { | |
| 33 DataTaskCompletionHandler cHandler = ^(NSData* _Nullable data, | |
| 34 NSURLResponse* _Nullable response, | |
| 35 NSError* _Nullable error) { | |
| 36 if(error) { | |
|
Elly Fong-Jones
2016/07/06 15:22:02
I think we need to notify the user of this class t
| |
| 37 NSLog(@"%@", error); | |
| 38 return; | |
| 39 } | |
| 40 | |
| 41 NSHTTPURLResponse* HTTPResponse = (NSHTTPURLResponse*)response; | |
| 42 if(HTTPResponse.statusCode != 200) { | |
| 43 NSLog(@"HTTP response: %ld", (unsigned long)HTTPResponse.statusCode); | |
| 44 return; | |
|
Elly Fong-Jones
2016/07/06 15:22:01
same comment - we need a better way to indicate th
| |
| 45 } | |
| 46 | |
| 47 // run block here | |
|
Elly Fong-Jones
2016/07/06 15:22:01
this comment doesn't seem like it adds much to und
| |
| 48 blockToRunAfter(data); | |
| 49 | |
| 50 }; | |
| 51 | |
| 52 [sessionHelper setDataResponseHandler:cHandler]; | |
| 53 } | |
| 54 | |
| 55 - (void)sendRequest { | |
| 56 [sessionHelper sendDataRequest]; | |
|
Elly Fong-Jones
2016/07/06 15:22:01
I could collapse this and setResponseHandlingWithB
| |
| 57 } | |
| 58 | |
| 59 @end | |
| OLD | NEW |