Index: chrome/installer/mac/app/OmahaCommunication.m |
diff --git a/chrome/installer/mac/app/OmahaCommunication.m b/chrome/installer/mac/app/OmahaCommunication.m |
index 42328902309983d7d8b1aaeecf40676a7f870806..9234c95e342d630f8e9d6b5095c44428e5513885 100644 |
--- a/chrome/installer/mac/app/OmahaCommunication.m |
+++ b/chrome/installer/mac/app/OmahaCommunication.m |
@@ -4,12 +4,13 @@ |
#import <Foundation/Foundation.h> |
-#include "OmahaCommunication.h" |
+#import "OmahaCommunication.h" |
-@implementation OmahaCommunication : NSObject |
+@implementation OmahaCommunication |
@synthesize requestXMLBody = requestXMLBody_; |
@synthesize sessionHelper = sessionHelper_; |
+@synthesize delegate = delegate_; |
- (id)init { |
return [self initWithBody:[[NSXMLDocument alloc] init]]; |
@@ -17,7 +18,7 @@ |
- (id)initWithBody:(NSXMLDocument*)xmlBody { |
if ((self = [super init])) { |
- sessionHelper_ = [[NetworkCommunication alloc] init]; |
Sidney San Martín
2016/07/19 23:19:20
IMHO the NetworkCommunication class works in a pre
Anna Zeng
2016/07/21 18:06:44
Sure thing! Just so you know our mentality behind
|
+ sessionHelper_ = [[NetworkCommunication alloc] initWithDelegate:self]; |
requestXMLBody_ = xmlBody; |
[self createOmahaRequest]; |
} |
@@ -33,27 +34,24 @@ |
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); |
+- (void)sendRequest { |
+ [sessionHelper_ sendDataRequest]; |
+} |
- }; |
+- (void)URLSession:(NSURLSession*)session |
+ dataTask:(NSURLSessionDataTask*)dataTask |
+ didReceiveData:(NSData*)data { |
+ if (!_dataCollected) { |
+ _dataCollected = [[NSMutableData alloc] initWithData:data]; |
+ } else { |
+ [_dataCollected appendData:data]; |
+ } |
+} |
- [sessionHelper_ sendDataRequestWithCompletionHandler:cHandler]; |
+- (void)URLSession:(NSURLSession*)session |
+ task:(NSURLSessionTask*)task |
+ didCompleteWithError:(NSError*)error { |
+ [delegate_ downloadChromeWithData:_dataCollected]; |
} |
@end |