Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/remote_debugging_server.h" | 5 #include "chrome/browser/devtools/remote_debugging_server.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 38 | 38 |
| 39 class TCPServerSocketFactory | 39 class TCPServerSocketFactory |
| 40 : public devtools_http_handler::DevToolsHttpHandler::ServerSocketFactory { | 40 : public devtools_http_handler::DevToolsHttpHandler::ServerSocketFactory { |
| 41 public: | 41 public: |
| 42 TCPServerSocketFactory(const std::string& address, uint16_t port) | 42 TCPServerSocketFactory(const std::string& address, uint16_t port) |
| 43 : address_(address), | 43 : address_(address), |
| 44 port_(port), | 44 port_(port), |
| 45 last_tethering_port_(kMinTetheringPort) {} | 45 last_tethering_port_(kMinTetheringPort) {} |
| 46 | 46 |
| 47 private: | 47 private: |
| 48 scoped_ptr<net::ServerSocket> CreateLocalHostServerSocket(int port) { | |
| 49 scoped_ptr<net::ServerSocket> socket( | |
| 50 new net::TCPServerSocket(nullptr, net::NetLog::Source())); | |
| 51 if (socket->ListenWithAddressAndPort( | |
| 52 "127.0.0.1", port, kBackLog) == net::OK) | |
| 53 return socket; | |
|
mmenke
2016/04/01 18:41:21
Where's the RemoteDebuggingClient? Would it be be
mmenke
2016/04/01 18:42:16
Also, it's possible the port could be used by anot
| |
| 54 if (socket->ListenWithAddressAndPort("::1", port, kBackLog) == net::OK) | |
| 55 return socket; | |
| 56 return scoped_ptr<net::ServerSocket>(); | |
| 57 } | |
| 58 | |
| 48 // devtools_http_handler::DevToolsHttpHandler::ServerSocketFactory. | 59 // devtools_http_handler::DevToolsHttpHandler::ServerSocketFactory. |
| 49 scoped_ptr<net::ServerSocket> CreateForHttpServer() override { | 60 scoped_ptr<net::ServerSocket> CreateForHttpServer() override { |
| 50 scoped_ptr<net::ServerSocket> socket( | 61 scoped_ptr<net::ServerSocket> socket( |
| 51 new net::TCPServerSocket(nullptr, net::NetLog::Source())); | 62 new net::TCPServerSocket(nullptr, net::NetLog::Source())); |
| 52 if (socket->ListenWithAddressAndPort(address_, port_, kBackLog) != net::OK) | 63 if (address_.empty()) |
| 53 return scoped_ptr<net::ServerSocket>(); | 64 return CreateLocalHostServerSocket(port_); |
| 54 | 65 if (socket->ListenWithAddressAndPort(address_, port_, kBackLog) == net::OK) |
| 55 return socket; | 66 return socket; |
| 67 return scoped_ptr<net::ServerSocket>(); | |
| 56 } | 68 } |
| 57 | 69 |
| 58 scoped_ptr<net::ServerSocket> CreateForTethering(std::string* name) override { | 70 scoped_ptr<net::ServerSocket> CreateForTethering(std::string* name) override { |
| 59 if (!g_tethering_enabled.Get()) | 71 if (!g_tethering_enabled.Get()) |
| 60 return scoped_ptr<net::ServerSocket>(); | 72 return scoped_ptr<net::ServerSocket>(); |
| 61 | 73 |
| 62 if (last_tethering_port_ == kMaxTetheringPort) | 74 if (last_tethering_port_ == kMaxTetheringPort) |
| 63 last_tethering_port_ = kMinTetheringPort; | 75 last_tethering_port_ = kMinTetheringPort; |
| 64 uint16_t port = ++last_tethering_port_; | 76 uint16_t port = ++last_tethering_port_; |
| 65 *name = base::UintToString(port); | 77 *name = base::UintToString(port); |
| 66 scoped_ptr<net::TCPServerSocket> socket( | 78 return CreateLocalHostServerSocket(port); |
| 67 new net::TCPServerSocket(nullptr, net::NetLog::Source())); | |
| 68 if (socket->ListenWithAddressAndPort("127.0.0.1", port, kBackLog) != | |
| 69 net::OK) { | |
| 70 return scoped_ptr<net::ServerSocket>(); | |
| 71 } | |
| 72 return std::move(socket); | |
| 73 } | 79 } |
| 74 | 80 |
| 75 std::string address_; | 81 std::string address_; |
| 76 uint16_t port_; | 82 uint16_t port_; |
| 77 uint16_t last_tethering_port_; | 83 uint16_t last_tethering_port_; |
| 78 | 84 |
| 79 DISALLOW_COPY_AND_ASSIGN(TCPServerSocketFactory); | 85 DISALLOW_COPY_AND_ASSIGN(TCPServerSocketFactory); |
| 80 }; | 86 }; |
| 81 | 87 |
| 82 class ChromeDevToolsHttpHandlerDelegate | 88 class ChromeDevToolsHttpHandlerDelegate |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 177 debug_frontend_dir, | 183 debug_frontend_dir, |
| 178 version_info::GetProductNameAndVersionForUserAgent(), | 184 version_info::GetProductNameAndVersionForUserAgent(), |
| 179 ::GetUserAgent())); | 185 ::GetUserAgent())); |
| 180 } | 186 } |
| 181 | 187 |
| 182 RemoteDebuggingServer::~RemoteDebuggingServer() { | 188 RemoteDebuggingServer::~RemoteDebuggingServer() { |
| 183 // Ensure Profile is alive, because the whole DevTools subsystem | 189 // Ensure Profile is alive, because the whole DevTools subsystem |
| 184 // accesses it during shutdown. | 190 // accesses it during shutdown. |
| 185 DCHECK(g_browser_process->profile_manager()); | 191 DCHECK(g_browser_process->profile_manager()); |
| 186 } | 192 } |
| OLD | NEW |