Rename SkyDebugger to KioskWM and move to /services
Already other applications use sky's simple window manager (mojo:sky_debugger) as a full-screen window manager. This moves this to /services and removes all sky references from it. As a part of this I've removed inspector support from skydb. It was already broken and will need to be re-thought to not involve calls into this new window manager. I'm also flipping the relationship between prompt.cc and debugger.cc for skydb. Skydb will tell mojo_shell to start sky_debugger_prompt instead of sky_debugger. I'm also renaming sky_debugger_prompt to be sky_debugger. R=abarth@chromium.org BUG= Review URL: https://codereview.chromium.org/883983004
This commit is contained in:
@@ -3,44 +3,36 @@
|
||||
# found in the LICENSE file.
|
||||
|
||||
import("//mojo/public/mojo_application.gni")
|
||||
import("//mojo/public/tools/bindings/mojom.gni")
|
||||
|
||||
group("debugger") {
|
||||
testonly = true
|
||||
|
||||
deps = [
|
||||
"//sky/tools/debugger/prompt",
|
||||
":sky_debugger",
|
||||
]
|
||||
}
|
||||
|
||||
mojo_native_application("sky_debugger") {
|
||||
output_name = "sky_debugger"
|
||||
|
||||
sources = [
|
||||
"debugger.cc",
|
||||
"debugger.h",
|
||||
"main.cc",
|
||||
"navigator_host_impl.cc",
|
||||
"navigator_host_impl.h",
|
||||
"trace_collector.cc",
|
||||
"trace_collector.h",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//base",
|
||||
"//base/allocator",
|
||||
"//mojo/application",
|
||||
"//mojo/converters/geometry",
|
||||
"//mojo/converters/input_events",
|
||||
"//mojo/common",
|
||||
"//mojo/public/cpp/bindings",
|
||||
"//mojo/public/cpp/system",
|
||||
"//mojo/public/cpp/utility",
|
||||
"//mojo/services/input_events/public/interfaces",
|
||||
"//mojo/services/navigation/public/interfaces",
|
||||
"//mojo/services/view_manager/public/cpp",
|
||||
"//services/window_manager:lib",
|
||||
"//mojo/services/window_manager/public/interfaces",
|
||||
"//net",
|
||||
"//net:http_server",
|
||||
"//services/tracing:bindings",
|
||||
"//sky/viewer:bindings",
|
||||
":bindings",
|
||||
]
|
||||
}
|
||||
|
||||
mojom("bindings") {
|
||||
sources = [
|
||||
"debugger.mojom",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -2,132 +2,217 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "sky/tools/debugger/debugger.h"
|
||||
#include <algorithm>
|
||||
|
||||
#include "services/window_manager/basic_focus_rules.h"
|
||||
#include "base/bind.h"
|
||||
#include "base/debug/profiler.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "base/strings/string_number_conversions.h"
|
||||
#include "base/strings/stringprintf.h"
|
||||
#include "mojo/application/application_runner_chromium.h"
|
||||
#include "mojo/public/c/system/main.h"
|
||||
#include "mojo/public/cpp/application/application_delegate.h"
|
||||
#include "mojo/public/cpp/application/application_impl.h"
|
||||
#include "mojo/services/window_manager/public/interfaces/window_manager.mojom.h"
|
||||
#include "net/base/net_errors.h"
|
||||
#include "net/server/http_server.h"
|
||||
#include "net/server/http_server_request_info.h"
|
||||
#include "net/socket/tcp_server_socket.h"
|
||||
#include "services/tracing/tracing.mojom.h"
|
||||
#include "sky/tools/debugger/trace_collector.h"
|
||||
|
||||
namespace sky {
|
||||
namespace debugger {
|
||||
namespace {
|
||||
|
||||
SkyDebugger::SkyDebugger()
|
||||
: window_manager_app_(new window_manager::WindowManagerApp(this, this)),
|
||||
root_(nullptr),
|
||||
content_(nullptr),
|
||||
navigator_host_factory_(this),
|
||||
weak_factory_(this) {
|
||||
exposed_services_impl_.AddService(&navigator_host_factory_);
|
||||
const size_t kMinSendBufferSize = 1024 * 1024;
|
||||
}
|
||||
|
||||
SkyDebugger::~SkyDebugger() {
|
||||
}
|
||||
class SkyDebugger : public mojo::ApplicationDelegate,
|
||||
public net::HttpServer::Delegate {
|
||||
public:
|
||||
SkyDebugger() : is_tracing_(false), weak_ptr_factory_(this) {}
|
||||
virtual ~SkyDebugger() {}
|
||||
|
||||
base::WeakPtr<SkyDebugger> SkyDebugger::GetWeakPtr() {
|
||||
return weak_factory_.GetWeakPtr();
|
||||
}
|
||||
private:
|
||||
// Overridden from mojo::ApplicationDelegate:
|
||||
virtual void Initialize(mojo::ApplicationImpl* app) override {
|
||||
app->ConnectToService("mojo:tracing", &tracing_);
|
||||
// Format: --args-for="app_url command_port"
|
||||
if (app->args().size() < 2) {
|
||||
LOG(ERROR) << "--args-for required to specify command_port";
|
||||
mojo::ApplicationImpl::Terminate();
|
||||
return;
|
||||
}
|
||||
|
||||
void SkyDebugger::Initialize(mojo::ApplicationImpl* app) {
|
||||
window_manager_app_->Initialize(app);
|
||||
app->ConnectToApplication("mojo:sky_debugger_prompt");
|
||||
base::StringToUint(app->args()[1], &command_port_);
|
||||
|
||||
// Format: --args-for="app_url default_url"
|
||||
if (app->args().size() > 1)
|
||||
default_url_ = app->args()[1];
|
||||
}
|
||||
scoped_ptr<net::ServerSocket> server_socket(
|
||||
new net::TCPServerSocket(NULL, net::NetLog::Source()));
|
||||
int result =
|
||||
server_socket->ListenWithAddressAndPort("0.0.0.0", command_port_, 1);
|
||||
if (result != net::OK) {
|
||||
LOG(ERROR) << "Failed to bind to port " << command_port_
|
||||
<< " skydb commands will not work.";
|
||||
mojo::ApplicationImpl::Terminate();
|
||||
return;
|
||||
}
|
||||
web_server_.reset(new net::HttpServer(server_socket.Pass(), this));
|
||||
|
||||
bool SkyDebugger::ConfigureIncomingConnection(
|
||||
mojo::ApplicationConnection* connection) {
|
||||
window_manager_app_->ConfigureIncomingConnection(connection);
|
||||
connection->AddService(this);
|
||||
|
||||
if (!default_url_.empty())
|
||||
NavigateToURL(default_url_); // Schedule a navigation in the new embedding.
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SkyDebugger::ConfigureOutgoingConnection(
|
||||
mojo::ApplicationConnection* connection) {
|
||||
window_manager_app_->ConfigureOutgoingConnection(connection);
|
||||
connection->AddService(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
void SkyDebugger::OnEmbed(
|
||||
mojo::View* root,
|
||||
mojo::InterfaceRequest<mojo::ServiceProvider> services,
|
||||
mojo::ServiceProviderPtr exposed_services) {
|
||||
root_ = root;
|
||||
root_->AddObserver(this);
|
||||
|
||||
window_manager_app_->SetViewportSize(gfx::Size(320, 640));
|
||||
|
||||
content_ = root->view_manager()->CreateView();
|
||||
content_->SetBounds(root_->bounds());
|
||||
root_->AddChild(content_);
|
||||
content_->SetVisible(true);
|
||||
|
||||
window_manager_app_->InitFocus(
|
||||
make_scoped_ptr(new window_manager::BasicFocusRules(root_)));
|
||||
|
||||
if (!pending_url_.empty())
|
||||
NavigateToURL(pending_url_);
|
||||
}
|
||||
|
||||
void SkyDebugger::Embed(const mojo::String& url,
|
||||
mojo::InterfaceRequest<mojo::ServiceProvider> services,
|
||||
mojo::ServiceProviderPtr exposed_services) {
|
||||
content_->Embed(url, nullptr, nullptr);
|
||||
}
|
||||
|
||||
void SkyDebugger::OnViewManagerDisconnected(mojo::ViewManager* view_manager) {
|
||||
root_ = nullptr;
|
||||
}
|
||||
|
||||
void SkyDebugger::OnViewDestroyed(mojo::View* view) {
|
||||
view->RemoveObserver(this);
|
||||
}
|
||||
|
||||
void SkyDebugger::OnViewBoundsChanged(mojo::View* view,
|
||||
const mojo::Rect& old_bounds,
|
||||
const mojo::Rect& new_bounds) {
|
||||
content_->SetBounds(new_bounds);
|
||||
}
|
||||
|
||||
void SkyDebugger::Create(mojo::ApplicationConnection* connection,
|
||||
mojo::InterfaceRequest<Debugger> request) {
|
||||
mojo::WeakBindToRequest(this, &request);
|
||||
}
|
||||
|
||||
void SkyDebugger::NavigateToURL(const mojo::String& url) {
|
||||
// We can get Navigate commands before we've actually been
|
||||
// embedded into the view and content_ created.
|
||||
// Just save the last one.
|
||||
if (content_) {
|
||||
mojo::ServiceProviderPtr exposed_services;
|
||||
exposed_services_impl_.Bind(GetProxy(&exposed_services));
|
||||
content_->Embed(url, GetProxy(&viewer_services_), exposed_services.Pass());
|
||||
} else {
|
||||
pending_url_ = url;
|
||||
app->ConnectToService("mojo:window_manager", &window_manager_);
|
||||
}
|
||||
}
|
||||
|
||||
void SkyDebugger::Shutdown() {
|
||||
// Make sure we shut down mojo before quitting the message loop or things
|
||||
// like blink::shutdown() may try to talk to the message loop and crash.
|
||||
window_manager_app_.reset();
|
||||
virtual bool ConfigureIncomingConnection(
|
||||
mojo::ApplicationConnection* connection) override {
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO(eseidel): This still hits an X11 error which I don't understand
|
||||
// "X Error of failed request: GLXBadDrawable", crbug.com/430581
|
||||
mojo::ApplicationImpl::Terminate();
|
||||
// TODO(eseidel): REMOVE THIS, temporarily fast-exit now to stop confusing
|
||||
// folks with exit-time crashes due to GLXBadDrawable above.
|
||||
exit(0);
|
||||
}
|
||||
// net::HttpServer::Delegate
|
||||
void OnConnect(int connection_id) override {}
|
||||
|
||||
void SkyDebugger::InjectInspector() {
|
||||
InspectorServicePtr inspector_service;
|
||||
mojo::ConnectToService(viewer_services_.get(), &inspector_service);
|
||||
inspector_service->Inject();
|
||||
}
|
||||
void OnClose(int connection_id) override {}
|
||||
|
||||
void OnHttpRequest(int connection_id,
|
||||
const net::HttpServerRequestInfo& info) override {
|
||||
// FIXME: We should use use a fancier lookup system more like what
|
||||
// services/http_server/http_server.cc does with AddHandler.
|
||||
if (info.path == "/reload")
|
||||
Load(connection_id, url_);
|
||||
else if (info.path == "/quit")
|
||||
Quit(connection_id);
|
||||
else if (info.path == "/load")
|
||||
Load(connection_id, info.data);
|
||||
else if (info.path == "/start_profiling")
|
||||
StartProfiling(connection_id);
|
||||
else if (info.path == "/stop_profiling")
|
||||
StopProfiling(connection_id);
|
||||
else if (info.path == "/start_tracing")
|
||||
StartTracing(connection_id);
|
||||
else if (info.path == "/stop_tracing")
|
||||
StopTracing(connection_id);
|
||||
else
|
||||
Help(info.path, connection_id);
|
||||
}
|
||||
|
||||
void OnWebSocketRequest(int connection_id,
|
||||
const net::HttpServerRequestInfo& info) override {
|
||||
Error(connection_id, "OnWebSocketRequest not implemented");
|
||||
}
|
||||
|
||||
void OnWebSocketMessage(int connection_id, const std::string& data) override {
|
||||
Error(connection_id, "OnWebSocketMessage not implemented");
|
||||
}
|
||||
|
||||
void Error(int connection_id, std::string message) {
|
||||
web_server_->Send500(connection_id, message);
|
||||
}
|
||||
|
||||
void Respond(int connection_id, std::string response) {
|
||||
// When sending tracing data back over the wire to the client, we can blow
|
||||
// through the default send buffer size.
|
||||
web_server_->SetSendBufferSize(
|
||||
connection_id, std::max(kMinSendBufferSize, response.length()));
|
||||
web_server_->Send200(connection_id, response, "text/plain");
|
||||
}
|
||||
|
||||
void Help(std::string path, int connection_id) {
|
||||
std::string help = base::StringPrintf(
|
||||
"Sky Debugger running on port %d\n"
|
||||
"Supported URLs:\n"
|
||||
"/reload -- Reload the current page\n"
|
||||
"/quit -- Quit\n"
|
||||
"/load -- Load a new URL, url in POST body.\n",
|
||||
command_port_);
|
||||
if (path != "/")
|
||||
help = "Unknown path: " + path + "\n\n" + help;
|
||||
Respond(connection_id, help);
|
||||
}
|
||||
|
||||
void Load(int connection_id, std::string url) {
|
||||
url_ = url;
|
||||
Reload();
|
||||
std::string response = std::string("Loaded ") + url + "\n";
|
||||
Respond(connection_id, response);
|
||||
}
|
||||
|
||||
void Reload() {
|
||||
// SimpleWindowManager will wire up necessary services on our behalf.
|
||||
window_manager_->Embed(url_, nullptr, nullptr);
|
||||
}
|
||||
|
||||
void Quit(int connection_id) {
|
||||
// TODO(eseidel): We should orderly shutdown once mojo can.
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void StartTracing(int connection_id) {
|
||||
if (is_tracing_) {
|
||||
Error(connection_id, "Already tracing. Use stop_tracing to stop.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
is_tracing_ = true;
|
||||
mojo::DataPipe pipe;
|
||||
tracing_->Start(pipe.producer_handle.Pass(), mojo::String("*"));
|
||||
trace_collector_.reset(new TraceCollector(pipe.consumer_handle.Pass()));
|
||||
Respond(connection_id, "Starting trace (type 'stop_tracing' to stop)\n");
|
||||
}
|
||||
|
||||
void StopTracing(int connection_id) {
|
||||
if (!is_tracing_) {
|
||||
Error(connection_id, "Not tracing yet. Use start_tracing to start.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
is_tracing_ = false;
|
||||
tracing_->StopAndFlush();
|
||||
trace_collector_->GetTrace(base::Bind(
|
||||
&SkyDebugger::OnTraceAvailable, base::Unretained(this), connection_id));
|
||||
}
|
||||
|
||||
void OnTraceAvailable(int connection_id, std::string trace) {
|
||||
trace_collector_.reset();
|
||||
Respond(connection_id, trace);
|
||||
}
|
||||
|
||||
void StartProfiling(int connection_id) {
|
||||
#if !defined(NDEBUG) || !defined(ENABLE_PROFILING)
|
||||
Error(connection_id,
|
||||
"Profiling requires is_debug=false and enable_profiling=true");
|
||||
return;
|
||||
#else
|
||||
base::debug::StartProfiling("sky_viewer.pprof");
|
||||
Respond(connection_id, "Starting profiling (stop with 'stop_profiling')");
|
||||
#endif
|
||||
}
|
||||
|
||||
void StopProfiling(int connection_id) {
|
||||
if (!base::debug::BeingProfiled()) {
|
||||
Error(connection_id, "Profiling not started");
|
||||
return;
|
||||
}
|
||||
base::debug::StopProfiling();
|
||||
Respond(connection_id, "Stopped profiling");
|
||||
}
|
||||
|
||||
bool is_tracing_;
|
||||
mojo::WindowManagerPtr window_manager_;
|
||||
tracing::TraceCoordinatorPtr tracing_;
|
||||
std::string url_;
|
||||
base::WeakPtrFactory<SkyDebugger> weak_ptr_factory_;
|
||||
scoped_ptr<net::HttpServer> web_server_;
|
||||
uint32_t command_port_;
|
||||
|
||||
scoped_ptr<TraceCollector> trace_collector_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(SkyDebugger);
|
||||
};
|
||||
|
||||
} // namespace debugger
|
||||
} // namespace sky
|
||||
|
||||
MojoResult MojoMain(MojoHandle shell_handle) {
|
||||
mojo::ApplicationRunnerChromium runner(new sky::debugger::SkyDebugger);
|
||||
runner.set_message_loop_type(base::MessageLoop::TYPE_IO);
|
||||
return runner.Run(shell_handle);
|
||||
}
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
// Copyright 2014 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "mojo/public/cpp/application/application_delegate.h"
|
||||
#include "mojo/public/cpp/application/application_impl.h"
|
||||
#include "mojo/public/cpp/application/connect.h"
|
||||
#include "mojo/public/cpp/application/service_provider_impl.h"
|
||||
#include "mojo/services/input_events/public/interfaces/input_events.mojom.h"
|
||||
#include "mojo/services/navigation/public/interfaces/navigation.mojom.h"
|
||||
#include "mojo/services/view_manager/public/cpp/view_manager.h"
|
||||
#include "mojo/services/view_manager/public/cpp/view_manager_delegate.h"
|
||||
#include "mojo/services/view_manager/public/cpp/view_observer.h"
|
||||
#include "services/window_manager/window_manager_app.h"
|
||||
#include "services/window_manager/window_manager_delegate.h"
|
||||
#include "sky/tools/debugger/debugger.mojom.h"
|
||||
#include "sky/tools/debugger/navigator_host_impl.h"
|
||||
#include "sky/viewer/services/inspector.mojom.h"
|
||||
|
||||
namespace sky {
|
||||
namespace debugger {
|
||||
|
||||
class SkyDebugger : public mojo::ApplicationDelegate,
|
||||
public mojo::ViewManagerDelegate,
|
||||
public mojo::ViewObserver,
|
||||
public mojo::InterfaceFactory<Debugger>,
|
||||
public mojo::InterfaceImpl<Debugger>,
|
||||
public window_manager::WindowManagerDelegate {
|
||||
public:
|
||||
SkyDebugger();
|
||||
virtual ~SkyDebugger();
|
||||
|
||||
base::WeakPtr<SkyDebugger> GetWeakPtr();
|
||||
|
||||
// Overridden from Debugger
|
||||
void NavigateToURL(const mojo::String& url) override;
|
||||
void InjectInspector() override;
|
||||
void Shutdown() override;
|
||||
|
||||
private:
|
||||
// Overridden from mojo::ApplicationDelegate:
|
||||
void Initialize(mojo::ApplicationImpl* app) override;
|
||||
bool ConfigureIncomingConnection(
|
||||
mojo::ApplicationConnection* connection) override;
|
||||
bool ConfigureOutgoingConnection(
|
||||
mojo::ApplicationConnection* connection) override;
|
||||
|
||||
// Overridden from mojo::ViewManagerDelegate:
|
||||
void OnEmbed(mojo::View* root,
|
||||
mojo::InterfaceRequest<mojo::ServiceProvider> services,
|
||||
mojo::ServiceProviderPtr exposed_services) override;
|
||||
void OnViewManagerDisconnected(mojo::ViewManager* view_manager) override;
|
||||
|
||||
// Overriden from mojo::ViewObserver:
|
||||
void OnViewDestroyed(mojo::View* view) override;
|
||||
void OnViewBoundsChanged(mojo::View* view,
|
||||
const mojo::Rect& old_bounds,
|
||||
const mojo::Rect& new_bounds) override;
|
||||
|
||||
// Overridden from InterfaceFactory<Debugger>:
|
||||
void Create(mojo::ApplicationConnection* connection,
|
||||
mojo::InterfaceRequest<Debugger> request) override;
|
||||
|
||||
// Overridden from WindowManagerDelegate
|
||||
void Embed(const mojo::String& url,
|
||||
mojo::InterfaceRequest<mojo::ServiceProvider> services,
|
||||
mojo::ServiceProviderPtr exposed_services) override;
|
||||
|
||||
scoped_ptr<window_manager::WindowManagerApp> window_manager_app_;
|
||||
|
||||
// TODO(eseidel): This is per-embedding state and should be separate
|
||||
// from the ApplicationDelegate!
|
||||
mojo::View* root_;
|
||||
mojo::View* content_;
|
||||
std::string default_url_;
|
||||
std::string pending_url_;
|
||||
|
||||
mojo::ServiceProviderPtr viewer_services_;
|
||||
|
||||
NavigatorHostFactory navigator_host_factory_;
|
||||
mojo::ServiceProviderImpl exposed_services_impl_;
|
||||
|
||||
base::WeakPtrFactory<SkyDebugger> weak_factory_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(SkyDebugger);
|
||||
};
|
||||
|
||||
} // namespace debugger
|
||||
} // namespace sky
|
||||
@@ -1,11 +0,0 @@
|
||||
// Copyright 2014 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
module sky;
|
||||
|
||||
interface Debugger {
|
||||
NavigateToURL(string url);
|
||||
InjectInspector();
|
||||
Shutdown();
|
||||
};
|
||||
@@ -1,13 +0,0 @@
|
||||
// Copyright 2014 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "mojo/application/application_runner_chromium.h"
|
||||
#include "mojo/public/c/system/main.h"
|
||||
|
||||
#include "sky/tools/debugger/debugger.h"
|
||||
|
||||
MojoResult MojoMain(MojoHandle shell_handle) {
|
||||
mojo::ApplicationRunnerChromium runner(new sky::debugger::SkyDebugger);
|
||||
return runner.Run(shell_handle);
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
// Copyright 2014 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "sky/tools/debugger/navigator_host_impl.h"
|
||||
|
||||
#include "sky/tools/debugger/debugger.h"
|
||||
|
||||
namespace sky {
|
||||
namespace debugger {
|
||||
|
||||
NavigatorHostImpl::NavigatorHostImpl(SkyDebugger* debugger)
|
||||
: debugger_(debugger->GetWeakPtr()) {
|
||||
}
|
||||
|
||||
NavigatorHostImpl::~NavigatorHostImpl() {
|
||||
}
|
||||
|
||||
void NavigatorHostImpl::DidNavigateLocally(const mojo::String& url) {
|
||||
// TODO(abarth): Do something interesting.
|
||||
}
|
||||
|
||||
void NavigatorHostImpl::RequestNavigate(mojo::Target target,
|
||||
mojo::URLRequestPtr request) {
|
||||
if (!debugger_)
|
||||
return;
|
||||
debugger_->NavigateToURL(request->url);
|
||||
}
|
||||
|
||||
} // namespace debugger
|
||||
} // namespace sky
|
||||
@@ -1,37 +0,0 @@
|
||||
// Copyright 2014 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef SKY_TOOLS_DEBUGGER_NAVIGATOR_HOST_IMPL_H_
|
||||
#define SKY_TOOLS_DEBUGGER_NAVIGATOR_HOST_IMPL_H_
|
||||
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "mojo/public/cpp/application/interface_factory_impl.h"
|
||||
#include "mojo/services/navigation/public/interfaces/navigation.mojom.h"
|
||||
#include "sky/tools/debugger/debugger.mojom.h"
|
||||
|
||||
namespace sky {
|
||||
namespace debugger {
|
||||
class SkyDebugger;
|
||||
|
||||
class NavigatorHostImpl : public mojo::InterfaceImpl<mojo::NavigatorHost> {
|
||||
public:
|
||||
explicit NavigatorHostImpl(SkyDebugger*);
|
||||
~NavigatorHostImpl();
|
||||
|
||||
private:
|
||||
void DidNavigateLocally(const mojo::String& url) override;
|
||||
void RequestNavigate(mojo::Target target, mojo::URLRequestPtr request) override;
|
||||
|
||||
base::WeakPtr<SkyDebugger> debugger_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(NavigatorHostImpl);
|
||||
};
|
||||
|
||||
typedef mojo::InterfaceFactoryImplWithContext<
|
||||
NavigatorHostImpl, SkyDebugger> NavigatorHostFactory;
|
||||
|
||||
} // namespace debugger
|
||||
} // namespace sky
|
||||
|
||||
#endif // SKY_TOOLS_DEBUGGER_NAVIGATOR_HOST_IMPL_H_
|
||||
@@ -1,30 +0,0 @@
|
||||
# Copyright 2014 The Chromium Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
import("//mojo/public/mojo_application.gni")
|
||||
|
||||
mojo_native_application("prompt") {
|
||||
output_name = "sky_debugger_prompt"
|
||||
|
||||
sources = [
|
||||
"prompt.cc",
|
||||
"trace_collector.cc",
|
||||
"trace_collector.h",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//base",
|
||||
"//base/allocator",
|
||||
"//mojo/application",
|
||||
"//mojo/common",
|
||||
"//mojo/public/cpp/bindings",
|
||||
"//mojo/public/cpp/system",
|
||||
"//mojo/public/cpp/utility",
|
||||
"//net",
|
||||
"//net:http_server",
|
||||
"//services/tracing:bindings",
|
||||
"//sky/tools/debugger:bindings",
|
||||
"//sky/viewer:bindings",
|
||||
]
|
||||
}
|
||||
@@ -1,230 +0,0 @@
|
||||
// Copyright 2014 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "base/bind.h"
|
||||
#include "base/debug/profiler.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "base/strings/string_number_conversions.h"
|
||||
#include "base/strings/stringprintf.h"
|
||||
#include "mojo/application/application_runner_chromium.h"
|
||||
#include "mojo/public/c/system/main.h"
|
||||
#include "mojo/public/cpp/application/application_delegate.h"
|
||||
#include "mojo/public/cpp/application/application_impl.h"
|
||||
#include "net/base/net_errors.h"
|
||||
#include "net/server/http_server.h"
|
||||
#include "net/server/http_server_request_info.h"
|
||||
#include "net/socket/tcp_server_socket.h"
|
||||
#include "services/tracing/tracing.mojom.h"
|
||||
#include "sky/tools/debugger/debugger.mojom.h"
|
||||
#include "sky/tools/debugger/prompt/trace_collector.h"
|
||||
|
||||
namespace sky {
|
||||
namespace debugger {
|
||||
namespace {
|
||||
|
||||
const size_t kMinSendBufferSize = 1024 * 1024;
|
||||
}
|
||||
|
||||
class Prompt : public mojo::ApplicationDelegate,
|
||||
public net::HttpServer::Delegate {
|
||||
public:
|
||||
Prompt()
|
||||
: is_tracing_(false),
|
||||
weak_ptr_factory_(this) {
|
||||
}
|
||||
virtual ~Prompt() {
|
||||
}
|
||||
|
||||
private:
|
||||
// Overridden from mojo::ApplicationDelegate:
|
||||
virtual void Initialize(mojo::ApplicationImpl* app) override {
|
||||
app->ConnectToService("mojo:tracing", &tracing_);
|
||||
// Format: --args-for="app_url command_port"
|
||||
if (app->args().size() < 2) {
|
||||
LOG(ERROR) << "--args-for required to specify command_port";
|
||||
mojo::ApplicationImpl::Terminate();
|
||||
return;
|
||||
}
|
||||
|
||||
base::StringToUint(app->args()[1], &command_port_);
|
||||
|
||||
scoped_ptr<net::ServerSocket> server_socket(
|
||||
new net::TCPServerSocket(NULL, net::NetLog::Source()));
|
||||
int result = server_socket->ListenWithAddressAndPort("0.0.0.0", command_port_, 1);
|
||||
if (result != net::OK) {
|
||||
LOG(ERROR) << "Failed to bind to port " << command_port_
|
||||
<< " skydb commands will not work.";
|
||||
mojo::ApplicationImpl::Terminate();
|
||||
return;
|
||||
}
|
||||
web_server_.reset(new net::HttpServer(server_socket.Pass(), this));
|
||||
}
|
||||
|
||||
virtual bool ConfigureIncomingConnection(
|
||||
mojo::ApplicationConnection* connection) override {
|
||||
connection->ConnectToService(&debugger_);
|
||||
return true;
|
||||
}
|
||||
|
||||
// net::HttpServer::Delegate
|
||||
void OnConnect(int connection_id) override {
|
||||
}
|
||||
|
||||
void OnClose(int connection_id) override {
|
||||
}
|
||||
|
||||
void OnHttpRequest(
|
||||
int connection_id, const net::HttpServerRequestInfo& info) override {
|
||||
|
||||
// FIXME: We should use use a fancier lookup system more like what
|
||||
// services/http_server/http_server.cc does with AddHandler.
|
||||
if (info.path == "/reload")
|
||||
Load(connection_id, url_);
|
||||
else if (info.path == "/inspect")
|
||||
Inspect(connection_id);
|
||||
else if (info.path == "/quit")
|
||||
Quit(connection_id);
|
||||
else if (info.path == "/load")
|
||||
Load(connection_id, info.data);
|
||||
else if (info.path == "/start_profiling")
|
||||
StartProfiling(connection_id);
|
||||
else if (info.path == "/stop_profiling")
|
||||
StopProfiling(connection_id);
|
||||
else if (info.path == "/start_tracing")
|
||||
StartTracing(connection_id);
|
||||
else if (info.path == "/stop_tracing")
|
||||
StopTracing(connection_id);
|
||||
else
|
||||
Help(info.path, connection_id);
|
||||
}
|
||||
|
||||
void OnWebSocketRequest(
|
||||
int connection_id, const net::HttpServerRequestInfo& info) override {
|
||||
Error(connection_id, "OnWebSocketRequest not implemented");
|
||||
}
|
||||
|
||||
void OnWebSocketMessage(
|
||||
int connection_id, const std::string& data) override {
|
||||
Error(connection_id, "OnWebSocketMessage not implemented");
|
||||
}
|
||||
|
||||
void Error(int connection_id, std::string message) {
|
||||
web_server_->Send500(connection_id, message);
|
||||
}
|
||||
|
||||
void Respond(int connection_id, std::string response) {
|
||||
// When sending tracing data back over the wire to the client, we can blow
|
||||
// through the default send buffer size.
|
||||
web_server_->SetSendBufferSize(
|
||||
connection_id, std::max(kMinSendBufferSize, response.length()));
|
||||
web_server_->Send200(connection_id, response, "text/plain");
|
||||
}
|
||||
|
||||
void Help(std::string path, int connection_id) {
|
||||
std::string help = base::StringPrintf("Sky Debugger running on port %d\n"
|
||||
"Supported URLs:\n"
|
||||
"/reload -- Reload the current page\n"
|
||||
"/quit -- Quit\n"
|
||||
"/load -- Load a new URL, url in POST body.\n",
|
||||
command_port_);
|
||||
if (path != "/")
|
||||
help = "Unknown path: " + path + "\n\n" + help;
|
||||
Respond(connection_id, help);
|
||||
}
|
||||
|
||||
void Load(int connection_id, std::string url) {
|
||||
url_ = url;
|
||||
Reload();
|
||||
std::string response = std::string("Loaded ") + url + "\n";
|
||||
Respond(connection_id, response);
|
||||
}
|
||||
|
||||
void Reload() {
|
||||
debugger_->NavigateToURL(url_);
|
||||
}
|
||||
|
||||
void Inspect(int connection_id) {
|
||||
debugger_->InjectInspector();
|
||||
Respond(connection_id,
|
||||
"Open the following URL in Chrome:\n"
|
||||
"chrome-devtools://devtools/bundled/devtools.html?ws=localhost:9898\n");
|
||||
}
|
||||
|
||||
void Quit(int connection_id) {
|
||||
debugger_->Shutdown();
|
||||
}
|
||||
|
||||
void StartTracing(int connection_id) {
|
||||
if (is_tracing_) {
|
||||
Error(connection_id, "Already tracing. Use stop_tracing to stop.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
is_tracing_ = true;
|
||||
mojo::DataPipe pipe;
|
||||
tracing_->Start(pipe.producer_handle.Pass(), mojo::String("*"));
|
||||
trace_collector_.reset(new TraceCollector(pipe.consumer_handle.Pass()));
|
||||
Respond(connection_id, "Starting trace (type 'stop_tracing' to stop)\n");
|
||||
}
|
||||
|
||||
void StopTracing(int connection_id) {
|
||||
if (!is_tracing_) {
|
||||
Error(connection_id, "Not tracing yet. Use start_tracing to start.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
is_tracing_ = false;
|
||||
tracing_->StopAndFlush();
|
||||
trace_collector_->GetTrace(base::Bind(
|
||||
&Prompt::OnTraceAvailable, base::Unretained(this), connection_id));
|
||||
}
|
||||
|
||||
void OnTraceAvailable(int connection_id, std::string trace) {
|
||||
trace_collector_.reset();
|
||||
Respond(connection_id, trace);
|
||||
}
|
||||
|
||||
void StartProfiling(int connection_id) {
|
||||
#if !defined(NDEBUG) || !defined(ENABLE_PROFILING)
|
||||
Error(connection_id,
|
||||
"Profiling requires is_debug=false and enable_profiling=true");
|
||||
return;
|
||||
#else
|
||||
base::debug::StartProfiling("sky_viewer.pprof");
|
||||
Respond(connection_id, "Starting profiling (stop with 'stop_profiling')");
|
||||
#endif
|
||||
}
|
||||
|
||||
void StopProfiling(int connection_id) {
|
||||
if (!base::debug::BeingProfiled()) {
|
||||
Error(connection_id, "Profiling not started");
|
||||
return;
|
||||
}
|
||||
base::debug::StopProfiling();
|
||||
Respond(connection_id, "Stopped profiling");
|
||||
}
|
||||
|
||||
bool is_tracing_;
|
||||
DebuggerPtr debugger_;
|
||||
tracing::TraceCoordinatorPtr tracing_;
|
||||
std::string url_;
|
||||
base::WeakPtrFactory<Prompt> weak_ptr_factory_;
|
||||
scoped_ptr<net::HttpServer> web_server_;
|
||||
uint32_t command_port_;
|
||||
|
||||
scoped_ptr<TraceCollector> trace_collector_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(Prompt);
|
||||
};
|
||||
|
||||
} // namespace debugger
|
||||
} // namespace sky
|
||||
|
||||
MojoResult MojoMain(MojoHandle shell_handle) {
|
||||
mojo::ApplicationRunnerChromium runner(new sky::debugger::Prompt);
|
||||
runner.set_message_loop_type(base::MessageLoop::TYPE_IO);
|
||||
return runner.Run(shell_handle);
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "sky/tools/debugger/prompt/trace_collector.h"
|
||||
#include "sky/tools/debugger/trace_collector.h"
|
||||
|
||||
namespace sky {
|
||||
namespace debugger {
|
||||
@@ -2,8 +2,8 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef SKY_TOOLS_DEBUGGER_PROMPT_TRACE_COLLECTOR_H_
|
||||
#define SKY_TOOLS_DEBUGGER_PROMPT_TRACE_COLLECTOR_H_
|
||||
#ifndef SKY_TOOLS_DEBUGGER_TRACE_COLLECTOR_H_
|
||||
#define SKY_TOOLS_DEBUGGER_TRACE_COLLECTOR_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
@@ -37,4 +37,4 @@ class TraceCollector : public mojo::common::DataPipeDrainer::Client {
|
||||
} // namespace debugger
|
||||
} // namespace sky
|
||||
|
||||
#endif // SKY_TOOLS_DEBUGGER_PROMPT_TRACE_COLLECTOR_H_
|
||||
#endif // SKY_TOOLS_DEBUGGER_TRACE_COLLECTOR_H_
|
||||
@@ -104,9 +104,9 @@ class SkyDebugger(object):
|
||||
shell_args = [
|
||||
'--v=1',
|
||||
'--content-handlers=%s' % ','.join(content_handlers),
|
||||
'--url-mappings=mojo:window_manager=mojo:sky_debugger',
|
||||
'--args-for=mojo:sky_debugger_prompt %d' % remote_command_port,
|
||||
'mojo:window_manager',
|
||||
'--url-mappings=mojo:window_manager=mojo:kiosk_wm',
|
||||
'--args-for=mojo:sky_debugger %d' % remote_command_port,
|
||||
'mojo:sky_debugger',
|
||||
]
|
||||
|
||||
if args.url_or_path:
|
||||
@@ -574,8 +574,6 @@ class SkyDebugger(object):
|
||||
'starts tracing the running sky instance')
|
||||
self._add_basic_command(subparsers, 'reload', '/reload',
|
||||
'reload the current page')
|
||||
self._add_basic_command(subparsers, 'inspect', '/inspect',
|
||||
'start the inspector on the current page (Linux only)')
|
||||
self._add_basic_command(subparsers, 'start_profiling', '/start_profiling',
|
||||
'starts profiling the running sky instance (Linux only)')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user