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

Side by Side 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, 7 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "headless/lib/browser/headless_devtools.h" 5 #include "headless/lib/browser/headless_devtools.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 10 matching lines...) Expand all
21 21
22 namespace headless { 22 namespace headless {
23 23
24 namespace { 24 namespace {
25 25
26 const int kBackLog = 10; 26 const int kBackLog = 10;
27 27
28 class TCPServerSocketFactory : public content::DevToolsSocketFactory { 28 class TCPServerSocketFactory : public content::DevToolsSocketFactory {
29 public: 29 public:
30 explicit TCPServerSocketFactory(const net::IPEndPoint& endpoint) 30 explicit TCPServerSocketFactory(const net::IPEndPoint& endpoint)
31 : endpoint_(endpoint) { 31 : endpoint_(endpoint), socket_fd_(0) {
32 DCHECK(endpoint_.address().IsValid()); 32 DCHECK(endpoint_.address().IsValid());
33 } 33 }
34 34
35 explicit TCPServerSocketFactory(const size_t socket_fd)
36 : socket_fd_(socket_fd) {}
37
35 private: 38 private:
36 // content::DevToolsSocketFactory implementation: 39 // content::DevToolsSocketFactory implementation:
37 std::unique_ptr<net::ServerSocket> CreateForHttpServer() override { 40 std::unique_ptr<net::ServerSocket> CreateForHttpServer() override {
38 std::unique_ptr<net::ServerSocket> socket( 41 if (!socket_fd_) {
42 std::unique_ptr<net::ServerSocket> socket(
43 new net::TCPServerSocket(nullptr, net::NetLogSource()));
44 if (socket->Listen(endpoint_, kBackLog) != net::OK)
45 return std::unique_ptr<net::ServerSocket>();
46 return socket;
47 }
48 #if defined(OS_POSIX)
49 std::unique_ptr<net::TCPServerSocket> tsock(
39 new net::TCPServerSocket(nullptr, net::NetLogSource())); 50 new net::TCPServerSocket(nullptr, net::NetLogSource()));
40 if (socket->Listen(endpoint_, kBackLog) != net::OK) 51 if (tsock->AdoptSocket(socket_fd_) != net::OK) {
52 LOG(ERROR) << "Failed to adopt open socket";
41 return std::unique_ptr<net::ServerSocket>(); 53 return std::unique_ptr<net::ServerSocket>();
42 54 }
43 return socket; 55 return std::unique_ptr<net::ServerSocket>(tsock.release());
56 #else
57 LOG(ERROR) << "Can't inherit an open socket on non-Posix systems";
58 return std::unique_ptr<net::ServerSocket>();
59 #endif
44 } 60 }
45 61
46 std::unique_ptr<net::ServerSocket> CreateForTethering( 62 std::unique_ptr<net::ServerSocket> CreateForTethering(
47 std::string* out_name) override { 63 std::string* out_name) override {
48 return nullptr; 64 return nullptr;
49 } 65 }
50 66
51 net::IPEndPoint endpoint_; 67 net::IPEndPoint endpoint_;
68 size_t socket_fd_;
52 69
53 DISALLOW_COPY_AND_ASSIGN(TCPServerSocketFactory); 70 DISALLOW_COPY_AND_ASSIGN(TCPServerSocketFactory);
54 }; 71 };
55 72
56 } // namespace 73 } // namespace
57 74
58 void StartLocalDevToolsHttpHandler(HeadlessBrowser::Options* options) { 75 void StartLocalDevToolsHttpHandler(HeadlessBrowser::Options* options) {
59 const net::IPEndPoint& endpoint = options->devtools_endpoint; 76 std::unique_ptr<content::DevToolsSocketFactory> socket_factory;
60 std::unique_ptr<content::DevToolsSocketFactory> socket_factory( 77 if (options->devtools_socket_fd == 0) {
61 new TCPServerSocketFactory(endpoint)); 78 const net::IPEndPoint& endpoint = options->devtools_endpoint;
79 socket_factory.reset(new TCPServerSocketFactory(endpoint));
80 } else {
81 const uint16_t socket_fd = options->devtools_socket_fd;
82 socket_factory.reset(new TCPServerSocketFactory(socket_fd));
83 }
62 content::DevToolsAgentHost::StartRemoteDebuggingServer( 84 content::DevToolsAgentHost::StartRemoteDebuggingServer(
63 std::move(socket_factory), std::string(), 85 std::move(socket_factory), std::string(),
64 options->user_data_dir, // TODO(altimin): Figure a proper value for this. 86 options->user_data_dir, // TODO(altimin): Figure a proper value for this.
65 base::FilePath(), options->product_name_and_version, options->user_agent); 87 base::FilePath(), options->product_name_and_version, options->user_agent);
66 } 88 }
67 89
68 void StopLocalDevToolsHttpHandler() { 90 void StopLocalDevToolsHttpHandler() {
69 content::DevToolsAgentHost::StopRemoteDebuggingServer(); 91 content::DevToolsAgentHost::StopRemoteDebuggingServer();
70 } 92 }
71 93
72 } // namespace headless 94 } // namespace headless
OLDNEW
« 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