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

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, 6 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/cast_content_client.h" 15 #include "chromecast/common/cast_content_client.h"
15 #include "chromecast/common/pref_names.h" 16 #include "chromecast/common/pref_names.h"
16 #include "components/devtools_http_handler/devtools_http_handler.h" 17 #include "components/devtools_http_handler/devtools_http_handler.h"
17 #include "content/public/browser/browser_context.h" 18 #include "content/public/browser/browser_context.h"
18 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
19 #include "content/public/common/content_switches.h" 20 #include "content/public/common/content_switches.h"
20 #include "content/public/common/user_agent.h" 21 #include "content/public/common/user_agent.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 new TCPServerSocketFactory("0.0.0.0", port)); 106 new TCPServerSocketFactory("0.0.0.0", port));
106 #endif 107 #endif
107 } 108 }
108 109
109 std::string GetFrontendUrl() { 110 std::string GetFrontendUrl() {
110 return base::StringPrintf(kFrontEndURL, content::GetWebKitRevision().c_str()); 111 return base::StringPrintf(kFrontEndURL, content::GetWebKitRevision().c_str());
111 } 112 }
112 113
113 } // namespace 114 } // namespace
114 115
115 RemoteDebuggingServer::RemoteDebuggingServer() : port_(0) { 116 RemoteDebuggingServer::RemoteDebuggingServer()
117 : port_(kDefaultRemoteDebuggingPort) {
116 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 118 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
117 pref_port_.Init(prefs::kRemoteDebuggingPort, 119 pref_enabled_.Init(prefs::kEnableRemoteDebugging,
118 CastBrowserProcess::GetInstance()->pref_service(), 120 CastBrowserProcess::GetInstance()->pref_service(),
119 base::Bind(&RemoteDebuggingServer::OnPortChanged, 121 base::Bind(&RemoteDebuggingServer::OnEnabledChanged,
120 base::Unretained(this))); 122 base::Unretained(this)));
123
124 std::string port_str =
125 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
126 switches::kRemoteDebuggingPort);
127 if (!port_str.empty()) {
128 int port = kDefaultRemoteDebuggingPort;
129 if (base::StringToInt(port_str, &port)) {
130 port_ = static_cast<uint16>(port);
131 } else {
132 port_ = kDefaultRemoteDebuggingPort;
133 }
134 }
121 135
122 // Starts new dev tools, clearing port number saved in config. 136 // Starts new dev tools, clearing port number saved in config.
123 // Remote debugging in production must be triggered only by config server. 137 // Remote debugging in production must be triggered only by config server.
124 pref_port_.SetValue(ShouldStartImmediately() ? 138 pref_enabled_.SetValue(ShouldStartImmediately() && port_ != 0);
125 kDefaultRemoteDebuggingPort : 0); 139 OnEnabledChanged();
126 OnPortChanged();
127 } 140 }
128 141
129 RemoteDebuggingServer::~RemoteDebuggingServer() { 142 RemoteDebuggingServer::~RemoteDebuggingServer() {
130 pref_port_.SetValue(0); 143 pref_enabled_.SetValue(false);
131 OnPortChanged(); 144 OnEnabledChanged();
132 } 145 }
133 146
134 void RemoteDebuggingServer::OnPortChanged() { 147 void RemoteDebuggingServer::OnEnabledChanged() {
135 uint16 new_port = static_cast<uint16>(std::max(*pref_port_, 0)); 148 bool enabled = *pref_enabled_ && port_ != 0;
136 VLOG(1) << "OnPortChanged called: old_port=" << port_ 149 if (enabled && !devtools_http_handler_) {
137 << ", new_port=" << new_port;
138
139 if (new_port == port_) {
140 VLOG(1) << "Port has not been changed. Ignore silently.";
141 return;
142 }
143
144 if (devtools_http_handler_) {
145 LOG(INFO) << "Stop old devtools: port=" << port_;
146 devtools_http_handler_.reset();
147 }
148
149 port_ = new_port;
150 if (port_ > 0) {
151 devtools_http_handler_.reset(new DevToolsHttpHandler( 150 devtools_http_handler_.reset(new DevToolsHttpHandler(
152 CreateSocketFactory(port_), 151 CreateSocketFactory(port_),
153 GetFrontendUrl(), 152 GetFrontendUrl(),
154 new CastDevToolsDelegate(), 153 new CastDevToolsDelegate(),
155 base::FilePath(), 154 base::FilePath(),
156 base::FilePath(), 155 base::FilePath(),
157 std::string(), 156 std::string(),
158 GetUserAgent())); 157 GetUserAgent()));
159 LOG(INFO) << "Devtools started: port=" << port_; 158 LOG(INFO) << "Devtools started: port=" << port_;
159 } else if (devtools_http_handler_) {
byungchul 2015/06/16 16:57:24 it includes the condition "enabled && evtools_http
derekjchow1 2015/06/16 17:02:48 Done.
160 LOG(INFO) << "Stop devtools: port=" << port_;
161 devtools_http_handler_.reset();
160 } 162 }
161 } 163 }
162 164
163 } // namespace shell 165 } // namespace shell
164 } // namespace chromecast 166 } // 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