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> |
| 8 |
7 #include "base/values.h" | 9 #include "base/values.h" |
8 #include "chrome/browser/devtools/devtools_network_conditions.h" | 10 #include "chrome/browser/devtools/devtools_network_conditions.h" |
9 #include "chrome/browser/devtools/devtools_network_controller_handle.h" | 11 #include "chrome/browser/devtools/devtools_network_controller_handle.h" |
10 #include "chrome/browser/devtools/devtools_protocol_constants.h" | 12 #include "chrome/browser/devtools/devtools_protocol_constants.h" |
11 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
12 #include "content/public/browser/devtools_agent_host.h" | 14 #include "content/public/browser/devtools_agent_host.h" |
13 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
14 | 16 |
15 DevToolsNetworkProtocolHandler::DevToolsNetworkProtocolHandler() { | 17 DevToolsNetworkProtocolHandler::DevToolsNetworkProtocolHandler() { |
16 } | 18 } |
(...skipping 21 matching lines...) Expand all Loading... |
38 return nullptr; | 40 return nullptr; |
39 } | 41 } |
40 | 42 |
41 scoped_ptr<base::DictionaryValue> | 43 scoped_ptr<base::DictionaryValue> |
42 DevToolsNetworkProtocolHandler::CanEmulateNetworkConditions( | 44 DevToolsNetworkProtocolHandler::CanEmulateNetworkConditions( |
43 content::DevToolsAgentHost* agent_host, | 45 content::DevToolsAgentHost* agent_host, |
44 int command_id, | 46 int command_id, |
45 base::DictionaryValue* params) { | 47 base::DictionaryValue* params) { |
46 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue()); | 48 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue()); |
47 result->SetBoolean(chrome::devtools::kResult, true); | 49 result->SetBoolean(chrome::devtools::kResult, true); |
48 return DevToolsProtocol::CreateSuccessResponse(command_id, result.Pass()); | 50 return DevToolsProtocol::CreateSuccessResponse(command_id, std::move(result)); |
49 } | 51 } |
50 | 52 |
51 scoped_ptr<base::DictionaryValue> | 53 scoped_ptr<base::DictionaryValue> |
52 DevToolsNetworkProtocolHandler::EmulateNetworkConditions( | 54 DevToolsNetworkProtocolHandler::EmulateNetworkConditions( |
53 content::DevToolsAgentHost* agent_host, | 55 content::DevToolsAgentHost* agent_host, |
54 int command_id, | 56 int command_id, |
55 base::DictionaryValue* params) { | 57 base::DictionaryValue* params) { |
56 namespace names = ::chrome::devtools::Network::emulateNetworkConditions; | 58 namespace names = ::chrome::devtools::Network::emulateNetworkConditions; |
57 | 59 |
58 bool offline = false; | 60 bool offline = false; |
(...skipping 23 matching lines...) Expand all Loading... |
82 return DevToolsProtocol::CreateInvalidParamsResponse( | 84 return DevToolsProtocol::CreateInvalidParamsResponse( |
83 command_id, names::kParamUploadThroughput); | 85 command_id, names::kParamUploadThroughput); |
84 } | 86 } |
85 if (upload_throughput < 0.0) | 87 if (upload_throughput < 0.0) |
86 upload_throughput = 0.0; | 88 upload_throughput = 0.0; |
87 | 89 |
88 scoped_ptr<DevToolsNetworkConditions> conditions( | 90 scoped_ptr<DevToolsNetworkConditions> conditions( |
89 new DevToolsNetworkConditions( | 91 new DevToolsNetworkConditions( |
90 offline, latency, download_throughput, upload_throughput)); | 92 offline, latency, download_throughput, upload_throughput)); |
91 | 93 |
92 UpdateNetworkState(agent_host, conditions.Pass()); | 94 UpdateNetworkState(agent_host, std::move(conditions)); |
93 return scoped_ptr<base::DictionaryValue>(); | 95 return scoped_ptr<base::DictionaryValue>(); |
94 } | 96 } |
95 | 97 |
96 void DevToolsNetworkProtocolHandler::UpdateNetworkState( | 98 void DevToolsNetworkProtocolHandler::UpdateNetworkState( |
97 content::DevToolsAgentHost* agent_host, | 99 content::DevToolsAgentHost* agent_host, |
98 scoped_ptr<DevToolsNetworkConditions> conditions) { | 100 scoped_ptr<DevToolsNetworkConditions> conditions) { |
99 Profile* profile = Profile::FromBrowserContext( | 101 Profile* profile = Profile::FromBrowserContext( |
100 agent_host->GetBrowserContext()); | 102 agent_host->GetBrowserContext()); |
101 if (!profile) | 103 if (!profile) |
102 return; | 104 return; |
103 profile->GetDevToolsNetworkControllerHandle()->SetNetworkState( | 105 profile->GetDevToolsNetworkControllerHandle()->SetNetworkState( |
104 agent_host->GetId(), conditions.Pass()); | 106 agent_host->GetId(), std::move(conditions)); |
105 } | 107 } |
106 | 108 |
107 void DevToolsNetworkProtocolHandler::DevToolsAgentStateChanged( | 109 void DevToolsNetworkProtocolHandler::DevToolsAgentStateChanged( |
108 content::DevToolsAgentHost* agent_host, | 110 content::DevToolsAgentHost* agent_host, |
109 bool attached) { | 111 bool attached) { |
110 scoped_ptr<DevToolsNetworkConditions> conditions; | 112 scoped_ptr<DevToolsNetworkConditions> conditions; |
111 if (attached) | 113 if (attached) |
112 conditions.reset(new DevToolsNetworkConditions()); | 114 conditions.reset(new DevToolsNetworkConditions()); |
113 UpdateNetworkState(agent_host, conditions.Pass()); | 115 UpdateNetworkState(agent_host, std::move(conditions)); |
114 } | 116 } |
OLD | NEW |