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

Side by Side Diff: chromecast/browser/devtools/remote_debugging_server.cc

Issue 722503002: Use uint16 for port numbers, misc edition (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Self-review Created 6 years, 1 month 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
OLDNEW
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
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/devtools.html"; 33 "https://chrome-devtools-frontend.appspot.com/serve_rev/%s/devtools.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 23 matching lines...) Expand all
108 kDefaultRemoteDebuggingPort : 0); 108 kDefaultRemoteDebuggingPort : 0);
109 OnPortChanged(); 109 OnPortChanged();
110 } 110 }
111 111
112 RemoteDebuggingServer::~RemoteDebuggingServer() { 112 RemoteDebuggingServer::~RemoteDebuggingServer() {
113 pref_port_.SetValue(0); 113 pref_port_.SetValue(0);
114 OnPortChanged(); 114 OnPortChanged();
115 } 115 }
116 116
117 void RemoteDebuggingServer::OnPortChanged() { 117 void RemoteDebuggingServer::OnPortChanged() {
118 int new_port = *pref_port_; 118 uint16 new_port = static_cast<uint16>(std::max(*pref_port_, 0));
119 if (new_port < 0) {
120 new_port = 0;
121 }
122 VLOG(1) << "OnPortChanged called: old_port=" << port_ 119 VLOG(1) << "OnPortChanged called: old_port=" << port_
123 << ", new_port=" << new_port; 120 << ", new_port=" << new_port;
124 121
125 if (new_port == port_) { 122 if (new_port == port_) {
126 VLOG(1) << "Port has not been changed. Ignore silently."; 123 VLOG(1) << "Port has not been changed. Ignore silently.";
127 return; 124 return;
128 } 125 }
129 126
130 if (devtools_http_handler_) { 127 if (devtools_http_handler_) {
131 LOG(INFO) << "Stop old devtools: port=" << port_; 128 LOG(INFO) << "Stop old devtools: port=" << port_;
132 // Note: Stop destroys devtools_http_handler_. 129 // Note: Stop destroys devtools_http_handler_.
133 devtools_http_handler_->Stop(); 130 devtools_http_handler_->Stop();
134 devtools_http_handler_ = NULL; 131 devtools_http_handler_ = NULL;
135 } 132 }
136 133
137 port_ = new_port; 134 port_ = new_port;
138 if (port_ > 0) { 135 if (port_ > 0) {
139 devtools_http_handler_ = content::DevToolsHttpHandler::Start( 136 devtools_http_handler_ = content::DevToolsHttpHandler::Start(
140 CreateSocketFactory(port_), 137 CreateSocketFactory(port_),
141 GetFrontendUrl(), 138 GetFrontendUrl(),
142 new CastDevToolsDelegate(), 139 new CastDevToolsDelegate(),
143 base::FilePath()); 140 base::FilePath());
144 LOG(INFO) << "Devtools started: port=" << port_; 141 LOG(INFO) << "Devtools started: port=" << port_;
145 } 142 }
146 } 143 }
147 144
148 } // namespace shell 145 } // namespace shell
149 } // namespace chromecast 146 } // namespace chromecast
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698