Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/devtools/chrome_devtools_manager_delegate.h" | 5 #include "chrome/browser/devtools/chrome_devtools_manager_delegate.h" |
| 6 | 6 |
| 7 #include "base/values.h" | 7 #include "base/values.h" |
| 8 #include "chrome/browser/devtools/devtools_network_conditions.h" | 8 #include "chrome/browser/devtools/devtools_network_conditions.h" |
| 9 #include "chrome/browser/devtools/devtools_network_controller.h" | 9 #include "chrome/browser/devtools/devtools_network_controller.h" |
| 10 #include "chrome/browser/devtools/devtools_protocol.h" | 10 #include "chrome/browser/devtools/devtools_protocol.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 74 return NULL; | 74 return NULL; |
| 75 return Profile::FromBrowserContext(host->GetSiteInstance()->GetProcess()-> | 75 return Profile::FromBrowserContext(host->GetSiteInstance()->GetProcess()-> |
| 76 GetBrowserContext()); | 76 GetBrowserContext()); |
| 77 } | 77 } |
| 78 | 78 |
| 79 scoped_ptr<DevToolsProtocol::Response> | 79 scoped_ptr<DevToolsProtocol::Response> |
| 80 ChromeDevToolsManagerDelegate::EmulateNetworkConditions( | 80 ChromeDevToolsManagerDelegate::EmulateNetworkConditions( |
| 81 content::DevToolsAgentHost* agent_host, | 81 content::DevToolsAgentHost* agent_host, |
| 82 DevToolsProtocol::Command* command) { | 82 DevToolsProtocol::Command* command) { |
| 83 base::DictionaryValue* params = command->params(); | 83 base::DictionaryValue* params = command->params(); |
| 84 | |
| 85 std::vector<std::string> domains; | |
| 86 base::ListValue* domain_list; | |
| 87 const char* domains_param = | |
| 88 chrome::devtools::Network::emulateNetworkConditions::kParamDomains; | |
| 89 if (!params || !params->GetList(domains_param, &domain_list)) | |
| 90 return command->InvalidParamResponse(domains_param); | |
| 91 size_t size = domain_list->GetSize(); | |
| 92 for (size_t i = 0; i < size; ++i) { | |
| 93 std::string domain; | |
| 94 if (!domain_list->GetString(i, &domain)) | |
| 95 return command->InvalidParamResponse(domains_param); | |
| 96 domains.push_back(domain); | |
| 97 } | |
| 98 | |
| 84 bool offline = false; | 99 bool offline = false; |
| 85 const char* offline_param = | 100 const char* offline_param = |
| 86 chrome::devtools::Network::emulateNetworkConditions::kParamOffline; | 101 chrome::devtools::Network::emulateNetworkConditions::kParamOffline; |
| 87 if (!params || !params->GetBoolean(offline_param, &offline)) | 102 if (!params->GetBoolean(offline_param, &offline)) |
| 88 return command->InvalidParamResponse(offline_param); | 103 return command->InvalidParamResponse(offline_param); |
| 89 | 104 |
| 105 double maximal_throughput = 0.0; | |
| 106 const char* maximal_throughput_param = | |
| 107 chrome::devtools::Network::emulateNetworkConditions::kParamMaximalThroughp ut; | |
| 108 if (!params->GetDouble(maximal_throughput_param, &maximal_throughput)) | |
| 109 return command->InvalidParamResponse(maximal_throughput_param); | |
| 110 if (maximal_throughput < 0.0) | |
|
vsevik
2014/06/06 13:56:54
nit: I think negative throughput value is actually
eustas
2014/06/06 14:48:12
Done.
| |
| 111 return command->InvalidParamResponse(maximal_throughput_param); | |
| 112 | |
| 90 EnsureDevtoolsCallbackRegistered(); | 113 EnsureDevtoolsCallbackRegistered(); |
| 91 scoped_refptr<DevToolsNetworkConditions> conditions; | 114 scoped_refptr<DevToolsNetworkConditions> conditions; |
| 92 if (offline) | 115 if (offline || maximal_throughput) |
| 93 conditions = new DevToolsNetworkConditions(std::vector<std::string>()); | 116 conditions = new DevToolsNetworkConditions(domains, maximal_throughput); |
| 94 UpdateNetworkState(agent_host, conditions); | 117 UpdateNetworkState(agent_host, conditions); |
| 95 return command->SuccessResponse(NULL); | 118 return command->SuccessResponse(NULL); |
| 96 } | 119 } |
| 97 | 120 |
| 98 void ChromeDevToolsManagerDelegate::UpdateNetworkState( | 121 void ChromeDevToolsManagerDelegate::UpdateNetworkState( |
| 99 content::DevToolsAgentHost* agent_host, | 122 content::DevToolsAgentHost* agent_host, |
| 100 scoped_refptr<DevToolsNetworkConditions> conditions) { | 123 scoped_refptr<DevToolsNetworkConditions> conditions) { |
| 101 Profile* profile = GetProfile(agent_host); | 124 Profile* profile = GetProfile(agent_host); |
| 102 if (!profile) | 125 if (!profile) |
| 103 return; | 126 return; |
| 104 profile->GetDevToolsNetworkController()->SetNetworkState( | 127 profile->GetDevToolsNetworkController()->SetNetworkState( |
| 105 agent_host->GetId(), conditions); | 128 agent_host->GetId(), conditions); |
| 106 } | 129 } |
| 107 | 130 |
| 108 void ChromeDevToolsManagerDelegate::OnDevToolsStateChanged( | 131 void ChromeDevToolsManagerDelegate::OnDevToolsStateChanged( |
| 109 content::DevToolsAgentHost* agent_host, | 132 content::DevToolsAgentHost* agent_host, |
| 110 bool attached) { | 133 bool attached) { |
| 111 UpdateNetworkState(agent_host, scoped_refptr<DevToolsNetworkConditions>()); | 134 UpdateNetworkState(agent_host, scoped_refptr<DevToolsNetworkConditions>()); |
| 112 } | 135 } |
| OLD | NEW |