| Index: services/shell/public/cpp/lib/shell_connection.cc
|
| diff --git a/services/shell/public/cpp/lib/shell_connection.cc b/services/shell/public/cpp/lib/shell_connection.cc
|
| index b4df114649e75c7fdaa447f9be970c198ad8f131..173f6a3e8901ff474f3e11d3eefb6b3f135362e2 100644
|
| --- a/services/shell/public/cpp/lib/shell_connection.cc
|
| +++ b/services/shell/public/cpp/lib/shell_connection.cc
|
| @@ -10,6 +10,7 @@
|
| #include "mojo/public/cpp/bindings/interface_ptr.h"
|
| #include "mojo/public/cpp/bindings/interface_request.h"
|
| #include "services/shell/public/cpp/capabilities.h"
|
| +#include "services/shell/public/cpp/connector.h"
|
| #include "services/shell/public/cpp/lib/connection_impl.h"
|
| #include "services/shell/public/cpp/lib/connector_impl.h"
|
| #include "services/shell/public/cpp/service.h"
|
| @@ -19,23 +20,28 @@
|
| ////////////////////////////////////////////////////////////////////////////////
|
| // ShellConnection, public:
|
|
|
| -ShellConnection::ShellConnection(shell::Service* service,
|
| - mojom::ServiceRequest request,
|
| - std::unique_ptr<Connector> connector,
|
| - mojom::ConnectorRequest connector_request)
|
| - : pending_connector_request_(std::move(connector_request)),
|
| - service_(service),
|
| - binding_(this, std::move(request)),
|
| - connector_(std::move(connector)) {
|
| - DCHECK(binding_.is_bound());
|
| - if (!connector_) {
|
| - connector_ = Connector::Create(&pending_connector_request_);
|
| - } else {
|
| - DCHECK(pending_connector_request_.is_pending());
|
| - }
|
| +ShellConnection::ShellConnection(shell::Service* client,
|
| + mojom::ServiceRequest request)
|
| + : client_(client), binding_(this) {
|
| + mojom::ConnectorPtr connector;
|
| + pending_connector_request_ = GetProxy(&connector);
|
| + connector_.reset(new ConnectorImpl(std::move(connector)));
|
| +
|
| + DCHECK(request.is_pending());
|
| + binding_.Bind(std::move(request));
|
| }
|
|
|
| ShellConnection::~ShellConnection() {}
|
| +
|
| +void ShellConnection::set_initialize_handler(const base::Closure& callback) {
|
| + initialize_handler_ = callback;
|
| +}
|
| +
|
| +void ShellConnection::SetAppTestConnectorForTesting(
|
| + mojom::ConnectorPtr connector) {
|
| + pending_connector_request_ = nullptr;
|
| + connector_.reset(new ConnectorImpl(std::move(connector)));
|
| +}
|
|
|
| void ShellConnection::SetConnectionLostClosure(const base::Closure& closure) {
|
| connection_lost_closure_ = closure;
|
| @@ -60,7 +66,7 @@
|
| binding_.set_connection_error_handler(
|
| base::Bind(&ShellConnection::OnConnectionError, base::Unretained(this)));
|
|
|
| - service_->OnStart(connector_.get(), identity_, id);
|
| + client_->OnStart(connector_.get(), identity_, id);
|
| }
|
|
|
| void ShellConnection::OnConnect(
|
| @@ -75,16 +81,29 @@
|
| allowed_capabilities.To<CapabilityRequest>(),
|
| Connection::State::CONNECTED));
|
|
|
| - std::unique_ptr<InterfaceRegistry> exposed_interfaces(
|
| - new InterfaceRegistry(registry.get()));
|
| - exposed_interfaces->Bind(std::move(local_interfaces));
|
| - registry->SetExposedInterfaces(std::move(exposed_interfaces));
|
| + InterfaceRegistry* exposed_interfaces =
|
| + client_->GetInterfaceRegistryForConnection();
|
| + if (exposed_interfaces) {
|
| + exposed_interfaces->Bind(std::move(local_interfaces));
|
| + registry->set_exposed_interfaces(exposed_interfaces);
|
| + } else {
|
| + std::unique_ptr<InterfaceRegistry> interfaces(
|
| + new InterfaceRegistry(registry.get()));
|
| + interfaces->Bind(std::move(local_interfaces));
|
| + registry->SetExposedInterfaces(std::move(interfaces));
|
| + }
|
| + shell::InterfaceProvider* remote_interface_provider =
|
| + client_->GetInterfaceProviderForConnection();
|
| + if (remote_interface_provider) {
|
| + remote_interface_provider->Bind(std::move(remote_interfaces));
|
| + registry->set_remote_interfaces(remote_interface_provider);
|
| + } else {
|
| + std::unique_ptr<InterfaceProvider> interfaces(new InterfaceProvider);
|
| + interfaces->Bind(std::move(remote_interfaces));
|
| + registry->SetRemoteInterfaces(std::move(interfaces));
|
| + }
|
|
|
| - std::unique_ptr<InterfaceProvider> interfaces(new InterfaceProvider);
|
| - interfaces->Bind(std::move(remote_interfaces));
|
| - registry->SetRemoteInterfaces(std::move(interfaces));
|
| -
|
| - if (!service_->OnConnect(registry.get()))
|
| + if (!client_->OnConnect(registry.get()))
|
| return;
|
|
|
| // TODO(beng): it appears we never prune this list. We should, when the
|
| @@ -99,7 +118,7 @@
|
| // Note that the Service doesn't technically have to quit now, it may live
|
| // on to service existing connections. All existing Connectors however are
|
| // invalid.
|
| - should_run_connection_lost_closure_ = service_->OnStop();
|
| + should_run_connection_lost_closure_ = client_->OnStop();
|
| if (should_run_connection_lost_closure_ &&
|
| !connection_lost_closure_.is_null())
|
| connection_lost_closure_.Run();
|
|
|