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 "chromecast/browser/devtools/remote_debugging_server.h" | 5 #include "chromecast/browser/devtools/remote_debugging_server.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "net/socket/unix_domain_server_socket_posix.h" | 24 #include "net/socket/unix_domain_server_socket_posix.h" |
25 #endif // defined(OS_ANDROID) | 25 #endif // defined(OS_ANDROID) |
26 | 26 |
27 namespace chromecast { | 27 namespace chromecast { |
28 namespace shell { | 28 namespace shell { |
29 | 29 |
30 namespace { | 30 namespace { |
31 | 31 |
32 const char kFrontEndURL[] = | 32 const char kFrontEndURL[] = |
33 "https://chrome-devtools-frontend.appspot.com/serve_rev/%s/inspector.html"; | 33 "https://chrome-devtools-frontend.appspot.com/serve_rev/%s/inspector.html"; |
34 const int kDefaultRemoteDebuggingPort = 9222; | 34 const uint16 kDefaultRemoteDebuggingPort = 9222; |
35 | 35 |
36 #if defined(OS_ANDROID) | 36 #if defined(OS_ANDROID) |
37 class UnixDomainServerSocketFactory | 37 class UnixDomainServerSocketFactory |
38 : public content::DevToolsHttpHandler::ServerSocketFactory { | 38 : public content::DevToolsHttpHandler::ServerSocketFactory { |
39 public: | 39 public: |
40 explicit UnixDomainServerSocketFactory(const std::string& socket_name) | 40 explicit UnixDomainServerSocketFactory(const std::string& socket_name) |
41 : content::DevToolsHttpHandler::ServerSocketFactory(socket_name, 0, 1) {} | 41 : content::DevToolsHttpHandler::ServerSocketFactory(socket_name, 0, 1) {} |
42 | 42 |
43 private: | 43 private: |
44 // content::DevToolsHttpHandler::ServerSocketFactory. | 44 // content::DevToolsHttpHandler::ServerSocketFactory. |
45 virtual scoped_ptr<net::ServerSocket> Create() const override { | 45 virtual scoped_ptr<net::ServerSocket> Create() const override { |
46 return scoped_ptr<net::ServerSocket>( | 46 return scoped_ptr<net::ServerSocket>( |
47 new net::UnixDomainServerSocket( | 47 new net::UnixDomainServerSocket( |
48 base::Bind(&content::CanUserConnectToDevTools), | 48 base::Bind(&content::CanUserConnectToDevTools), |
49 true /* use_abstract_namespace */)); | 49 true /* use_abstract_namespace */)); |
50 } | 50 } |
51 | 51 |
52 DISALLOW_COPY_AND_ASSIGN(UnixDomainServerSocketFactory); | 52 DISALLOW_COPY_AND_ASSIGN(UnixDomainServerSocketFactory); |
53 }; | 53 }; |
54 #else | 54 #else |
55 class TCPServerSocketFactory | 55 class TCPServerSocketFactory |
56 : public content::DevToolsHttpHandler::ServerSocketFactory { | 56 : public content::DevToolsHttpHandler::ServerSocketFactory { |
57 public: | 57 public: |
58 TCPServerSocketFactory(const std::string& address, int port, int backlog) | 58 TCPServerSocketFactory(const std::string& address, uint16 port, int backlog) |
59 : content::DevToolsHttpHandler::ServerSocketFactory( | 59 : content::DevToolsHttpHandler::ServerSocketFactory( |
60 address, port, backlog) {} | 60 address, port, backlog) {} |
61 | 61 |
62 private: | 62 private: |
63 // content::DevToolsHttpHandler::ServerSocketFactory. | 63 // content::DevToolsHttpHandler::ServerSocketFactory. |
64 virtual scoped_ptr<net::ServerSocket> Create() const override { | 64 virtual scoped_ptr<net::ServerSocket> Create() const override { |
65 return scoped_ptr<net::ServerSocket>( | 65 return scoped_ptr<net::ServerSocket>( |
66 new net::TCPServerSocket(NULL, net::NetLog::Source())); | 66 new net::TCPServerSocket(NULL, net::NetLog::Source())); |
67 } | 67 } |
68 | 68 |
69 DISALLOW_COPY_AND_ASSIGN(TCPServerSocketFactory); | 69 DISALLOW_COPY_AND_ASSIGN(TCPServerSocketFactory); |
70 }; | 70 }; |
71 #endif | 71 #endif |
72 | 72 |
73 scoped_ptr<content::DevToolsHttpHandler::ServerSocketFactory> | 73 scoped_ptr<content::DevToolsHttpHandler::ServerSocketFactory> |
74 CreateSocketFactory(int port) { | 74 CreateSocketFactory(uint16 port) { |
75 #if defined(OS_ANDROID) | 75 #if defined(OS_ANDROID) |
76 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 76 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
77 std::string socket_name = "cast_shell_devtools_remote"; | 77 std::string socket_name = "cast_shell_devtools_remote"; |
78 if (command_line->HasSwitch(switches::kRemoteDebuggingSocketName)) { | 78 if (command_line->HasSwitch(switches::kRemoteDebuggingSocketName)) { |
79 socket_name = command_line->GetSwitchValueASCII( | 79 socket_name = command_line->GetSwitchValueASCII( |
80 switches::kRemoteDebuggingSocketName); | 80 switches::kRemoteDebuggingSocketName); |
81 } | 81 } |
82 return scoped_ptr<content::DevToolsHttpHandler::ServerSocketFactory>( | 82 return scoped_ptr<content::DevToolsHttpHandler::ServerSocketFactory>( |
83 new UnixDomainServerSocketFactory(socket_name)); | 83 new UnixDomainServerSocketFactory(socket_name)); |
84 #else | 84 #else |
(...skipping 21 matching lines...) Expand all Loading... |
106 kDefaultRemoteDebuggingPort : 0); | 106 kDefaultRemoteDebuggingPort : 0); |
107 OnPortChanged(); | 107 OnPortChanged(); |
108 } | 108 } |
109 | 109 |
110 RemoteDebuggingServer::~RemoteDebuggingServer() { | 110 RemoteDebuggingServer::~RemoteDebuggingServer() { |
111 pref_port_.SetValue(0); | 111 pref_port_.SetValue(0); |
112 OnPortChanged(); | 112 OnPortChanged(); |
113 } | 113 } |
114 | 114 |
115 void RemoteDebuggingServer::OnPortChanged() { | 115 void RemoteDebuggingServer::OnPortChanged() { |
116 int new_port = *pref_port_; | 116 uint16 new_port = static_cast<uint16>(std::max(*pref_port_, 0)); |
117 if (new_port < 0) { | |
118 new_port = 0; | |
119 } | |
120 VLOG(1) << "OnPortChanged called: old_port=" << port_ | 117 VLOG(1) << "OnPortChanged called: old_port=" << port_ |
121 << ", new_port=" << new_port; | 118 << ", new_port=" << new_port; |
122 | 119 |
123 if (new_port == port_) { | 120 if (new_port == port_) { |
124 VLOG(1) << "Port has not been changed. Ignore silently."; | 121 VLOG(1) << "Port has not been changed. Ignore silently."; |
125 return; | 122 return; |
126 } | 123 } |
127 | 124 |
128 if (devtools_http_handler_) { | 125 if (devtools_http_handler_) { |
129 LOG(INFO) << "Stop old devtools: port=" << port_; | 126 LOG(INFO) << "Stop old devtools: port=" << port_; |
130 devtools_http_handler_.reset(); | 127 devtools_http_handler_.reset(); |
131 } | 128 } |
132 | 129 |
133 port_ = new_port; | 130 port_ = new_port; |
134 if (port_ > 0) { | 131 if (port_ > 0) { |
135 devtools_http_handler_.reset(content::DevToolsHttpHandler::Start( | 132 devtools_http_handler_.reset(content::DevToolsHttpHandler::Start( |
136 CreateSocketFactory(port_), | 133 CreateSocketFactory(port_), |
137 GetFrontendUrl(), | 134 GetFrontendUrl(), |
138 new CastDevToolsDelegate(), | 135 new CastDevToolsDelegate(), |
139 base::FilePath())); | 136 base::FilePath())); |
140 LOG(INFO) << "Devtools started: port=" << port_; | 137 LOG(INFO) << "Devtools started: port=" << port_; |
141 } | 138 } |
142 } | 139 } |
143 | 140 |
144 } // namespace shell | 141 } // namespace shell |
145 } // namespace chromecast | 142 } // namespace chromecast |
OLD | NEW |