Commit fe597286 authored by Chong Gu's avatar Chong Gu Committed by Commit Bot

[Fuchsia] Allow web_engine_shell to allocate debugging port dynamically.

When remote debugging port set to 0, allow web_engine_shell to find available port to use.
Allow web_engine_shell to log the remote debugging port (if turned on).

Bug: 1014642
Change-Id: I7e7b98f10eb8ea0aa17c1a4761bbb50bf9d32dba
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1984626
Commit-Queue: Chong Gu <chonggu@google.com>
Reviewed-by: default avatarKevin Marshall <kmarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#729566}
parent 19dd1b48
......@@ -7,6 +7,7 @@
#include <fuchsia/web/cpp/fidl.h>
#include <lib/sys/cpp/component_context.h>
#include <lib/ui/scenic/cpp/view_token_pair.h>
#include <iostream>
#include "base/base_paths_fuchsia.h"
#include "base/command_line.h"
......@@ -26,9 +27,11 @@ constexpr char kRemoteDebuggingPortSwitch[] = "remote-debugging-port";
constexpr char kEnableLoggingSwitch[] = "enable-logging";
void PrintUsage() {
LOG(INFO) << "Usage: "
std::cerr << "Usage: "
<< base::CommandLine::ForCurrentProcess()->GetProgram().BaseName()
<< " [--" << kRemoteDebuggingPortSwitch << "] URL";
<< " [--" << kRemoteDebuggingPortSwitch << "] URL." << std::endl
<< "Setting " << kRemoteDebuggingPortSwitch << " to 0 will "
<< "automatically choose an available port.";
}
int main(int argc, char** argv) {
......@@ -63,10 +66,10 @@ int main(int argc, char** argv) {
std::string port_str =
command_line->GetSwitchValueNative(kRemoteDebuggingPortSwitch);
int port_parsed;
if (!base::StringToInt(port_str, &port_parsed) || port_parsed <= 0 ||
if (!base::StringToInt(port_str, &port_parsed) || port_parsed < 0 ||
port_parsed > 65535) {
LOG(ERROR) << "Invalid value for --remote-debugging-port (must be in the "
"range 1-65535).";
"range 0-65535).";
PrintUsage();
return 1;
}
......@@ -132,6 +135,20 @@ int main(int argc, char** argv) {
quit_run_loop.Run();
});
// Log the debugging port, if debugging is requested.
if (remote_debugging_port) {
context->GetRemoteDebuggingPort(
[](fuchsia::web::Context_GetRemoteDebuggingPort_Result result) {
if (result.is_err()) {
LOG(ERROR) << "Remote debugging service was not opened.";
return;
}
// Telemetry expects this exact format of log line output to retrieve
// the remote debugging port.
LOG(INFO) << "Remote debugging port: " << result.response().port;
});
}
// Navigate |frame| to |url|.
fuchsia::web::LoadUrlParams load_params;
load_params.set_type(fuchsia::web::LoadUrlReason::TYPED);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment