| 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/port_forwarding_controller.h" | 5 #include "chrome/browser/devtools/device/port_forwarding_controller.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <utility> |
| 8 | 9 |
| 9 #include "base/bind.h" | 10 #include "base/bind.h" |
| 10 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 11 #include "base/macros.h" | 12 #include "base/macros.h" |
| 12 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
| 13 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 14 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
| 15 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/strings/string_split.h" | 17 #include "base/strings/string_split.h" |
| 17 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 47 | 48 |
| 48 static const char kDevToolsRemoteBrowserTarget[] = "/devtools/browser"; | 49 static const char kDevToolsRemoteBrowserTarget[] = "/devtools/browser"; |
| 49 | 50 |
| 50 class SocketTunnel : public base::NonThreadSafe { | 51 class SocketTunnel : public base::NonThreadSafe { |
| 51 public: | 52 public: |
| 52 static void StartTunnel(const std::string& host, | 53 static void StartTunnel(const std::string& host, |
| 53 int port, | 54 int port, |
| 54 int result, | 55 int result, |
| 55 scoped_ptr<net::StreamSocket> socket) { | 56 scoped_ptr<net::StreamSocket> socket) { |
| 56 if (result == net::OK) | 57 if (result == net::OK) |
| 57 new SocketTunnel(socket.Pass(), host, port); | 58 new SocketTunnel(std::move(socket), host, port); |
| 58 } | 59 } |
| 59 | 60 |
| 60 private: | 61 private: |
| 61 SocketTunnel(scoped_ptr<net::StreamSocket> socket, | 62 SocketTunnel(scoped_ptr<net::StreamSocket> socket, |
| 62 const std::string& host, | 63 const std::string& host, |
| 63 int port) | 64 int port) |
| 64 : remote_socket_(socket.Pass()), | 65 : remote_socket_(std::move(socket)), |
| 65 pending_writes_(0), | 66 pending_writes_(0), |
| 66 pending_destruction_(false) { | 67 pending_destruction_(false) { |
| 67 host_resolver_ = net::HostResolver::CreateDefaultResolver(nullptr); | 68 host_resolver_ = net::HostResolver::CreateDefaultResolver(nullptr); |
| 68 net::HostResolver::RequestInfo request_info(net::HostPortPair(host, port)); | 69 net::HostResolver::RequestInfo request_info(net::HostPortPair(host, port)); |
| 69 int result = host_resolver_->Resolve( | 70 int result = host_resolver_->Resolve( |
| 70 request_info, | 71 request_info, |
| 71 net::DEFAULT_PRIORITY, | 72 net::DEFAULT_PRIORITY, |
| 72 &address_list_, | 73 &address_list_, |
| 73 base::Bind(&SocketTunnel::OnResolved, base::Unretained(this)), | 74 base::Bind(&SocketTunnel::OnResolved, base::Unretained(this)), |
| 74 nullptr, | 75 nullptr, |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 | 330 |
| 330 pending_responses_[id] = | 331 pending_responses_[id] = |
| 331 base::Bind(&Connection::ProcessUnbindResponse, | 332 base::Bind(&Connection::ProcessUnbindResponse, |
| 332 base::Unretained(this), port); | 333 base::Unretained(this), port); |
| 333 #if defined(DEBUG_DEVTOOLS) | 334 #if defined(DEBUG_DEVTOOLS) |
| 334 port_status_[port] = kStatusDisconnecting; | 335 port_status_[port] = kStatusDisconnecting; |
| 335 #endif // defined(DEBUG_DEVTOOLS) | 336 #endif // defined(DEBUG_DEVTOOLS) |
| 336 } | 337 } |
| 337 | 338 |
| 338 web_socket_->SendFrame( | 339 web_socket_->SendFrame( |
| 339 DevToolsProtocol::SerializeCommand(id, method, params.Pass())); | 340 DevToolsProtocol::SerializeCommand(id, method, std::move(params))); |
| 340 } | 341 } |
| 341 | 342 |
| 342 bool PortForwardingController::Connection::ProcessResponse( | 343 bool PortForwardingController::Connection::ProcessResponse( |
| 343 const std::string& message) { | 344 const std::string& message) { |
| 344 int id = 0; | 345 int id = 0; |
| 345 int error_code = 0; | 346 int error_code = 0; |
| 346 if (!DevToolsProtocol::ParseResponse(message, &id, &error_code)) | 347 if (!DevToolsProtocol::ParseResponse(message, &id, &error_code)) |
| 347 return false; | 348 return false; |
| 348 | 349 |
| 349 CommandCallbackMap::iterator it = pending_responses_.find(id); | 350 CommandCallbackMap::iterator it = pending_responses_.find(id); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 registry_copy.push_back(it->second); | 493 registry_copy.push_back(it->second); |
| 493 } | 494 } |
| 494 STLDeleteElements(®istry_copy); | 495 STLDeleteElements(®istry_copy); |
| 495 } | 496 } |
| 496 } | 497 } |
| 497 | 498 |
| 498 void PortForwardingController::UpdateConnections() { | 499 void PortForwardingController::UpdateConnections() { |
| 499 for (Registry::iterator it = registry_.begin(); it != registry_.end(); ++it) | 500 for (Registry::iterator it = registry_.begin(); it != registry_.end(); ++it) |
| 500 it->second->UpdateForwardingMap(forwarding_map_); | 501 it->second->UpdateForwardingMap(forwarding_map_); |
| 501 } | 502 } |
| OLD | NEW |