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

Side by Side Diff: chrome/browser/devtools/device/android_device_manager.cc

Issue 288353005: DevTools: Introduce virtual AndroidDeviceManager::Device::HttpQuery (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@deviceinfo2
Patch Set: Rebase better Created 6 years, 7 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/device/android_device_manager.h" 5 #include "chrome/browser/devtools/device/android_device_manager.h"
6 6
7 #include "base/strings/string_number_conversions.h" 7 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "net/base/io_buffer.h" 10 #include "net/base/io_buffer.h"
11 #include "net/base/net_errors.h" 11 #include "net/base/net_errors.h"
12 #include "net/socket/stream_socket.h" 12 #include "net/socket/stream_socket.h"
13 13
14 namespace { 14 namespace {
15 15
16 const int kBufferSize = 16 * 1024; 16 const int kBufferSize = 16 * 1024;
17 17
18 static const char kHttpGetRequest[] = "GET %s HTTP/1.1\r\n\r\n";
19
18 static const char kWebSocketUpgradeRequest[] = "GET %s HTTP/1.1\r\n" 20 static const char kWebSocketUpgradeRequest[] = "GET %s HTTP/1.1\r\n"
19 "Upgrade: WebSocket\r\n" 21 "Upgrade: WebSocket\r\n"
20 "Connection: Upgrade\r\n" 22 "Connection: Upgrade\r\n"
21 "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" 23 "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"
22 "Sec-WebSocket-Version: 13\r\n" 24 "Sec-WebSocket-Version: 13\r\n"
23 "\r\n"; 25 "\r\n";
24 26
25 class HttpRequest { 27 class HttpRequest {
26 public: 28 public:
27 typedef AndroidDeviceManager::CommandCallback CommandCallback; 29 typedef AndroidDeviceManager::CommandCallback CommandCallback;
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 185
184 AndroidDeviceManager::DeviceInfo::~DeviceInfo() { 186 AndroidDeviceManager::DeviceInfo::~DeviceInfo() {
185 } 187 }
186 188
187 AndroidDeviceManager::Device::Device(const std::string& serial, 189 AndroidDeviceManager::Device::Device(const std::string& serial,
188 bool is_connected) 190 bool is_connected)
189 : serial_(serial), 191 : serial_(serial),
190 is_connected_(is_connected) { 192 is_connected_(is_connected) {
191 } 193 }
192 194
195 void AndroidDeviceManager::Device::HttpQuery(const std::string& socket_name,
196 const std::string& path,
197 const CommandCallback& callback) {
198 std::string request(base::StringPrintf(kHttpGetRequest, path.c_str()));
199 OpenSocket(socket_name,
200 base::Bind(&HttpRequest::CommandRequest, request, callback));
201 }
202
193 AndroidDeviceManager::Device::~Device() { 203 AndroidDeviceManager::Device::~Device() {
194 } 204 }
195 205
196 AndroidDeviceManager::DeviceProvider::DeviceProvider() { 206 AndroidDeviceManager::DeviceProvider::DeviceProvider() {
197 } 207 }
198 208
199 AndroidDeviceManager::DeviceProvider::~DeviceProvider() { 209 AndroidDeviceManager::DeviceProvider::~DeviceProvider() {
200 } 210 }
201 211
202 // static 212 // static
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 } 258 }
249 259
250 void AndroidDeviceManager::HttpQuery( 260 void AndroidDeviceManager::HttpQuery(
251 const std::string& serial, 261 const std::string& serial,
252 const std::string& socket_name, 262 const std::string& socket_name,
253 const std::string& request, 263 const std::string& request,
254 const CommandCallback& callback) { 264 const CommandCallback& callback) {
255 DCHECK(CalledOnValidThread()); 265 DCHECK(CalledOnValidThread());
256 Device* device = FindDevice(serial); 266 Device* device = FindDevice(serial);
257 if (device) 267 if (device)
258 device->OpenSocket(socket_name, 268 device->HttpQuery(socket_name, request, callback);
259 base::Bind(&HttpRequest::CommandRequest, request, callback));
260 else 269 else
261 callback.Run(net::ERR_CONNECTION_FAILED, std::string()); 270 callback.Run(net::ERR_CONNECTION_FAILED, std::string());
262 } 271 }
263 272
264 void AndroidDeviceManager::HttpUpgrade( 273 void AndroidDeviceManager::HttpUpgrade(
265 const std::string& serial, 274 const std::string& serial,
266 const std::string& socket_name, 275 const std::string& socket_name,
267 const std::string& url, 276 const std::string& url,
268 const SocketCallback& callback) { 277 const SocketCallback& callback) {
269 DCHECK(CalledOnValidThread()); 278 DCHECK(CalledOnValidThread());
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 } 330 }
322 331
323 AndroidDeviceManager::Device* 332 AndroidDeviceManager::Device*
324 AndroidDeviceManager::FindDevice(const std::string& serial) { 333 AndroidDeviceManager::FindDevice(const std::string& serial) {
325 DCHECK(CalledOnValidThread()); 334 DCHECK(CalledOnValidThread());
326 DeviceMap::const_iterator it = devices_.find(serial); 335 DeviceMap::const_iterator it = devices_.find(serial);
327 if (it == devices_.end()) 336 if (it == devices_.end())
328 return NULL; 337 return NULL;
329 return (*it).second.get(); 338 return (*it).second.get();
330 } 339 }
OLDNEW
« no previous file with comments | « chrome/browser/devtools/device/android_device_manager.h ('k') | chrome/browser/devtools/device/devtools_android_bridge.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698