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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 chrome::devtools::Network::emulateNetworkConditions::kParamMaximalThroughput; | 107 chrome::devtools::Network::emulateNetworkConditions::kParamMaximalThroughput; |
108 if (!params->GetDouble(maximal_throughput_param, &maximal_throughput)) | 108 if (!params->GetDouble(maximal_throughput_param, &maximal_throughput)) |
109 return command->InvalidParamResponse(maximal_throughput_param); | 109 return command->InvalidParamResponse(maximal_throughput_param); |
110 if (maximal_throughput < 0.0) | 110 if (maximal_throughput < 0.0) |
111 maximal_throughput = 0.0; | 111 maximal_throughput = 0.0; |
112 | 112 |
113 EnsureDevtoolsCallbackRegistered(); | 113 EnsureDevtoolsCallbackRegistered(); |
114 scoped_refptr<DevToolsNetworkConditions> conditions; | 114 scoped_refptr<DevToolsNetworkConditions> conditions; |
115 if (offline || maximal_throughput) | 115 if (offline || maximal_throughput) |
116 conditions = new DevToolsNetworkConditions(domains, maximal_throughput); | 116 conditions = new DevToolsNetworkConditions(domains, maximal_throughput); |
| 117 |
| 118 emulate_network_conditions_client_id_ = agent_host->GetId(); |
117 UpdateNetworkState(agent_host, conditions); | 119 UpdateNetworkState(agent_host, conditions); |
118 return command->SuccessResponse(NULL); | 120 return command->SuccessResponse(NULL); |
119 } | 121 } |
120 | 122 |
121 void ChromeDevToolsManagerDelegate::UpdateNetworkState( | 123 void ChromeDevToolsManagerDelegate::UpdateNetworkState( |
122 content::DevToolsAgentHost* agent_host, | 124 content::DevToolsAgentHost* agent_host, |
123 scoped_refptr<DevToolsNetworkConditions> conditions) { | 125 scoped_refptr<DevToolsNetworkConditions> conditions) { |
124 Profile* profile = GetProfile(agent_host); | 126 Profile* profile = GetProfile(agent_host); |
125 if (!profile) | 127 if (!profile) |
126 return; | 128 return; |
127 profile->GetDevToolsNetworkController()->SetNetworkState( | 129 profile->GetDevToolsNetworkController()->SetNetworkState(conditions); |
128 agent_host->GetId(), conditions); | |
129 } | 130 } |
130 | 131 |
131 void ChromeDevToolsManagerDelegate::OnDevToolsStateChanged( | 132 void ChromeDevToolsManagerDelegate::OnDevToolsStateChanged( |
132 content::DevToolsAgentHost* agent_host, | 133 content::DevToolsAgentHost* agent_host, |
133 bool attached) { | 134 bool attached) { |
134 UpdateNetworkState(agent_host, scoped_refptr<DevToolsNetworkConditions>()); | 135 if (agent_host->GetId() == emulate_network_conditions_client_id_) { |
| 136 emulate_network_conditions_client_id_ = std::string(); |
| 137 UpdateNetworkState(agent_host, scoped_refptr<DevToolsNetworkConditions>()); |
| 138 } |
135 } | 139 } |
OLD | NEW |