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

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

Issue 793663007: Set RemoteDebuggingServer port based on "remote-debugging-port" flag. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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
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"
11 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
12 #include "chromecast/browser/cast_browser_process.h" 13 #include "chromecast/browser/cast_browser_process.h"
13 #include "chromecast/browser/devtools/cast_dev_tools_delegate.h" 14 #include "chromecast/browser/devtools/cast_dev_tools_delegate.h"
14 #include "chromecast/common/pref_names.h" 15 #include "chromecast/common/pref_names.h"
15 #include "content/public/browser/browser_context.h" 16 #include "content/public/browser/browser_context.h"
16 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
17 #include "content/public/browser/devtools_http_handler.h" 18 #include "content/public/browser/devtools_http_handler.h"
18 #include "content/public/common/content_switches.h" 19 #include "content/public/common/content_switches.h"
19 #include "content/public/common/user_agent.h" 20 #include "content/public/common/user_agent.h"
20 #include "net/socket/tcp_server_socket.h" 21 #include "net/socket/tcp_server_socket.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 new TCPServerSocketFactory("0.0.0.0", port, 1)); 87 new TCPServerSocketFactory("0.0.0.0", port, 1));
87 #endif 88 #endif
88 } 89 }
89 90
90 std::string GetFrontendUrl() { 91 std::string GetFrontendUrl() {
91 return base::StringPrintf(kFrontEndURL, content::GetWebKitRevision().c_str()); 92 return base::StringPrintf(kFrontEndURL, content::GetWebKitRevision().c_str());
92 } 93 }
93 94
94 } // namespace 95 } // namespace
95 96
96 RemoteDebuggingServer::RemoteDebuggingServer() : port_(0) { 97 RemoteDebuggingServer::RemoteDebuggingServer()
98 : port_(kDefaultRemoteDebuggingPort) {
97 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 99 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
98 pref_port_.Init(prefs::kRemoteDebuggingPort, 100 pref_enabled_.Init(prefs::kEnableRemoteDebugging,
99 CastBrowserProcess::GetInstance()->pref_service(), 101 CastBrowserProcess::GetInstance()->pref_service(),
100 base::Bind(&RemoteDebuggingServer::OnPortChanged, 102 base::Bind(&RemoteDebuggingServer::OnEnabledChanged,
101 base::Unretained(this))); 103 base::Unretained(this)));
104
105 std::string port_str = base::CommandLine::ForCurrentProcess()
106 ->GetSwitchValueASCII(switches::kRemoteDebuggingPort);
107 if (!port_str.empty()) {
108 unsigned port;
byungchul 2015/01/08 06:28:56 Init to 0. StringToUint may not set port on error.
derekjchow1 2015/01/08 17:55:42 Done.
109 base::StringToUint(port_str, &port);
byungchul 2015/01/08 06:28:56 Do we support port=0 case which disables remote de
derekjchow1 2015/01/08 17:55:42 Yes. There is a check in OnEnabledChanged that onl
byungchul 2015/01/08 18:51:21 My question is, if it is by intention or not. Alte
derekjchow1 2015/01/12 23:15:55 Done. Your correct, we should set default port.
110 port_ = port;
111 }
102 112
103 // Starts new dev tools, clearing port number saved in config. 113 // Starts new dev tools, clearing port number saved in config.
104 // Remote debugging in production must be triggered only by config server. 114 // Remote debugging in production must be triggered only by config server.
105 pref_port_.SetValue(ShouldStartImmediately() ? 115 pref_enabled_.SetValue(ShouldStartImmediately() && port_ != 0);
106 kDefaultRemoteDebuggingPort : 0); 116 OnEnabledChanged();
107 OnPortChanged();
108 } 117 }
109 118
110 RemoteDebuggingServer::~RemoteDebuggingServer() { 119 RemoteDebuggingServer::~RemoteDebuggingServer() {
111 pref_port_.SetValue(0); 120 pref_enabled_.SetValue(false);
112 OnPortChanged(); 121 OnEnabledChanged();
113 } 122 }
114 123
115 void RemoteDebuggingServer::OnPortChanged() { 124 void RemoteDebuggingServer::OnEnabledChanged() {
116 uint16 new_port = static_cast<uint16>(std::max(*pref_port_, 0)); 125 bool enabled = *pref_enabled_ && port_ != 0;
117 VLOG(1) << "OnPortChanged called: old_port=" << port_ 126 if (enabled && !devtools_http_handler_) {
118 << ", new_port=" << new_port; 127 VLOG(1) << "Start devtools: port=" << port_;
119
120 if (new_port == port_) {
121 VLOG(1) << "Port has not been changed. Ignore silently.";
122 return;
123 }
124
125 if (devtools_http_handler_) {
126 LOG(INFO) << "Stop old devtools: port=" << port_;
127 devtools_http_handler_.reset();
128 }
129
130 port_ = new_port;
131 if (port_ > 0) {
132 devtools_http_handler_.reset(content::DevToolsHttpHandler::Start( 128 devtools_http_handler_.reset(content::DevToolsHttpHandler::Start(
133 CreateSocketFactory(port_), 129 CreateSocketFactory(port_),
134 GetFrontendUrl(), 130 GetFrontendUrl(),
135 new CastDevToolsDelegate(), 131 new CastDevToolsDelegate(),
136 base::FilePath())); 132 base::FilePath()));
137 LOG(INFO) << "Devtools started: port=" << port_; 133 } else if (devtools_http_handler_) {
134 LOG(INFO) << "Stop devtools: port=" << port_;
gunsch 2015/01/08 03:46:52 Make the Start/Stop devtools either both LOG(INFO)
derekjchow1 2015/01/08 17:55:42 Done.
135 devtools_http_handler_.reset();
138 } 136 }
139 } 137 }
140 138
141 } // namespace shell 139 } // namespace shell
142 } // namespace chromecast 140 } // namespace chromecast
OLDNEW
« no previous file with comments | « chromecast/browser/devtools/remote_debugging_server.h ('k') | chromecast/browser/pref_service_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698