Commit bd1e4485 authored by Illia Martyniuk's avatar Illia Martyniuk Committed by Commit Bot

VIZ DevTools: adding the flag to initialize VIZ DevTools

The flag --enable-viz-devtools will be used to initialize Viz DevTools server and
observe Viz Display Compositor objects from the GPU process. Now on creating of the
DevTools server from the browser process we pass the flag we need to search for in
the command line to determine whether to enable devtools or not and a default port
number to run the server on. When we start chrome along with the devtools flag we
can specify the port number we want the server to run on, but it is optional, so
if nothing's specified we pass the default port number to run the server on.
Later the GPU process will also pass its corresponding parameters.

Bug: 816802
Cq-Include-Trybots: master.tryserver.chromium.android:android_optional_gpu_tests_rel
Change-Id: I8f5e461758cf7aa0e575680e659c45232a9fd8e2
Reviewed-on: https://chromium-review.googlesource.com/943247Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Reviewed-by: default avatarAntoine Labour <piman@chromium.org>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Commit-Queue: Illia Martyniuk <illiam@google.com>
Cr-Commit-Position: refs/heads/master@{#542931}
parent 3804ffa0
......@@ -17,6 +17,7 @@
#if defined(USE_AURA)
#include "base/run_loop.h"
#include "components/ui_devtools/devtools_server.h"
#include "components/ui_devtools/switches.h"
#include "components/ui_devtools/views/css_agent.h"
#include "components/ui_devtools/views/dom_agent.h"
#include "components/ui_devtools/views/overlay_agent.h"
......@@ -113,7 +114,8 @@ void ChromeBrowserMainExtraPartsViews::PreProfileInit() {
IMEDriver::Register();
// Start devtools server
devtools_server_ = ui_devtools::UiDevToolsServer::Create(nullptr);
devtools_server_ = ui_devtools::UiDevToolsServer::Create(
nullptr, ui_devtools::kEnableUiDevTools, 9223);
if (devtools_server_) {
auto dom_backend = std::make_unique<ui_devtools::DOMAgent>();
auto overlay_backend =
......
......@@ -28,20 +28,20 @@ namespace {
const char kChromeDeveloperToolsPrefix[] =
"chrome-devtools://devtools/bundled/inspector.html?ws=";
bool IsUiDevToolsEnabled() {
return base::CommandLine::ForCurrentProcess()->HasSwitch(kEnableUiDevTools);
bool IsDevToolsEnabled(const char* enable_devtools_flag) {
return base::CommandLine::ForCurrentProcess()->HasSwitch(
enable_devtools_flag);
}
int GetUiDevToolsPort() {
DCHECK(IsUiDevToolsEnabled());
int GetUiDevToolsPort(const char* enable_devtools_flag, int default_port) {
DCHECK(IsDevToolsEnabled(enable_devtools_flag));
// This value is duplicated in the chrome://flags description.
constexpr int kDefaultPort = 9223;
int port;
if (!base::StringToInt(
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
kEnableUiDevTools),
enable_devtools_flag),
&port))
port = kDefaultPort;
port = default_port;
return port;
}
......@@ -71,8 +71,11 @@ constexpr net::NetworkTrafficAnnotationTag kUIDevtoolsServer =
UiDevToolsServer* UiDevToolsServer::devtools_server_ = nullptr;
UiDevToolsServer::UiDevToolsServer(
scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner)
: io_thread_task_runner_(io_thread_task_runner) {
scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner,
const char* enable_devtools_flag,
int default_port)
: io_thread_task_runner_(io_thread_task_runner),
port_(GetUiDevToolsPort(enable_devtools_flag, default_port)) {
DCHECK(!devtools_server_);
main_thread_task_runner_ = base::ThreadTaskRunnerHandle::Get();
devtools_server_ = this;
......@@ -96,12 +99,15 @@ UiDevToolsServer::~UiDevToolsServer() {
// static
std::unique_ptr<UiDevToolsServer> UiDevToolsServer::Create(
scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner) {
scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner,
const char* enable_devtools_flag,
int default_port) {
std::unique_ptr<UiDevToolsServer> server;
if (IsUiDevToolsEnabled() && !devtools_server_) {
if (IsDevToolsEnabled(enable_devtools_flag) && !devtools_server_) {
// TODO(mhashmi): Change port if more than one inspectable clients
server.reset(new UiDevToolsServer(io_thread_task_runner));
server->Start("0.0.0.0", GetUiDevToolsPort());
server.reset(new UiDevToolsServer(io_thread_task_runner,
enable_devtools_flag, default_port));
server->Start("0.0.0.0");
}
return server;
}
......@@ -118,7 +124,7 @@ UiDevToolsServer::GetClientNamesAndUrls() {
pairs.push_back(std::pair<std::string, std::string>(
devtools_server_->clients_[i]->name(),
base::StringPrintf("%s0.0.0.0:%d/%" PRIuS, kChromeDeveloperToolsPrefix,
GetUiDevToolsPort(), i)));
devtools_server_->port(), i)));
}
return pairs;
}
......@@ -135,19 +141,18 @@ void UiDevToolsServer::SendOverWebSocket(int connection_id,
message, kUIDevtoolsServer));
}
void UiDevToolsServer::Start(const std::string& address_string, uint16_t port) {
void UiDevToolsServer::Start(const std::string& address_string) {
io_thread_task_runner_->PostTask(
FROM_HERE, base::Bind(&UiDevToolsServer::StartServer,
base::Unretained(this), address_string, port));
base::Unretained(this), address_string));
}
void UiDevToolsServer::StartServer(const std::string& address_string,
uint16_t port) {
void UiDevToolsServer::StartServer(const std::string& address_string) {
DCHECK(!server_);
std::unique_ptr<net::ServerSocket> socket(
new net::TCPServerSocket(nullptr, net::NetLogSource()));
constexpr int kBacklog = 1;
if (socket->ListenWithAddressAndPort(address_string, port, kBacklog) !=
if (socket->ListenWithAddressAndPort(address_string, port_, kBacklog) !=
net::OK)
return;
server_ = std::make_unique<net::HttpServer>(std::move(socket), this);
......
......@@ -25,9 +25,12 @@ class UI_DEVTOOLS_EXPORT UiDevToolsServer : public net::HttpServer::Delegate {
~UiDevToolsServer() override;
// Returns an empty unique_ptr if ui devtools flag isn't enabled or if a
// server instance has already been created.
// server instance has already been created. Server doesn't know anything
// about the caller, so both UI and Viz pass their corresponding params.
static std::unique_ptr<UiDevToolsServer> Create(
scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner);
scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner,
const char* enable_devtools_flag,
int default_port);
// Returns a list of attached UiDevToolsClient name + URL
using NameUrlPair = std::pair<std::string, std::string>;
......@@ -36,12 +39,16 @@ class UI_DEVTOOLS_EXPORT UiDevToolsServer : public net::HttpServer::Delegate {
void AttachClient(std::unique_ptr<UiDevToolsClient> client);
void SendOverWebSocket(int connection_id, const String& message);
int port() const { return port_; }
private:
explicit UiDevToolsServer(
scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner);
scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner,
const char* enable_devtools_flag,
int default_port);
void Start(const std::string& address_string, uint16_t port);
void StartServer(const std::string& address_string, uint16_t port);
void Start(const std::string& address_string);
void StartServer(const std::string& address_string);
// HttpServer::Delegate
void OnConnect(int connection_id) override;
......@@ -62,6 +69,9 @@ class UI_DEVTOOLS_EXPORT UiDevToolsServer : public net::HttpServer::Delegate {
scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner_;
scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_;
// The port the devtools server listens on
const int port_;
// The server (owned by ash for now)
static UiDevToolsServer* devtools_server_;
......
......@@ -20,6 +20,10 @@ const char kDeadlineToSynchronizeSurfaces[] =
// by the parent compositor.
const char kEnableSurfaceSynchronization[] = "enable-surface-synchronization";
// Enables inspecting Viz Display Compositor objects. Default port is 9229.
// For local inspection use chrome://inspect#other
const char kEnableVizDevTools[] = "enable-viz-devtools";
// Effectively disables pipelining of compositor frame production stages by
// waiting for each stage to finish before completing a frame.
const char kRunAllCompositorStagesBeforeDraw[] =
......
......@@ -16,6 +16,7 @@ namespace switches {
// Keep list in alphabetical order.
VIZ_COMMON_EXPORT extern const char kDeadlineToSynchronizeSurfaces[];
VIZ_COMMON_EXPORT extern const char kEnableSurfaceSynchronization[];
VIZ_COMMON_EXPORT extern const char kEnableVizDevTools[];
VIZ_COMMON_EXPORT extern const char kRunAllCompositorStagesBeforeDraw[];
VIZ_COMMON_EXPORT extern const char kUseVizHitTestSurfaceLayer[];
......
......@@ -142,6 +142,7 @@ static const char* const kSwitchNames[] = {
switches::kEnableHeapProfiling,
switches::kEnableLogging,
switches::kEnableOOPRasterization,
switches::kEnableVizDevTools,
switches::kHeadless,
switches::kLoggingLevel,
switches::kEnableLowEndDeviceMode,
......
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