Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8377)

Unified Diff: chrome/installer/mac/app/NetworkCommunication.m

Issue 2094583004: Initial commit for Chrome metainstaller on Mac. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Made small changes according to LGTM comments Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/installer/mac/app/NetworkCommunication.h ('k') | chrome/installer/mac/app/OWNERS » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..d19566a1e0188cd7a0d61bbbd0f09abc39275e02
--- /dev/null
+++ b/chrome/installer/mac/app/NetworkCommunication.m
@@ -0,0 +1,65 @@
+// 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>
+
+#import "NetworkCommunication.h"
+
+@implementation NetworkCommunication : NSObject
+
+@synthesize session = session_;
+@synthesize request = request_;
+@synthesize dataResponseHandler = dataResponseHandler_;
+@synthesize downloadResponseHandler = 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 {
+ 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_;
+}
+
+- (void)sendDataRequestWithCompletionHandler:
+ (DataTaskCompletionHandler)completionHandler {
+ dataResponseHandler_ = completionHandler;
+ NSURLSessionDataTask* dataTask =
+ [session_ dataTaskWithRequest:request_
+ completionHandler:dataResponseHandler_];
+
+ [dataTask resume];
+}
+
+- (void)sendDownloadRequest {
+ NSURLSessionDownloadTask* downloadTask;
+ if (downloadResponseHandler_) {
+ downloadTask = [session_ downloadTaskWithRequest:request_
+ completionHandler:downloadResponseHandler_];
+ } else {
+ downloadTask = [session_ downloadTaskWithRequest:request_];
+ }
+ [downloadTask resume];
+}
+
+@end
« no previous file with comments | « chrome/installer/mac/app/NetworkCommunication.h ('k') | chrome/installer/mac/app/OWNERS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698