Chromium Code Reviews| Index: chrome/installer/mac/app/OmahaCommunication.m |
| diff --git a/chrome/installer/mac/app/OmahaCommunication.m b/chrome/installer/mac/app/OmahaCommunication.m |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..705cb18f76603aff4244642a8a29c6c962f0d6b6 |
| --- /dev/null |
| +++ b/chrome/installer/mac/app/OmahaCommunication.m |
| @@ -0,0 +1,57 @@ |
| +// 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> |
|
Mark Mentovai
2016/07/11 17:56:16
#import "OmahaCommunication.h"
(blank line)
#
|
| +#include "OmahaCommunication.h" |
| + |
| +@implementation OmahaCommunication : NSObject |
| + |
| +@synthesize requestXMLBody = requestXMLBody_; |
| +@synthesize sessionHelper = sessionHelper_; |
| + |
| +- (id)init { |
| + return [self initWithBody:[[NSXMLDocument alloc] init]]; |
| +} |
| + |
| +- (id)initWithBody:(NSXMLDocument*)xmlBody { |
| + if ((self = [super init])) { |
| + sessionHelper_ = [[NetworkCommunication alloc] init]; |
| + requestXMLBody_ = xmlBody; |
| + [self createOmahaRequest]; |
| + } |
| + return self; |
| +} |
| + |
| +- (NSURLRequest*)createOmahaRequest { |
| + NSMutableURLRequest* request = [sessionHelper_ |
| + 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,
|
| + andXMLBody:requestXMLBody_]; |
| + request.HTTPMethod = @"POST"; |
| + return request; |
| +} |
| + |
| +- (void)sendRequestWithBlock:(OmahaRequestCompletionHandler)block { |
| + DataTaskCompletionHandler cHandler = |
| + ^(NSData* _Nullable data, NSURLResponse* _Nullable response, |
| + NSError* _Nullable error) { |
| + if (error) { |
| + NSLog(@"%@", error); |
| + block(data, error); |
| + return; |
| + } |
| + |
| + NSHTTPURLResponse* HTTPResponse = (NSHTTPURLResponse*)response; |
| + if (HTTPResponse.statusCode != 200) { |
| + // TODO: make these logging statements more rare |
| + NSLog(@"HTTP response: %ld", (unsigned long)HTTPResponse.statusCode); |
| + } |
| + |
| + block(data, error); |
| + |
| + }; |
| + |
| + [sessionHelper_ sendDataRequestWithCompletionHandler:cHandler]; |
| +} |
| + |
| +@end |