| 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/devtools_network_protocol_handler.h" | 5 #include "chrome/browser/devtools/devtools_network_protocol_handler.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/devtools/devtools_network_conditions.h" | 10 #include "chrome/browser/devtools/devtools_network_conditions.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 command_id, names::kParamUploadThroughput); | 85 command_id, names::kParamUploadThroughput); |
| 86 } | 86 } |
| 87 if (upload_throughput < 0.0) | 87 if (upload_throughput < 0.0) |
| 88 upload_throughput = 0.0; | 88 upload_throughput = 0.0; |
| 89 | 89 |
| 90 std::unique_ptr<DevToolsNetworkConditions> conditions( | 90 std::unique_ptr<DevToolsNetworkConditions> conditions( |
| 91 new DevToolsNetworkConditions(offline, latency, download_throughput, | 91 new DevToolsNetworkConditions(offline, latency, download_throughput, |
| 92 upload_throughput)); | 92 upload_throughput)); |
| 93 | 93 |
| 94 UpdateNetworkState(agent_host, std::move(conditions)); | 94 UpdateNetworkState(agent_host, std::move(conditions)); |
| 95 | 95 return nullptr; // Fall-through. |
| 96 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); | |
| 97 return DevToolsProtocol::CreateSuccessResponse(command_id, std::move(result)); | |
| 98 } | 96 } |
| 99 | 97 |
| 100 void DevToolsNetworkProtocolHandler::UpdateNetworkState( | 98 void DevToolsNetworkProtocolHandler::UpdateNetworkState( |
| 101 content::DevToolsAgentHost* agent_host, | 99 content::DevToolsAgentHost* agent_host, |
| 102 std::unique_ptr<DevToolsNetworkConditions> conditions) { | 100 std::unique_ptr<DevToolsNetworkConditions> conditions) { |
| 103 Profile* profile = Profile::FromBrowserContext( | 101 Profile* profile = Profile::FromBrowserContext( |
| 104 agent_host->GetBrowserContext()); | 102 agent_host->GetBrowserContext()); |
| 105 if (!profile) | 103 if (!profile) |
| 106 return; | 104 return; |
| 107 profile->GetDevToolsNetworkControllerHandle()->SetNetworkState( | 105 profile->GetDevToolsNetworkControllerHandle()->SetNetworkState( |
| 108 agent_host->GetId(), std::move(conditions)); | 106 agent_host->GetId(), std::move(conditions)); |
| 109 } | 107 } |
| 110 | 108 |
| 111 void DevToolsNetworkProtocolHandler::DevToolsAgentStateChanged( | 109 void DevToolsNetworkProtocolHandler::DevToolsAgentStateChanged( |
| 112 content::DevToolsAgentHost* agent_host, | 110 content::DevToolsAgentHost* agent_host, |
| 113 bool attached) { | 111 bool attached) { |
| 114 std::unique_ptr<DevToolsNetworkConditions> conditions; | 112 std::unique_ptr<DevToolsNetworkConditions> conditions; |
| 115 if (attached) | 113 if (attached) |
| 116 conditions.reset(new DevToolsNetworkConditions()); | 114 conditions.reset(new DevToolsNetworkConditions()); |
| 117 UpdateNetworkState(agent_host, std::move(conditions)); | 115 UpdateNetworkState(agent_host, std::move(conditions)); |
| 118 } | 116 } |
| OLD | NEW |