From 6a04218fdbdffebd5e075111d5b3452365e11f7f Mon Sep 17 00:00:00 2001 From: Przemyslaw Pietrzkiewicz Date: Tue, 17 Feb 2015 18:18:31 +0100 Subject: [PATCH] Delete sky/services/inspector/server.cc. Sky Inspector is currently not working. This patch removes the Inspector server, which is based on net/http_server, to unblock dropping /net in Mojo. BUG=456130 R=abarth@chromium.org Review URL: https://codereview.chromium.org/931873002 --- services/inspector/BUILD.gn | 18 ---- services/inspector/inspector.mojom | 4 - services/inspector/server.cc | 154 ----------------------------- viewer/BUILD.gn | 2 - viewer/services/inspector_impl.cc | 44 --------- viewer/services/inspector_impl.h | 35 ------- 6 files changed, 257 deletions(-) delete mode 100644 services/inspector/server.cc delete mode 100644 viewer/services/inspector_impl.cc delete mode 100644 viewer/services/inspector_impl.h diff --git a/services/inspector/BUILD.gn b/services/inspector/BUILD.gn index 8eed1affbd4..5a9b3d39c16 100644 --- a/services/inspector/BUILD.gn +++ b/services/inspector/BUILD.gn @@ -2,28 +2,10 @@ # 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") import("//mojo/public/tools/bindings/mojom.gni") group("inspector") { deps = [ - ":sky_inspector_server", - ] -} - -mojo_native_application("sky_inspector_server") { - sources = [ - "server.cc", - ] - - deps = [ - "//base", - "//mojo/application", - "//mojo/common", - "//mojo/public/cpp/bindings", - "//mojo/public/cpp/utility", - "//net", - "//net:http_server", ":bindings", ] } diff --git a/services/inspector/inspector.mojom b/services/inspector/inspector.mojom index 2208720cb8d..0ed53658b24 100644 --- a/services/inspector/inspector.mojom +++ b/services/inspector/inspector.mojom @@ -4,10 +4,6 @@ module sky; -interface InspectorServer { - Listen(int32 port) => (); -}; - interface InspectorFrontend { SendMessage(string message); }; diff --git a/services/inspector/server.cc b/services/inspector/server.cc deleted file mode 100644 index ac051e90e00..00000000000 --- a/services/inspector/server.cc +++ /dev/null @@ -1,154 +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/common/weak_binding_set.h" -#include "mojo/common/weak_interface_ptr_set.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/public/cpp/bindings/binding.h" -#include "net/server/http_server.h" -#include "net/socket/tcp_server_socket.h" -#include "sky/services/inspector/inspector.mojom.h" - - -namespace sky { -namespace inspector { - -namespace { -const int kNotConnected = -1; -} - -class Server : public mojo::ApplicationDelegate, - public InspectorFrontend, - public InspectorServer, - public mojo::InterfaceFactory, - public mojo::InterfaceFactory, - public net::HttpServer::Delegate { - public: - Server() : connection_id_(kNotConnected), server_binding_(this) {} - virtual ~Server(); - - private: - // mojo::ApplicationDelegate: - void Initialize(mojo::ApplicationImpl* app) override { - } - bool ConfigureIncomingConnection( - mojo::ApplicationConnection* connection) override { - connection->AddService(this); - connection->AddService(this); - if (connection->GetServiceProvider()) { - // The application connecting to us may implement InspectorBackend, - // attempt to establish a connection to find out. If it doesn't then this - // pipe will close. - InspectorBackendPtr backend; - connection->ConnectToService(&backend); - backends_.AddInterfacePtr(backend.Pass()); - } - return true; - } - - // InterfaceFactory: - void Create(mojo::ApplicationConnection* connection, - mojo::InterfaceRequest request) override { - frontend_bindings_.AddBinding(this, request.Pass()); - } - - // InterfaceFactory: - void Create(mojo::ApplicationConnection* connection, - mojo::InterfaceRequest request) override { - server_binding_.Bind(request.PassMessagePipe()); - } - - // InspectorServer: - void Listen(int32_t port, const mojo::Closure& callback) override; - - // InspectorFrontend: - void SendMessage(const mojo::String& message) override; - - // net::HttpServer::Delegate: - void OnConnect(int connection_id) override; - void OnHttpRequest( - int connection_id, const net::HttpServerRequestInfo& info) override; - void OnWebSocketRequest( - int connection_id, const net::HttpServerRequestInfo& info) override; - void OnWebSocketMessage( - int connection_id, const std::string& data) override; - void OnClose(int connection_id) override; - - int connection_id_; - scoped_ptr web_server_; - - mojo::WeakInterfacePtrSet backends_; - mojo::WeakBindingSet frontend_bindings_; - mojo::Binding server_binding_; - - DISALLOW_COPY_AND_ASSIGN(Server); -}; - -Server::~Server() -{ -} - -void Server::OnConnect(int connection_id) { -} - -void Server::OnHttpRequest( - int connection_id, const net::HttpServerRequestInfo& info) { - web_server_->Send500(connection_id, "websockets protocol only"); -} - -void Server::OnWebSocketRequest( - int connection_id, const net::HttpServerRequestInfo& info) { - if (connection_id_ != kNotConnected) { - web_server_->Close(connection_id); - return; - } - web_server_->AcceptWebSocket(connection_id, info); - connection_id_ = connection_id; - backends_.ForAllPtrs([](InspectorBackend* backend) { backend->OnConnect(); }); -} - -void Server::OnWebSocketMessage( - int connection_id, const std::string& data) { - DCHECK_EQ(connection_id, connection_id_); - backends_.ForAllPtrs( - [data](InspectorBackend* backend) { backend->OnMessage(data); }); -} - -void Server::OnClose(int connection_id) { - if (connection_id != connection_id_) - return; - connection_id_ = kNotConnected; - backends_.ForAllPtrs( - [](InspectorBackend* backend) { backend->OnDisconnect(); }); -} - -void Server::Listen(int32_t port, const mojo::Closure& callback) { - backends_.CloseAll(); // Assume caller represents a new app. - - // TODO(eseidel): Early-out here if we're already bound to the right port. - web_server_.reset(); - scoped_ptr server_socket( - new net::TCPServerSocket(NULL, net::NetLog::Source())); - server_socket->ListenWithAddressAndPort("0.0.0.0", port, 1); - web_server_.reset(new net::HttpServer(server_socket.Pass(), this)); - callback.Run(); -} - -void Server::SendMessage(const mojo::String& message) { - if (connection_id_ == kNotConnected) - return; - web_server_->SendOverWebSocket(connection_id_, message); -} - -} // namespace inspector -} // namespace sky - -MojoResult MojoMain(MojoHandle shell_handle) { - mojo::ApplicationRunnerChromium runner(new sky::inspector::Server); - runner.set_message_loop_type(base::MessageLoop::TYPE_IO); - return runner.Run(shell_handle); -} diff --git a/viewer/BUILD.gn b/viewer/BUILD.gn index 5dc7aae619a..382e3bce8e3 100644 --- a/viewer/BUILD.gn +++ b/viewer/BUILD.gn @@ -27,8 +27,6 @@ mojo_native_application("viewer") { "platform/weburlloader_impl.h", "runtime_flags.cc", "runtime_flags.h", - "services/inspector_impl.cc", - "services/inspector_impl.h", "viewer.cc", ] diff --git a/viewer/services/inspector_impl.cc b/viewer/services/inspector_impl.cc deleted file mode 100644 index d85c3e37df1..00000000000 --- a/viewer/services/inspector_impl.cc +++ /dev/null @@ -1,44 +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/viewer/services/inspector_impl.h" - -#include "base/bind.h" -#include "sky/engine/public/web/WebDocument.h" -#include "sky/engine/public/web/WebElement.h" -#include "sky/engine/public/web/WebFrame.h" -#include "sky/engine/public/web/WebView.h" -#include "sky/services/inspector/inspector.mojom.h" -#include "sky/viewer/document_view.h" - -namespace sky { - -InspectorServiceImpl::InspectorServiceImpl(DocumentView* view) - : view_(view->GetWeakPtr()) { -} - -InspectorServiceImpl::~InspectorServiceImpl() { -} - -void Ignored() {} - -void InspectorServiceImpl::Inject() { - if (!view_) - return; - - mojo::ServiceProviderPtr inspector_service_provider; - view_->shell()->ConnectToApplication("mojo:sky_inspector_server", - GetProxy(&inspector_service_provider), - nullptr); - InspectorServerPtr inspector; - mojo::ConnectToService(inspector_service_provider.get(), &inspector); - inspector->Listen(9898, base::Bind(&Ignored)); - // Listen drops existing agents/backends, wait before registering new ones. - inspector.WaitForIncomingMethodCall(); - - view_->web_view()->injectModule("/sky/framework/inspector/inspector.sky"); - view_->StartDebuggerInspectorBackend(); -} - -} // namespace sky diff --git a/viewer/services/inspector_impl.h b/viewer/services/inspector_impl.h deleted file mode 100644 index 1db6cde60e0..00000000000 --- a/viewer/services/inspector_impl.h +++ /dev/null @@ -1,35 +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_VIEWER_SERVICES_INSPECTOR_IMPL_H_ -#define SKY_VIEWER_SERVICES_INSPECTOR_IMPL_H_ - -#include "base/basictypes.h" -#include "base/memory/weak_ptr.h" -#include "mojo/public/cpp/application/interface_factory_impl.h" -#include "sky/viewer/services/inspector.mojom.h" - -namespace sky { -class DocumentView; - -class InspectorServiceImpl : public mojo::InterfaceImpl { - public: - explicit InspectorServiceImpl(DocumentView*); - virtual ~InspectorServiceImpl(); - - private: - // Overridden from InspectorService: - void Inject() override; - - base::WeakPtr view_; - - DISALLOW_COPY_AND_ASSIGN(InspectorServiceImpl); -}; - -typedef mojo::InterfaceFactoryImplWithContext< - InspectorServiceImpl, DocumentView> InspectorServiceFactory; - -} // namespace sky - -#endif // SKY_VIEWER_SERVICES_INSPECTOR_IMPL_H_