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

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: Fixed majority of comments excluding refactoring for blocks in main. 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
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..a1f95b11529ab36e3478ca71a0ed7df2727ae166
--- /dev/null
+++ b/chrome/installer/mac/app/NetworkCommunication.m
@@ -0,0 +1,73 @@
+// 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;
Mark Mentovai 2016/07/07 17:53:48 Please name the variables that back your propertie
+@synthesize request;
+@synthesize dataResponseHandler;
+@synthesize downloadResponseHandler;
+
+- (id)init {
+ return [self initWithDelegate:nil];
+}
+
+- (id)initWithDelegate:(id) delegate {
+ if ((self = [super init])) {
+ NSURLSessionConfiguration* sessionConfig = [NSURLSessionConfiguration
Mark Mentovai 2016/07/07 17:53:48 Both sessionConfig and session are autoreleased, s
+ defaultSessionConfiguration];
+ session = [NSURLSession sessionWithConfiguration:sessionConfig
+ delegate:delegate
+ delegateQueue:nil];
+ }
+ return self;
+}
+
+- (NSMutableURLRequest*)createRequestWithURLasString:(NSString*) urlString
+ andXMLBody:(NSXMLDocument*) body {
+ if (request) {
Mark Mentovai 2016/07/07 17:53:48 When would this ever happen?
+ [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;
+}
+
+- (void)sendDataRequestWithCompletionHandler:
+ (DataTaskCompletionHandler) completionHandler {
+ dataResponseHandler = completionHandler;
+ NSURLSessionDataTask* dataTask = [session dataTaskWithRequest:request
+ completionHandler:dataResponseHandler];
+
+ [dataTask resume];
+ return;
+}
+
+- (void)sendDownloadRequest {
+ NSURLSessionDownloadTask* downloadTask;
+ if (downloadResponseHandler) {
+ downloadTask =
+ [session downloadTaskWithRequest:request
+ completionHandler:downloadResponseHandler];
+ } else {
+ downloadTask =
+ [session downloadTaskWithRequest:request];
+ }
+ [downloadTask resume];
+
+ return;
+}
+
+@end

Powered by Google App Engine
This is Rietveld 408576698