Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(293)

Side by Side Diff: chrome/browser/devtools/chrome_devtools_manager_delegate.cc

Issue 342473004: DevTools: make network conditions emulation scoped (browser) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 #endif 54 #endif
55 } 55 }
56 56
57 base::DictionaryValue* ChromeDevToolsManagerDelegate::HandleCommand( 57 base::DictionaryValue* ChromeDevToolsManagerDelegate::HandleCommand(
58 content::DevToolsAgentHost* agent_host, 58 content::DevToolsAgentHost* agent_host,
59 base::DictionaryValue* command_dict) { 59 base::DictionaryValue* command_dict) {
60 scoped_ptr<DevToolsProtocol::Command> command( 60 scoped_ptr<DevToolsProtocol::Command> command(
61 DevToolsProtocol::ParseCommand(command_dict)); 61 DevToolsProtocol::ParseCommand(command_dict));
62 if (!command) 62 if (!command)
63 return NULL; 63 return NULL;
64
64 const std::string method = command->method(); 65 const std::string method = command->method();
66 scoped_ptr<DevToolsProtocol::Response> response;
67
65 if (method == chrome::devtools::Network::emulateNetworkConditions::kName) 68 if (method == chrome::devtools::Network::emulateNetworkConditions::kName)
66 return EmulateNetworkConditions(agent_host, command.get())->Serialize(); 69 response = EmulateNetworkConditions(agent_host, command.get());
70
71 if (response)
72 return response->Serialize();
67 return NULL; 73 return NULL;
68 } 74 }
69 75
70 Profile* ChromeDevToolsManagerDelegate::GetProfile( 76 Profile* ChromeDevToolsManagerDelegate::GetProfile(
71 content::DevToolsAgentHost* agent_host) { 77 content::DevToolsAgentHost* agent_host) {
72 content::RenderViewHost* host = agent_host->GetRenderViewHost(); 78 content::RenderViewHost* host = agent_host->GetRenderViewHost();
73 if (!host) 79 if (!host)
74 return NULL; 80 return NULL;
75 return Profile::FromBrowserContext(host->GetSiteInstance()->GetProcess()-> 81 return Profile::FromBrowserContext(host->GetSiteInstance()->GetProcess()->
76 GetBrowserContext()); 82 GetBrowserContext());
77 } 83 }
78 84
79 scoped_ptr<DevToolsProtocol::Response> 85 scoped_ptr<DevToolsProtocol::Response>
80 ChromeDevToolsManagerDelegate::EmulateNetworkConditions( 86 ChromeDevToolsManagerDelegate::EmulateNetworkConditions(
81 content::DevToolsAgentHost* agent_host, 87 content::DevToolsAgentHost* agent_host,
82 DevToolsProtocol::Command* command) { 88 DevToolsProtocol::Command* command) {
83 base::DictionaryValue* params = command->params(); 89 base::DictionaryValue* params = command->params();
84 90 namespace names = ::chrome::devtools::Network::emulateNetworkConditions;
85 std::vector<std::string> domains;
86 base::ListValue* domain_list = NULL;
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 91
99 bool offline = false; 92 bool offline = false;
100 const char* offline_param = 93 if (!params || !params->GetBoolean(names::kParamOffline, &offline))
101 chrome::devtools::Network::emulateNetworkConditions::kParamOffline; 94 return command->InvalidParamResponse(names::kParamOffline);
102 if (!params->GetBoolean(offline_param, &offline))
103 return command->InvalidParamResponse(offline_param);
104 95
105 double maximal_throughput = 0.0; 96 double latency = 0.0;
106 const char* maximal_throughput_param = 97 if (!params->GetDouble(names::kParamLatency, &latency))
107 chrome::devtools::Network::emulateNetworkConditions::kParamMaximalThroughput; 98 return command->InvalidParamResponse(names::kParamLatency);
108 if (!params->GetDouble(maximal_throughput_param, &maximal_throughput)) 99 if (latency < 0.0)
109 return command->InvalidParamResponse(maximal_throughput_param); 100 latency = 0.0;
110 if (maximal_throughput < 0.0) 101
111 maximal_throughput = 0.0; 102 double download_throughput = 0.0;
103 if (!params->GetDouble(names::kParamDownloadThroughput, &download_throughput))
104 return command->InvalidParamResponse(names::kParamDownloadThroughput);
105 if (download_throughput < 0.0)
106 download_throughput = 0.0;
107
108 double upload_throughput = 0.0;
109 if (!params->GetDouble(names::kParamUploadThroughput, &upload_throughput))
110 return command->InvalidParamResponse(names::kParamUploadThroughput);
111 if (upload_throughput < 0.0)
112 upload_throughput = 0.0;
112 113
113 EnsureDevtoolsCallbackRegistered(); 114 EnsureDevtoolsCallbackRegistered();
114 scoped_refptr<DevToolsNetworkConditions> conditions; 115 scoped_refptr<DevToolsNetworkConditions> conditions(
115 if (offline || maximal_throughput) 116 new DevToolsNetworkConditions(
116 conditions = new DevToolsNetworkConditions(domains, maximal_throughput); 117 offline, latency, download_throughput, upload_throughput));
117 118
118 emulate_network_conditions_client_id_ = agent_host->GetId();
119 UpdateNetworkState(agent_host, conditions); 119 UpdateNetworkState(agent_host, conditions);
120 return command->SuccessResponse(NULL); 120 return command->SuccessResponse(NULL);
121 } 121 }
122 122
123 void ChromeDevToolsManagerDelegate::UpdateNetworkState( 123 void ChromeDevToolsManagerDelegate::UpdateNetworkState(
124 content::DevToolsAgentHost* agent_host, 124 content::DevToolsAgentHost* agent_host,
125 scoped_refptr<DevToolsNetworkConditions> conditions) { 125 scoped_refptr<DevToolsNetworkConditions> conditions) {
126 Profile* profile = GetProfile(agent_host); 126 Profile* profile = GetProfile(agent_host);
127 if (!profile) 127 if (!profile)
128 return; 128 return;
129 profile->GetDevToolsNetworkController()->SetNetworkState(conditions); 129 profile->GetDevToolsNetworkController()->SetNetworkState(
130 agent_host->GetId(), conditions);
130 } 131 }
131 132
132 void ChromeDevToolsManagerDelegate::OnDevToolsStateChanged( 133 void ChromeDevToolsManagerDelegate::OnDevToolsStateChanged(
133 content::DevToolsAgentHost* agent_host, 134 content::DevToolsAgentHost* agent_host,
134 bool attached) { 135 bool attached) {
135 if (agent_host->GetId() == emulate_network_conditions_client_id_) { 136 scoped_refptr<DevToolsNetworkConditions> conditions;
136 emulate_network_conditions_client_id_ = std::string(); 137 if (attached)
137 UpdateNetworkState(agent_host, scoped_refptr<DevToolsNetworkConditions>()); 138 conditions = new DevToolsNetworkConditions();
138 } 139 UpdateNetworkState(agent_host, conditions);
139 } 140 }
OLDNEW
« no previous file with comments | « chrome/browser/devtools/chrome_devtools_manager_delegate.h ('k') | chrome/browser/devtools/devtools_network_conditions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698