OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2014 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 29 matching lines...) Expand all Loading... |
40 | 40 |
41 @end | 41 @end |
42 | 42 |
43 @implementation NSURLConnection (ARDUtilities) | 43 @implementation NSURLConnection (ARDUtilities) |
44 | 44 |
45 + (void)sendAsyncRequest:(NSURLRequest *)request | 45 + (void)sendAsyncRequest:(NSURLRequest *)request |
46 completionHandler:(void (^)(NSURLResponse *response, | 46 completionHandler:(void (^)(NSURLResponse *response, |
47 NSData *data, | 47 NSData *data, |
48 NSError *error))completionHandler { | 48 NSError *error))completionHandler { |
49 // Kick off an async request which will call back on main thread. | 49 // Kick off an async request which will call back on main thread. |
50 [NSURLConnection sendAsynchronousRequest:request | 50 NSURLSession *session = [NSURLSession sharedSession]; |
51 queue:[NSOperationQueue mainQueue] | 51 [[session dataTaskWithRequest:request |
52 completionHandler:^(NSURLResponse *response, | 52 completionHandler:^(NSData *data, NSURLResponse *response, NSError
*error) { |
53 NSData *data, | 53 if (completionHandler) { |
54 NSError *error) { | 54 completionHandler(response, data, error); |
55 if (completionHandler) { | 55 } |
56 completionHandler(response, data, error); | 56 }] resume]; |
57 } | |
58 }]; | |
59 } | 57 } |
60 | 58 |
61 // Posts data to the specified URL. | 59 // Posts data to the specified URL. |
62 + (void)sendAsyncPostToURL:(NSURL *)url | 60 + (void)sendAsyncPostToURL:(NSURL *)url |
63 withData:(NSData *)data | 61 withData:(NSData *)data |
64 completionHandler:(void (^)(BOOL succeeded, | 62 completionHandler:(void (^)(BOOL succeeded, |
65 NSData *data))completionHandler { | 63 NSData *data))completionHandler { |
66 NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; | 64 NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; |
67 request.HTTPMethod = @"POST"; | 65 request.HTTPMethod = @"POST"; |
68 request.HTTPBody = data; | 66 request.HTTPBody = data; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 cpu_usage_percentage += | 117 cpu_usage_percentage += |
120 100.f * (float)thread_info_data.cpu_usage / TH_USAGE_SCALE; | 118 100.f * (float)thread_info_data.cpu_usage / TH_USAGE_SCALE; |
121 } | 119 } |
122 } | 120 } |
123 | 121 |
124 // Dealloc the created array. | 122 // Dealloc the created array. |
125 vm_deallocate(task, (vm_address_t)thread_array, | 123 vm_deallocate(task, (vm_address_t)thread_array, |
126 sizeof(thread_act_t) * thread_count); | 124 sizeof(thread_act_t) * thread_count); |
127 return lroundf(cpu_usage_percentage); | 125 return lroundf(cpu_usage_percentage); |
128 } | 126 } |
OLD | NEW |