| 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/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 using content::BrowserThread; | |
| 15 | |
| 16 namespace { | 14 namespace { |
| 17 | 15 |
| 18 const int kBufferSize = 16 * 1024; | 16 const int kBufferSize = 16 * 1024; |
| 19 | 17 |
| 20 static const char kWebSocketUpgradeRequest[] = "GET %s HTTP/1.1\r\n" | 18 static const char kWebSocketUpgradeRequest[] = "GET %s HTTP/1.1\r\n" |
| 21 "Upgrade: WebSocket\r\n" | 19 "Upgrade: WebSocket\r\n" |
| 22 "Connection: Upgrade\r\n" | 20 "Connection: Upgrade\r\n" |
| 23 "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" | 21 "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 24 "Sec-WebSocket-Version: 13\r\n" | 22 "Sec-WebSocket-Version: 13\r\n" |
| 25 "\r\n"; | 23 "\r\n"; |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 | 167 |
| 170 scoped_ptr<net::StreamSocket> socket_; | 168 scoped_ptr<net::StreamSocket> socket_; |
| 171 std::string response_; | 169 std::string response_; |
| 172 AndroidDeviceManager::CommandCallback command_callback_; | 170 AndroidDeviceManager::CommandCallback command_callback_; |
| 173 AndroidDeviceManager::SocketCallback socket_callback_; | 171 AndroidDeviceManager::SocketCallback socket_callback_; |
| 174 size_t body_pos_; | 172 size_t body_pos_; |
| 175 }; | 173 }; |
| 176 | 174 |
| 177 } // namespace | 175 } // namespace |
| 178 | 176 |
| 177 AndroidDeviceManager::BrowserInfo::BrowserInfo() |
| 178 : type(kTypeOther) { |
| 179 } |
| 180 |
| 181 AndroidDeviceManager::DeviceInfo::DeviceInfo() { |
| 182 } |
| 183 |
| 184 AndroidDeviceManager::DeviceInfo::~DeviceInfo() { |
| 185 } |
| 186 |
| 179 AndroidDeviceManager::Device::Device(const std::string& serial, | 187 AndroidDeviceManager::Device::Device(const std::string& serial, |
| 180 bool is_connected) | 188 bool is_connected) |
| 181 : serial_(serial), | 189 : serial_(serial), |
| 182 is_connected_(is_connected) { | 190 is_connected_(is_connected) { |
| 183 } | 191 } |
| 184 | 192 |
| 185 AndroidDeviceManager::Device::~Device() { | 193 AndroidDeviceManager::Device::~Device() { |
| 186 } | 194 } |
| 187 | 195 |
| 188 AndroidDeviceManager::DeviceProvider::DeviceProvider() { | 196 AndroidDeviceManager::DeviceProvider::DeviceProvider() { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 210 stopped_ = true; | 218 stopped_ = true; |
| 211 devices_.clear(); | 219 devices_.clear(); |
| 212 } | 220 } |
| 213 | 221 |
| 214 bool AndroidDeviceManager::IsConnected(const std::string& serial) { | 222 bool AndroidDeviceManager::IsConnected(const std::string& serial) { |
| 215 DCHECK(CalledOnValidThread()); | 223 DCHECK(CalledOnValidThread()); |
| 216 Device* device = FindDevice(serial); | 224 Device* device = FindDevice(serial); |
| 217 return device && device->is_connected(); | 225 return device && device->is_connected(); |
| 218 } | 226 } |
| 219 | 227 |
| 220 void AndroidDeviceManager::RunCommand( | 228 void AndroidDeviceManager::QueryDeviceInfo(const std::string& serial, |
| 221 const std::string& serial, | 229 const DeviceInfoCallback& callback) { |
| 222 const std::string& command, | |
| 223 const CommandCallback& callback) { | |
| 224 DCHECK(CalledOnValidThread()); | 230 DCHECK(CalledOnValidThread()); |
| 225 Device* device = FindDevice(serial); | 231 Device* device = FindDevice(serial); |
| 226 if (device) | 232 if (device) |
| 227 device->RunCommand(command, callback); | 233 device->QueryDeviceInfo(callback); |
| 228 else | 234 else |
| 229 callback.Run(net::ERR_CONNECTION_FAILED, std::string()); | 235 callback.Run(DeviceInfo()); |
| 230 } | 236 } |
| 231 | 237 |
| 232 void AndroidDeviceManager::OpenSocket( | 238 void AndroidDeviceManager::OpenSocket( |
| 233 const std::string& serial, | 239 const std::string& serial, |
| 234 const std::string& socket_name, | 240 const std::string& socket_name, |
| 235 const SocketCallback& callback) { | 241 const SocketCallback& callback) { |
| 236 DCHECK(CalledOnValidThread()); | 242 DCHECK(CalledOnValidThread()); |
| 237 Device* device = FindDevice(serial); | 243 Device* device = FindDevice(serial); |
| 238 if (device) | 244 if (device) |
| 239 device->OpenSocket(socket_name, callback); | 245 device->OpenSocket(socket_name, callback); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 } | 321 } |
| 316 | 322 |
| 317 AndroidDeviceManager::Device* | 323 AndroidDeviceManager::Device* |
| 318 AndroidDeviceManager::FindDevice(const std::string& serial) { | 324 AndroidDeviceManager::FindDevice(const std::string& serial) { |
| 319 DCHECK(CalledOnValidThread()); | 325 DCHECK(CalledOnValidThread()); |
| 320 DeviceMap::const_iterator it = devices_.find(serial); | 326 DeviceMap::const_iterator it = devices_.find(serial); |
| 321 if (it == devices_.end()) | 327 if (it == devices_.end()) |
| 322 return NULL; | 328 return NULL; |
| 323 return (*it).second.get(); | 329 return (*it).second.get(); |
| 324 } | 330 } |
| OLD | NEW |