set client id on AtomNetworkDelegate instead of cmd line switch

This commit is contained in:
deepak1556 2016-04-18 11:35:24 +05:30
parent fcf04377d7
commit b8e04f4947
5 changed files with 20 additions and 24 deletions

View file

@ -22,8 +22,6 @@
#include "atom/common/native_mate_converters/file_path_converter.h"
#include "atom/common/native_mate_converters/net_converter.h"
#include "atom/common/node_includes.h"
#include "atom/common/options_switches.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/guid.h"
#include "base/prefs/pref_service.h"
@ -288,12 +286,6 @@ void ClearHostResolverCacheInIO(
}
}
void SetDevToolsNetworkEmulationClientId(const std::string& id) {
auto cmd_line = base::CommandLine::ForCurrentProcess();
cmd_line->AppendSwitchASCII(
switches::kDevToolsEmulateNetworkConditionsClientId, id);
}
} // namespace
Session::Session(AtomBrowserContext* browser_context)
@ -394,14 +386,16 @@ void Session::EnableNetworkEmulation(const mate::Dictionary& options) {
browser_context_->network_controller_handle()->SetNetworkState(
devtools_network_emulation_client_id_, std::move(conditions));
SetDevToolsNetworkEmulationClientId(devtools_network_emulation_client_id_);
browser_context_->network_delegate()->SetDevToolsNetworkEmulationClientId(
devtools_network_emulation_client_id_);
}
void Session::DisableNetworkEmulation() {
scoped_ptr<brightray::DevToolsNetworkConditions> conditions;
browser_context_->network_controller_handle()->SetNetworkState(
devtools_network_emulation_client_id_, std::move(conditions));
SetDevToolsNetworkEmulationClientId(std::string());
browser_context_->network_delegate()->SetDevToolsNetworkEmulationClientId(
std::string());
}
void Session::SetCertVerifyProc(v8::Local<v8::Value> val,

View file

@ -4,17 +4,16 @@
#include "atom/browser/net/atom_network_delegate.h"
#include <string>
#include <utility>
#include "atom/common/native_mate_converters/net_converter.h"
#include "atom/common/options_switches.h"
#include "base/command_line.h"
#include "base/stl_util.h"
#include "base/strings/string_util.h"
#include "brightray/browser/net/devtools_network_transaction.h"
#include "content/public/browser/browser_thread.h"
#include "net/url_request/url_request.h"
using brightray::DevToolsNetworkTransaction;
using content::BrowserThread;
namespace atom {
@ -228,6 +227,11 @@ void AtomNetworkDelegate::SetResponseListenerInIO(
response_listeners_[type] = { patterns, callback };
}
void AtomNetworkDelegate::SetDevToolsNetworkEmulationClientId(
const std::string& client_id) {
client_id_ = client_id;
}
int AtomNetworkDelegate::OnBeforeURLRequest(
net::URLRequest* request,
const net::CompletionCallback& callback,
@ -243,12 +247,10 @@ int AtomNetworkDelegate::OnBeforeSendHeaders(
net::URLRequest* request,
const net::CompletionCallback& callback,
net::HttpRequestHeaders* headers) {
auto cmd_line = base::CommandLine::ForCurrentProcess();
auto client_id = cmd_line->GetSwitchValueASCII(
switches::kDevToolsEmulateNetworkConditionsClientId);
if (!client_id.empty())
if (!client_id_.empty())
headers->SetHeader(
switches::kDevToolsEmulateNetworkConditionsClientId, client_id);
DevToolsNetworkTransaction::kDevToolsEmulateNetworkConditionsClientId,
client_id_);
if (!ContainsKey(response_listeners_, kOnBeforeSendHeaders))
return brightray::NetworkDelegate::OnBeforeSendHeaders(
request, callback, headers);

View file

@ -7,6 +7,7 @@
#include <map>
#include <set>
#include <string>
#include "brightray/browser/network_delegate.h"
#include "base/callback.h"
@ -68,6 +69,8 @@ class AtomNetworkDelegate : public brightray::NetworkDelegate {
const URLPatterns& patterns,
const ResponseListener& callback);
void SetDevToolsNetworkEmulationClientId(const std::string& client_id);
protected:
// net::NetworkDelegate:
int OnBeforeURLRequest(net::URLRequest* request,
@ -116,6 +119,9 @@ class AtomNetworkDelegate : public brightray::NetworkDelegate {
std::map<ResponseEvent, ResponseListenerInfo> response_listeners_;
std::map<uint64_t, net::CompletionCallback> callbacks_;
// Client id for devtools network emulation.
std::string client_id_;
DISALLOW_COPY_AND_ASSIGN(AtomNetworkDelegate);
};

View file

@ -156,10 +156,6 @@ const char kWidevineCdmPath[] = "widevine-cdm-path";
// Widevine CDM version.
const char kWidevineCdmVersion[] = "widevine-cdm-version";
// Client id for devtools network emulation.
const char kDevToolsEmulateNetworkConditionsClientId[] =
"X-DevTools-Emulate-Network-Conditions-Client-Id";
} // namespace switches
} // namespace atom

View file

@ -87,8 +87,6 @@ extern const char kOpenerID[];
extern const char kWidevineCdmPath[];
extern const char kWidevineCdmVersion[];
extern const char kDevToolsEmulateNetworkConditionsClientId[];
} // namespace switches
} // namespace atom