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

Unified Diff: headless/lib/browser/headless_devtools.cc

Issue 2810353003: Adds a command-line flag indicating an open and listening socket to (Closed)
Patch Set: Updated upstream dependency Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: headless/lib/browser/headless_devtools.cc
diff --git a/headless/lib/browser/headless_devtools.cc b/headless/lib/browser/headless_devtools.cc
index ac60dcec2e2c92103c34aeaa19f3cedf286f4320..c9739cea91765de8a69943bfb870a9b09095e0db 100644
--- a/headless/lib/browser/headless_devtools.cc
+++ b/headless/lib/browser/headless_devtools.cc
@@ -28,19 +28,36 @@ const int kBackLog = 10;
class TCPServerSocketFactory : public content::DevToolsSocketFactory {
public:
explicit TCPServerSocketFactory(const net::IPEndPoint& endpoint)
- : endpoint_(endpoint) {
+ : endpoint_(endpoint), socket_fd(0) {
DCHECK(endpoint_.address().IsValid());
}
+ explicit TCPServerSocketFactory(const size_t socket_fd)
+ : socket_fd(socket_fd) {}
+
private:
// content::DevToolsSocketFactory implementation:
std::unique_ptr<net::ServerSocket> CreateForHttpServer() override {
- std::unique_ptr<net::ServerSocket> socket(
- new net::TCPServerSocket(nullptr, net::NetLogSource()));
- if (socket->Listen(endpoint_, kBackLog) != net::OK)
+ if (socket_fd == 0) {
+ std::unique_ptr<net::ServerSocket> socket(
+ new net::TCPServerSocket(nullptr, net::NetLogSource()));
+ if (socket->Listen(endpoint_, kBackLog) != net::OK)
+ return std::unique_ptr<net::ServerSocket>();
+ return socket;
dvallet 2017/04/13 03:44:29 nit: since you are returning here, I would remove
+ } else {
+#if defined(OS_POSIX)
+ std::unique_ptr<net::TCPServerSocket> tsock(
+ new net::TCPServerSocket(nullptr, net::NetLogSource()));
+ if (tsock->AdopListeningRawSocket(socket_fd) != net::OK) {
+ LOG(ERROR) << "Failed to adopt open socket";
+ return std::unique_ptr<net::ServerSocket>();
+ }
+ return std::unique_ptr<net::ServerSocket>(tsock.release());
+#else
+ LOG(ERROR) << "Can't inherit an open socket on non-Posix systems";
return std::unique_ptr<net::ServerSocket>();
-
- return socket;
+#endif
+ }
}
std::unique_ptr<net::ServerSocket> CreateForTethering(
@@ -49,6 +66,7 @@ class TCPServerSocketFactory : public content::DevToolsSocketFactory {
}
net::IPEndPoint endpoint_;
+ size_t socket_fd;
DISALLOW_COPY_AND_ASSIGN(TCPServerSocketFactory);
};
@@ -56,9 +74,14 @@ class TCPServerSocketFactory : public content::DevToolsSocketFactory {
} // namespace
void StartLocalDevToolsHttpHandler(HeadlessBrowser::Options* options) {
- const net::IPEndPoint& endpoint = options->devtools_endpoint;
- std::unique_ptr<content::DevToolsSocketFactory> socket_factory(
- new TCPServerSocketFactory(endpoint));
+ std::unique_ptr<content::DevToolsSocketFactory> socket_factory;
+ if (options->devtools_socket_fd == 0) {
+ const net::IPEndPoint& endpoint = options->devtools_endpoint;
+ socket_factory.reset(new TCPServerSocketFactory(endpoint));
+ } else {
+ const uint16_t socket_fd = options->devtools_socket_fd;
+ socket_factory.reset(new TCPServerSocketFactory(socket_fd));
+ }
content::DevToolsAgentHost::StartRemoteDebuggingServer(
std::move(socket_factory), std::string(),
options->user_data_dir, // TODO(altimin): Figure a proper value for this.

Powered by Google App Engine
This is Rietveld 408576698