Index: chrome/browser/devtools/chrome_devtools_manager_delegate.cc |
diff --git a/chrome/browser/devtools/chrome_devtools_manager_delegate.cc b/chrome/browser/devtools/chrome_devtools_manager_delegate.cc |
index 473309d4d369f19091d17bac186f4cb6adceaa9f..5c161dcdd11ad33aa1d1d1d487cac54e4e6d5b30 100644 |
--- a/chrome/browser/devtools/chrome_devtools_manager_delegate.cc |
+++ b/chrome/browser/devtools/chrome_devtools_manager_delegate.cc |
@@ -61,9 +61,15 @@ base::DictionaryValue* ChromeDevToolsManagerDelegate::HandleCommand( |
DevToolsProtocol::ParseCommand(command_dict)); |
if (!command) |
return NULL; |
+ |
const std::string method = command->method(); |
+ scoped_ptr<DevToolsProtocol::Response> response; |
+ |
if (method == chrome::devtools::Network::emulateNetworkConditions::kName) |
- return EmulateNetworkConditions(agent_host, command.get())->Serialize(); |
+ response = EmulateNetworkConditions(agent_host, command.get()); |
+ |
+ if (response) |
+ return response->Serialize(); |
return NULL; |
} |
@@ -82,40 +88,41 @@ ChromeDevToolsManagerDelegate::EmulateNetworkConditions( |
DevToolsProtocol::Command* command) { |
base::DictionaryValue* params = command->params(); |
- std::vector<std::string> domains; |
- base::ListValue* domain_list = NULL; |
- const char* domains_param = |
- chrome::devtools::Network::emulateNetworkConditions::kParamDomains; |
- if (!params || !params->GetList(domains_param, &domain_list)) |
- return command->InvalidParamResponse(domains_param); |
- size_t size = domain_list->GetSize(); |
- for (size_t i = 0; i < size; ++i) { |
- std::string domain; |
- if (!domain_list->GetString(i, &domain)) |
- return command->InvalidParamResponse(domains_param); |
- domains.push_back(domain); |
- } |
- |
bool offline = false; |
const char* offline_param = |
chrome::devtools::Network::emulateNetworkConditions::kParamOffline; |
- if (!params->GetBoolean(offline_param, &offline)) |
+ if (!params || !params->GetBoolean(offline_param, &offline)) |
return command->InvalidParamResponse(offline_param); |
- double maximal_throughput = 0.0; |
- const char* maximal_throughput_param = |
-chrome::devtools::Network::emulateNetworkConditions::kParamMaximalThroughput; |
- if (!params->GetDouble(maximal_throughput_param, &maximal_throughput)) |
- return command->InvalidParamResponse(maximal_throughput_param); |
- if (maximal_throughput < 0.0) |
- maximal_throughput = 0.0; |
+ double latency = 0.0; |
+ const char* latency_param = |
+ chrome::devtools::Network::emulateNetworkConditions::kParamLatency; |
+ if (!params->GetDouble(latency_param, &latency)) |
+ return command->InvalidParamResponse(latency_param); |
+ if (latency < 0.0) |
+ latency = 0.0; |
+ |
+ double download_throughput = 0.0; |
+ const char* download_throughput_param = |
+chrome::devtools::Network::emulateNetworkConditions::kParamDownloadThroughput; |
+ if (!params->GetDouble(download_throughput_param, &download_throughput)) |
+ return command->InvalidParamResponse(download_throughput_param); |
+ if (download_throughput < 0.0) |
+ download_throughput = 0.0; |
+ |
+ double upload_throughput = 0.0; |
+ const char* upload_throughput_param = |
+chrome::devtools::Network::emulateNetworkConditions::kParamUploadThroughput; |
+ if (!params->GetDouble(upload_throughput_param, &upload_throughput)) |
+ return command->InvalidParamResponse(upload_throughput_param); |
+ if (upload_throughput < 0.0) |
+ upload_throughput = 0.0; |
EnsureDevtoolsCallbackRegistered(); |
- scoped_refptr<DevToolsNetworkConditions> conditions; |
- if (offline || maximal_throughput) |
- conditions = new DevToolsNetworkConditions(domains, maximal_throughput); |
+ scoped_refptr<DevToolsNetworkConditions> conditions( |
+ new DevToolsNetworkConditions( |
+ offline, latency, download_throughput, upload_throughput)); |
- emulate_network_conditions_client_id_ = agent_host->GetId(); |
UpdateNetworkState(agent_host, conditions); |
return command->SuccessResponse(NULL); |
} |
@@ -126,14 +133,15 @@ void ChromeDevToolsManagerDelegate::UpdateNetworkState( |
Profile* profile = GetProfile(agent_host); |
if (!profile) |
return; |
- profile->GetDevToolsNetworkController()->SetNetworkState(conditions); |
+ profile->GetDevToolsNetworkController()->SetNetworkState( |
+ agent_host->GetId(), conditions); |
} |
void ChromeDevToolsManagerDelegate::OnDevToolsStateChanged( |
content::DevToolsAgentHost* agent_host, |
bool attached) { |
- if (agent_host->GetId() == emulate_network_conditions_client_id_) { |
- emulate_network_conditions_client_id_ = std::string(); |
- UpdateNetworkState(agent_host, scoped_refptr<DevToolsNetworkConditions>()); |
- } |
+ scoped_refptr<DevToolsNetworkConditions> conditions; |
+ if (attached) |
+ conditions = new DevToolsNetworkConditions(); |
+ UpdateNetworkState(agent_host, conditions); |
} |