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

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

Issue 2094583004: Initial commit for Chrome metainstaller on Mac. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Additional progress addressing downloader and parser, moved BUILD dependencies away from root. 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
(Empty)
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #if !defined(__x86_64__)
6 #error "What are you doing?"
7 #endif
8
9 #import <Foundation/Foundation.h>
10 #include <mach-o/arch.h>
11 #include "request.h"
12
13 // NSString *omahaEndpoint = @"https://tools.google.com/service/update2";
14 static NSData *payload;
15
16 NSString* getArchitecture(void) {
17 const NXArchInfo *arch = NXGetLocalArchInfo();
18 NSString *archName = [NSString stringWithUTF8String:arch->name];
19 return archName;
20 }
21
22 NSString *getOSVersion(void) {
23 NSString *versionString = [[NSProcessInfo processInfo]
24 operatingSystemVersionString];
25 NSString *versionNumber = [[versionString componentsSeparatedByString:@" "]
26 objectAtIndex:1];
27 return versionNumber;
28 }
29
30 // Boris (borisv) indicated that the OS version, platform, appid, and version ar e the user
31 // attributes that Omaha actually looks at. The other parameters are useful for logging purposes
32 // but otherwise not directly used.
33 NSXMLDocument *createXMLRequestBody(NSString *operatingSystem,
34 NSString *architecture) {
35 NSString *protocol = @"3.0";
36 NSString *keystoneVersion = @"KeystoneAgent-1.99.4.0";
37
38 NSString *platform = @"mac";
39 NSString *plat_arch = [NSString stringWithFormat:@"%@_%@", operatingSystem,
40 architecture];
41
42 NSString *appid = @"com.google.Chrome";
43 NSString *version = @"0.0.0.0";
44 NSString *language = @"en-us";
45
46 NSXMLElement *root = [[NSXMLElement alloc] initWithName:@"request"];
47 [root addAttribute:[NSXMLNode attributeWithName:@"protocol"
48 stringValue:protocol]];
49 [root addAttribute:[NSXMLNode attributeWithName:@"version"
50 stringValue:keystoneVersion]];
51
52 NSXMLElement *osChild = [[NSXMLElement alloc] initWithName:@"os"];
53 [osChild addAttribute:[NSXMLNode attributeWithName:@"platform"
54 stringValue:platform]];
55 [osChild addAttribute:[NSXMLNode attributeWithName:@"version"
56 stringValue:operatingSystem]];
57 [osChild addAttribute:[NSXMLNode attributeWithName:@"arch"
58 stringValue:architecture]];
59 [osChild addAttribute:[NSXMLNode attributeWithName:@"sp"
60 stringValue:plat_arch]];
61 [root addChild:osChild];
62
63 NSXMLElement *appChild = [[NSXMLElement alloc] initWithName:@"app"];
64 [appChild addAttribute:[NSXMLNode attributeWithName:@"appid"
65 stringValue:appid]];
66 [appChild addAttribute:[NSXMLNode attributeWithName:@"version"
67 stringValue:version]];
68 [appChild addAttribute:[NSXMLNode attributeWithName:@"lang"
69 stringValue:language]];
70 [root addChild:appChild];
71
72 NSXMLElement *updateChildChild = [[NSXMLElement alloc]
73 initWithName:@"updatecheck"];
74 [appChild addChild:updateChildChild];
75
76 NSXMLDocument *requestXMLDocument = [[NSXMLDocument alloc]
77 initWithRootElement:root];
78 return requestXMLDocument;
79 }
80
81 NSURLRequest* createOmahaRequest(NSXMLDocument *requestXMLBody) {
82 // create request
83 NSURL *requestURL = [NSURL URLWithString:@"https://tools.google.com/service/up date2"];
84 NSMutableURLRequest *request = [NSMutableURLRequest
85 requestWithURL:requestURL];
86
87 // populate metadata
88 request.HTTPMethod = @"POST";
89 [request addValue:@"text/xml" forHTTPHeaderField:@"Content-Type"];
90
91 // populate xml body
92 NSData *requestBody = [[requestXMLBody XMLString]
93 dataUsingEncoding:NSUTF8StringEncoding];
94 request.HTTPBody = requestBody;
95
96 return request;
97 }
98
99 NSData* sendRequestAndReceiveResponse(NSURLRequest *request) {
100 // NSData *payload = [NSData alloc];
101 NSURLSessionConfiguration *sessionConfig = [NSURLSessionConfiguration
102 defaultSessionConfiguration];
103 NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfig
104 delegate:nil
105 delegateQueue:nil];
106
107 NSURLSessionDataTask *omahaDataTask = [session dataTaskWithRequest:request
108 completionHandler:^(NSData *_Nullable data,
109 NSURLResponse *_Nullable response,
110 NSError *_Nullable error) {
111 if(error) {
112 NSLog(@"%@", error);
113 return;
114 }
115
116 NSHTTPURLResponse *HTTPResponse = (NSHTTPURLResponse *)response;
117 if(HTTPResponse.statusCode == 200) {
118 // [payload initWithData:data];
119 payload = [[NSData alloc] initWithData:data];
120 } else {
121 NSLog(@"HTTP response: %ld", (unsigned long)HTTPResponse.statusCode);
122 return;
123 }
124
125 return;
126 }];
127
128 [omahaDataTask resume];
129 [session finishTasksAndInvalidate];
130 while([omahaDataTask state] != NSURLSessionTaskStateCompleted) {
131 sleep(1);
132 }
133
134 return [payload autorelease];
135 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698