Fix network delegate race condition (#12044)

* Fix race condition when getting network delegate

* Remove the evil URLRequestContextGetter::network_delegate

* Move the arguments instead of const referrencing

Safer and more efficient.
This commit is contained in:
Cheng Zhao 2018-02-26 23:24:00 +09:00 committed by shelley vohr
parent fdd66bd76d
commit 53229e3d6c
5 changed files with 41 additions and 26 deletions

View file

@ -441,14 +441,15 @@ void DownloadIdCallback(content::DownloadManager* download_manager,
}
void SetDevToolsNetworkEmulationClientIdInIO(
brightray::URLRequestContextGetter* context_getter,
brightray::URLRequestContextGetter* url_request_context_getter,
const std::string& client_id) {
if (!context_getter)
if (!url_request_context_getter)
return;
auto network_delegate =
static_cast<AtomNetworkDelegate*>(context_getter->network_delegate());
if (network_delegate)
network_delegate->SetDevToolsNetworkEmulationClientId(client_id);
net::URLRequestContext* context =
url_request_context_getter->GetURLRequestContext();
AtomNetworkDelegate* network_delegate =
static_cast<AtomNetworkDelegate*>(context->network_delegate());
network_delegate->SetDevToolsNetworkEmulationClientId(client_id);
}
} // namespace