Index: chrome/installer/mac/app/NetworkCommunication.m |
diff --git a/chrome/installer/mac/app/NetworkCommunication.m b/chrome/installer/mac/app/NetworkCommunication.m |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2fb9b81fec8c2ca88d7ba209bf83c276f869f4aa |
--- /dev/null |
+++ b/chrome/installer/mac/app/NetworkCommunication.m |
@@ -0,0 +1,72 @@ |
+// 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> |
+#include "NetworkCommunication.h" |
+ |
+@implementation NetworkCommunication : NSObject |
+ |
+// The following variables each have getters and setters, so when this class |
+// is in use, please don't forget to set the response handler! |
+@synthesize session; |
+@synthesize request; |
+@synthesize dataResponseHandler; |
+@synthesize downloadResponseHandler; |
+ |
+- (id)init { |
+ return [self initWithDelegate:nil]; |
+} |
+ |
+- (id)initWithDelegate:(id) delegate { |
+ if ((self = [super init])) { |
+ NSURLSessionConfiguration* sessionConfig = [NSURLSessionConfiguration |
+ defaultSessionConfiguration]; |
+ session = [NSURLSession sessionWithConfiguration:sessionConfig |
+ delegate:delegate |
+ delegateQueue:nil]; |
+ } |
+ return self; |
+} |
+ |
+- (NSMutableURLRequest*)createRequestWithURLasString:(NSString*) urlString |
+ andXMLBody:(NSXMLDocument*) body { |
+ if(request) { |
Elly Fong-Jones
2016/07/06 15:22:01
"if (request", i.e., space after if and before (
|
+ [request autorelease]; |
+ } |
+ NSURL* requestURL = [NSURL URLWithString:urlString]; |
+ request = [NSMutableURLRequest requestWithURL:requestURL]; |
+ if(body) { |
+ [request addValue:@"text/xml" forHTTPHeaderField:@"Content-Type"]; |
+ NSData* requestBody = [[body XMLString] |
+ dataUsingEncoding:NSUTF8StringEncoding]; |
+ request.HTTPBody = requestBody; |
+ } |
+ return request; |
+} |
+ |
+- (NSURLSessionDataTask*)sendDataRequest { |
+ NSURLSessionDataTask* dataTask = [session dataTaskWithRequest:request |
+ completionHandler:dataResponseHandler]; |
+ |
+ [dataTask resume]; |
+ return dataTask; |
+} |
+ |
+- (NSURLSessionDownloadTask*)sendDownloadRequest { |
+ NSURLSessionDownloadTask* downloadTask; |
+ if(downloadResponseHandler) { |
+ downloadTask = |
+ [session downloadTaskWithRequest:request |
+ completionHandler:downloadResponseHandler]; |
+ } else { |
+ downloadTask = |
+ [session downloadTaskWithRequest:request]; |
+ } |
+ |
+ [downloadTask resume]; |
+ |
Elly Fong-Jones
2016/07/06 15:22:01
no blank line needed here
|
+ return downloadTask; |
+} |
+ |
+@end |