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

Side by Side Diff: chrome/installer/mac/app/NetworkCommunication.m

Issue 2148293005: Migrate mac installer to delegate-driven model (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Last patch before CQ 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import <Foundation/Foundation.h>
6
7 #import "NetworkCommunication.h" 5 #import "NetworkCommunication.h"
8 6
9 @implementation NetworkCommunication : NSObject 7 @implementation NetworkCommunication : NSObject
10 8
11 @synthesize session = session_; 9 @synthesize session = session_;
12 @synthesize request = request_; 10 @synthesize request = request_;
13 @synthesize dataResponseHandler = dataResponseHandler_; 11 @synthesize dataResponseHandler = dataResponseHandler_;
14 @synthesize downloadResponseHandler = downloadResponseHandler_;
15 12
16 - (id)init { 13 - (id)init {
17 return [self initWithDelegate:nil]; 14 return [self initWithDelegate:nil];
18 } 15 }
19 16
20 - (id)initWithDelegate:(id)delegate { 17 - (id)initWithDelegate:(id)delegate {
21 if ((self = [super init])) { 18 if ((self = [super init])) {
22 NSURLSessionConfiguration* sessionConfig = 19 NSURLSessionConfiguration* sessionConfig =
23 [NSURLSessionConfiguration defaultSessionConfiguration]; 20 [NSURLSessionConfiguration defaultSessionConfiguration];
24 session_ = [NSURLSession sessionWithConfiguration:sessionConfig 21 session_ = [NSURLSession sessionWithConfiguration:sessionConfig
25 delegate:delegate 22 delegate:delegate
26 delegateQueue:nil]; 23 delegateQueue:nil];
27 } 24 }
28 return self; 25 return self;
29 } 26 }
30 27
31 - (NSMutableURLRequest*)createRequestWithUrlAsString:(NSString*)urlString 28 - (NSMutableURLRequest*)createRequestWithUrlAsString:(NSString*)urlString
32 andXMLBody:(NSXMLDocument*)body { 29 andXMLBody:(NSXMLDocument*)body {
33 NSURL* requestURL = [NSURL URLWithString:urlString]; 30 NSURL* requestURL = [NSURL URLWithString:urlString];
34 request_ = [NSMutableURLRequest requestWithURL:requestURL]; 31 request_ = [NSMutableURLRequest requestWithURL:requestURL];
35 if (body) { 32 if (body) {
36 [request_ addValue:@"text/xml" forHTTPHeaderField:@"Content-Type"]; 33 [request_ addValue:@"text/xml" forHTTPHeaderField:@"Content-Type"];
37 NSData* requestBody = 34 NSData* requestBody =
38 [[body XMLString] dataUsingEncoding:NSUTF8StringEncoding]; 35 [[body XMLString] dataUsingEncoding:NSUTF8StringEncoding];
39 request_.HTTPBody = requestBody; 36 request_.HTTPBody = requestBody;
40 } 37 }
41 return request_; 38 return request_;
42 } 39 }
43 40
44 - (void)sendDataRequestWithCompletionHandler: 41 - (void)sendDataRequest {
45 (DataTaskCompletionHandler)completionHandler { 42 NSURLSessionDataTask* dataTask;
46 dataResponseHandler_ = completionHandler; 43 if (dataResponseHandler_) {
47 NSURLSessionDataTask* dataTask = 44 dataTask = [session_ dataTaskWithRequest:request_
48 [session_ dataTaskWithRequest:request_ 45 completionHandler:dataResponseHandler_];
49 completionHandler:dataResponseHandler_]; 46 } else {
47 dataTask = [session_ dataTaskWithRequest:request_];
48 }
50 49
51 [dataTask resume]; 50 [dataTask resume];
52 } 51 }
53 52
54 - (void)sendDownloadRequest { 53 - (void)sendDownloadRequest {
55 NSURLSessionDownloadTask* downloadTask; 54 NSURLSessionDownloadTask* downloadTask =
56 if (downloadResponseHandler_) { 55 [session_ downloadTaskWithRequest:request_];
57 downloadTask = [session_ downloadTaskWithRequest:request_
58 completionHandler:downloadResponseHandler_];
59 } else {
60 downloadTask = [session_ downloadTaskWithRequest:request_];
61 }
62 [downloadTask resume]; 56 [downloadTask resume];
63 } 57 }
64 58
65 @end 59 @end
OLDNEW
« no previous file with comments | « chrome/installer/mac/app/NetworkCommunication.h ('k') | chrome/installer/mac/app/OmahaCommunication.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698