From ddf962c6eae0aa44b61112e1e7ee6ab8c89137db Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Tue, 19 Apr 2016 10:01:38 +0530 Subject: [PATCH] client_id is accessed on different threads --- atom/browser/net/atom_network_delegate.cc | 11 +++++++++-- atom/browser/net/atom_network_delegate.h | 2 ++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/atom/browser/net/atom_network_delegate.cc b/atom/browser/net/atom_network_delegate.cc index 6ef5ac22807a..3143cd3b2575 100644 --- a/atom/browser/net/atom_network_delegate.cc +++ b/atom/browser/net/atom_network_delegate.cc @@ -229,6 +229,7 @@ void AtomNetworkDelegate::SetResponseListenerInIO( void AtomNetworkDelegate::SetDevToolsNetworkEmulationClientId( const std::string& client_id) { + base::AutoLock auto_lock(lock_); client_id_ = client_id; } @@ -247,10 +248,16 @@ int AtomNetworkDelegate::OnBeforeSendHeaders( net::URLRequest* request, const net::CompletionCallback& callback, net::HttpRequestHeaders* headers) { - if (!client_id_.empty()) + std::string client_id; + { + base::AutoLock auto_lock(lock_); + client_id = client_id_; + } + + if (!client_id.empty()) headers->SetHeader( DevToolsNetworkTransaction::kDevToolsEmulateNetworkConditionsClientId, - client_id_); + client_id); if (!ContainsKey(response_listeners_, kOnBeforeSendHeaders)) return brightray::NetworkDelegate::OnBeforeSendHeaders( request, callback, headers); diff --git a/atom/browser/net/atom_network_delegate.h b/atom/browser/net/atom_network_delegate.h index e0b41eb45891..92ea6415e69e 100644 --- a/atom/browser/net/atom_network_delegate.h +++ b/atom/browser/net/atom_network_delegate.h @@ -11,6 +11,7 @@ #include "brightray/browser/network_delegate.h" #include "base/callback.h" +#include "base/synchronization/lock.h" #include "base/values.h" #include "extensions/common/url_pattern.h" #include "net/base/net_errors.h" @@ -119,6 +120,7 @@ class AtomNetworkDelegate : public brightray::NetworkDelegate { std::map response_listeners_; std::map callbacks_; + base::Lock lock_; // Client id for devtools network emulation. std::string client_id_;