Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 56 additions & 44 deletions util/net/http_transport_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -294,50 +294,62 @@ static bool ExecuteProxyRequest(NSMutableURLRequest* request,
NSURLSession* session =
[NSURLSession sessionWithConfiguration:sessionConfig];
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
[[session dataTaskWithRequest:request
completionHandler:^(
NSData* body, NSURLResponse* response, NSError* error) {
if (error) {
Metrics::CrashUploadErrorCode(error.code);
LOG(ERROR) << [[error localizedDescription] UTF8String]
<< " (" << [[error domain] UTF8String] << " "
<< [error code] << ")";
sync_rv = false;
dispatch_semaphore_signal(semaphore);
return;
}
if (!response) {
LOG(ERROR) << "no response";
sync_rv = false;
dispatch_semaphore_signal(semaphore);
return;
}
auto http_response =
base::apple::ObjCCast<NSHTTPURLResponse>(response);
if (!http_response) {
LOG(ERROR) << "no http_response";
sync_rv = false;
dispatch_semaphore_signal(semaphore);
return;
}
NSInteger http_status = [http_response statusCode];
if (http_status < 200 || http_status > 203) {
LOG(ERROR) << base::StringPrintf(
"HTTP status %ld", implicit_cast<long>(http_status));
sync_rv = false;
dispatch_semaphore_signal(semaphore);
return;
}

if (response_body) {
response_body->assign(
static_cast<const char*>([body bytes]), [body length]);
}
sync_rv = true;
dispatch_semaphore_signal(semaphore);
}] resume];

dispatch_semaphore_wait(semaphore, (dispatch_time_t)(10 * NSEC_PER_SEC));
NSURLSessionDataTask* task = [session
dataTaskWithRequest:request
completionHandler:^(
NSData* body, NSURLResponse* response, NSError* error) {
if (error) {
Metrics::CrashUploadErrorCode(error.code);
LOG(ERROR) << [[error localizedDescription] UTF8String] << " (" <<
[[error domain] UTF8String] << " " << [error code] << ")";
sync_rv = false;
dispatch_semaphore_signal(semaphore);
return;
}
if (!response) {
LOG(ERROR) << "no response";
sync_rv = false;
dispatch_semaphore_signal(semaphore);
return;
}
auto http_response =
base::apple::ObjCCast<NSHTTPURLResponse>(response);
if (!http_response) {
LOG(ERROR) << "no http_response";
sync_rv = false;
dispatch_semaphore_signal(semaphore);
return;
}
NSInteger http_status = [http_response statusCode];
if (http_status < 200 || http_status > 203) {
LOG(ERROR) << base::StringPrintf(
"HTTP status %ld", implicit_cast<long>(http_status));
sync_rv = false;
dispatch_semaphore_signal(semaphore);
return;
}

if (response_body) {
response_body->assign(static_cast<const char*>([body bytes]),
[body length]);
}
sync_rv = true;
dispatch_semaphore_signal(semaphore);
}];

if (task == nil) {
LOG(ERROR) << "Failed to create upload task.";
return false;
}

[task resume];

if (0 !=
dispatch_semaphore_wait(
semaphore, dispatch_time(DISPATCH_TIME_NOW, 10 * NSEC_PER_SEC))) {
LOG(ERROR) << "Upload task semaphore wait timed out";
sync_rv = false;
}
}
return sync_rv;
}
Expand Down