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> | |
Mark Mentovai
2016/07/11 17:56:16
#import "OmahaCommunication.h"
(blank line)
#
| |
6 #include "OmahaCommunication.h" | |
7 | |
8 @implementation OmahaCommunication : NSObject | |
9 | |
10 @synthesize requestXMLBody = requestXMLBody_; | |
11 @synthesize sessionHelper = sessionHelper_; | |
12 | |
13 - (id)init { | |
14 return [self initWithBody:[[NSXMLDocument alloc] init]]; | |
15 } | |
16 | |
17 - (id)initWithBody:(NSXMLDocument*)xmlBody { | |
18 if ((self = [super init])) { | |
19 sessionHelper_ = [[NetworkCommunication alloc] init]; | |
20 requestXMLBody_ = xmlBody; | |
21 [self createOmahaRequest]; | |
22 } | |
23 return self; | |
24 } | |
25 | |
26 - (NSURLRequest*)createOmahaRequest { | |
27 NSMutableURLRequest* request = [sessionHelper_ | |
28 createRequestWithUrlAsString:@"https://tools.google.com/service/update2" | |
Elly Fong-Jones
2016/07/11 16:15:48
We will want this to be a command-line flag later,
| |
29 andXMLBody:requestXMLBody_]; | |
30 request.HTTPMethod = @"POST"; | |
31 return request; | |
32 } | |
33 | |
34 - (void)sendRequestWithBlock:(OmahaRequestCompletionHandler)block { | |
35 DataTaskCompletionHandler cHandler = | |
36 ^(NSData* _Nullable data, NSURLResponse* _Nullable response, | |
37 NSError* _Nullable error) { | |
38 if (error) { | |
39 NSLog(@"%@", error); | |
40 block(data, error); | |
41 return; | |
42 } | |
43 | |
44 NSHTTPURLResponse* HTTPResponse = (NSHTTPURLResponse*)response; | |
45 if (HTTPResponse.statusCode != 200) { | |
46 // TODO: make these logging statements more rare | |
47 NSLog(@"HTTP response: %ld", (unsigned long)HTTPResponse.statusCode); | |
48 } | |
49 | |
50 block(data, error); | |
51 | |
52 }; | |
53 | |
54 [sessionHelper_ sendDataRequestWithCompletionHandler:cHandler]; | |
55 } | |
56 | |
57 @end | |
OLD | NEW |