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

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: Merge branch 'master' of https://chromium.googlesource.com/chromium/src into headlessport 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
« no previous file with comments | « headless/lib/browser/headless_browser_main_parts.cc ('k') | headless/public/headless_browser.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..960600793d903f0cb93a4b6c6f01cefb2c79d153 100644
--- a/headless/lib/browser/headless_devtools.cc
+++ b/headless/lib/browser/headless_devtools.cc
@@ -28,19 +28,35 @@ 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(
+ if (!socket_fd_) {
+ 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;
+ }
+#if defined(OS_POSIX)
+ std::unique_ptr<net::TCPServerSocket> tsock(
new net::TCPServerSocket(nullptr, net::NetLogSource()));
- if (socket->Listen(endpoint_, kBackLog) != net::OK)
+ if (tsock->AdoptSocket(socket_fd_) != net::OK) {
+ LOG(ERROR) << "Failed to adopt open socket";
return std::unique_ptr<net::ServerSocket>();
-
- return socket;
+ }
+ 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>();
+#endif
}
std::unique_ptr<net::ServerSocket> CreateForTethering(
@@ -49,6 +65,7 @@ class TCPServerSocketFactory : public content::DevToolsSocketFactory {
}
net::IPEndPoint endpoint_;
+ size_t socket_fd_;
DISALLOW_COPY_AND_ASSIGN(TCPServerSocketFactory);
};
@@ -56,9 +73,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.
« no previous file with comments | « headless/lib/browser/headless_browser_main_parts.cc ('k') | headless/public/headless_browser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698