Commit e6a9f01d authored by ben's avatar ben Committed by Commit bot

Add RegisterService, split out of Connect().

- Eliminates client lib's ConnectParams struct as this is no longer needed.
- Converts call sites.
- In Service Manager, RegisterService just calls Connect() with some empty values. The codepath is mostly the same. Note that when the ClientProcessConnection is passed now OnGotResolvedName returns early prior to completing the connection, as RegisterService is not a "connect" action, just a "start" one.

R=rockot@chromium.org,tsepez@chromium.org

Review-Url: https://codereview.chromium.org/2610173003
Cr-Commit-Position: refs/heads/master@{#442114}
parent c3c37251
...@@ -74,15 +74,8 @@ class BackgroundTestState { ...@@ -74,15 +74,8 @@ class BackgroundTestState {
// will spawn a new instance. // will spawn a new instance.
params->set_target(service_manager::Identity( params->set_target(service_manager::Identity(
kTestName, service_manager::mojom::kRootUserID)); kTestName, service_manager::mojom::kRootUserID));
params->set_client_process_info(std::move(service),
service_manager::mojom::ClientProcessConnectionPtr MakeRequest(&pid_receiver_));
client_process_connection =
service_manager::mojom::ClientProcessConnection::New();
client_process_connection->service =
service.PassInterface().PassHandle();
client_process_connection->pid_receiver_request =
mojo::MakeRequest(&pid_receiver_).PassMessagePipe();
params->set_client_process_connection(std::move(client_process_connection));
service_manager->Connect(std::move(params)); service_manager->Connect(std::move(params));
} }
......
...@@ -439,15 +439,14 @@ void BrowserContext::Initialize( ...@@ -439,15 +439,14 @@ void BrowserContext::Initialize(
service_manager::mojom::ServiceRequest service_request(&service); service_manager::mojom::ServiceRequest service_request(&service);
service_manager::mojom::PIDReceiverPtr pid_receiver; service_manager::mojom::PIDReceiverPtr pid_receiver;
service_manager::Connector::ConnectParams params( service_manager::Identity identity(mojom::kBrowserServiceName, new_id);
service_manager::Identity(mojom::kBrowserServiceName, new_id)); service_manager_connection->GetConnector()->Start(
params.set_client_process_connection(std::move(service), identity, std::move(service), mojo::MakeRequest(&pid_receiver));
mojo::MakeRequest(&pid_receiver));
pid_receiver->SetPID(base::GetCurrentProcId()); pid_receiver->SetPID(base::GetCurrentProcId());
BrowserContextServiceManagerConnectionHolder* connection_holder = BrowserContextServiceManagerConnectionHolder* connection_holder =
new BrowserContextServiceManagerConnectionHolder( new BrowserContextServiceManagerConnectionHolder(
service_manager_connection->GetConnector()->Connect(&params), service_manager_connection->GetConnector()->Connect(identity),
std::move(service_request)); std::move(service_request));
browser_context->SetUserData(kServiceManagerConnection, connection_holder); browser_context->SetUserData(kServiceManagerConnection, connection_holder);
......
...@@ -94,13 +94,12 @@ class ChildConnection::IOThreadContext ...@@ -94,13 +94,12 @@ class ChildConnection::IOThreadContext
service_manager::mojom::PIDReceiverRequest pid_receiver_request( service_manager::mojom::PIDReceiverRequest pid_receiver_request(
&pid_receiver_); &pid_receiver_);
service_manager::Connector::ConnectParams params(child_identity); if (connector) {
params.set_client_process_connection(std::move(service), connector->Start(child_identity,
std::move(pid_receiver_request)); std::move(service),
std::move(pid_receiver_request));
// In some unit testing scenarios a null connector is passed. connection_ = connector->Connect(child_identity);
if (connector) }
connection_ = connector->Connect(&params);
} }
void ShutDownOnIOThread() { void ShutDownOnIOThread() {
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "services/service_manager/public/cpp/identity.h" #include "services/service_manager/public/cpp/identity.h"
#include "services/service_manager/public/interfaces/connector.mojom.h" #include "services/service_manager/public/interfaces/connector.mojom.h"
#include "services/service_manager/public/interfaces/interface_provider.mojom.h" #include "services/service_manager/public/interfaces/interface_provider.mojom.h"
#include "services/service_manager/public/interfaces/service.mojom.h"
namespace service_manager { namespace service_manager {
...@@ -35,12 +36,20 @@ class ConnectParams { ...@@ -35,12 +36,20 @@ class ConnectParams {
return std::move(remote_interfaces_); return std::move(remote_interfaces_);
} }
void set_client_process_connection( void set_client_process_info(
mojom::ClientProcessConnectionPtr client_process_connection) { mojom::ServicePtr service,
client_process_connection_ = std::move(client_process_connection); mojom::PIDReceiverRequest pid_receiver_request) {
service_ = std::move(service);
pid_receiver_request_ = std::move(pid_receiver_request);
} }
mojom::ClientProcessConnectionPtr TakeClientProcessConnection() { bool HasClientProcessInfo() const {
return std::move(client_process_connection_); return service_.is_bound() && pid_receiver_request_.is_pending();
}
mojom::ServicePtr TakeService() {
return std::move(service_);
}
mojom::PIDReceiverRequest TakePIDReceiverRequest() {
return std::move(pid_receiver_request_);
} }
void set_connect_callback(const mojom::Connector::ConnectCallback& value) { void set_connect_callback(const mojom::Connector::ConnectCallback& value) {
...@@ -58,7 +67,8 @@ class ConnectParams { ...@@ -58,7 +67,8 @@ class ConnectParams {
Identity target_; Identity target_;
mojom::InterfaceProviderRequest remote_interfaces_; mojom::InterfaceProviderRequest remote_interfaces_;
mojom::ClientProcessConnectionPtr client_process_connection_; mojom::ServicePtr service_;
mojom::PIDReceiverRequest pid_receiver_request_;
mojom::Connector::ConnectCallback connect_callback_; mojom::Connector::ConnectCallback connect_callback_;
DISALLOW_COPY_AND_ASSIGN(ConnectParams); DISALLOW_COPY_AND_ASSIGN(ConnectParams);
......
...@@ -36,73 +36,39 @@ class Connector { ...@@ -36,73 +36,39 @@ class Connector {
public: public:
virtual ~Connector() {} virtual ~Connector() {}
class ConnectParams {
public:
explicit ConnectParams(const Identity& target);
explicit ConnectParams(const std::string& name);
~ConnectParams();
const Identity& target() { return target_; }
void set_target(const Identity& target) { target_ = target; }
void set_client_process_connection(
mojom::ServicePtr service,
mojom::PIDReceiverRequest pid_receiver_request) {
service_ = std::move(service);
pid_receiver_request_ = std::move(pid_receiver_request);
}
void TakeClientProcessConnection(
mojom::ServicePtr* service,
mojom::PIDReceiverRequest* pid_receiver_request) {
*service = std::move(service_);
*pid_receiver_request = std::move(pid_receiver_request_);
}
InterfaceProvider* remote_interfaces() { return remote_interfaces_; }
void set_remote_interfaces(InterfaceProvider* remote_interfaces) {
remote_interfaces_ = remote_interfaces;
}
private:
Identity target_;
mojom::ServicePtr service_;
mojom::PIDReceiverRequest pid_receiver_request_;
InterfaceProvider* remote_interfaces_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(ConnectParams);
};
// Creates a new Connector instance and fills in |*request| with a request // Creates a new Connector instance and fills in |*request| with a request
// for the other end the Connector's interface. // for the other end the Connector's interface.
static std::unique_ptr<Connector> Create(mojom::ConnectorRequest* request); static std::unique_ptr<Connector> Create(mojom::ConnectorRequest* request);
// Requests a new connection to an application. Returns a pointer to the // Creates an instance of a service for |identity| in a process started by the
// connection if the connection is permitted by this application's delegate, // client (or someone else). Must be called before Connect() may be called to
// or nullptr otherwise. Caller takes ownership. // |identity|.
// Once this method is called, this object is bound to the thread on which the virtual void Start(
// call took place. To pass to another thread, call Clone() and pass the const Identity& identity,
// result. mojom::ServicePtr service,
mojom::PIDReceiverRequest pid_receiver_request) = 0;
// Requests a new connection to a service. Returns a pointer to the
// connection if the connection is permitted by that service, nullptr
// otherwise. Once this method is called, this object is bound to the thread
// on which the call took place. To pass to another thread, call Clone() and
// pass the result.
virtual std::unique_ptr<Connection> Connect(const std::string& name) = 0; virtual std::unique_ptr<Connection> Connect(const std::string& name) = 0;
virtual std::unique_ptr<Connection> Connect(ConnectParams* params) = 0; virtual std::unique_ptr<Connection> Connect(const Identity& target) = 0;
// Connect to application identified by |request->name| and connect to the // Connect to |target| & request to bind |Interface|. Does not retain a
// service implementation of the interface identified by |Interface|. // connection to |target|.
template <typename Interface> template <typename Interface>
void ConnectToInterface(ConnectParams* params, void ConnectToInterface(const Identity& target,
mojo::InterfacePtr<Interface>* ptr) { mojo::InterfacePtr<Interface>* ptr) {
std::unique_ptr<Connection> connection = Connect(params); std::unique_ptr<Connection> connection = Connect(target);
if (connection) if (connection)
connection->GetInterface(ptr); connection->GetInterface(ptr);
} }
template <typename Interface> template <typename Interface>
void ConnectToInterface(const Identity& target,
mojo::InterfacePtr<Interface>* ptr) {
ConnectParams params(target);
return ConnectToInterface(&params, ptr);
}
template <typename Interface>
void ConnectToInterface(const std::string& name, void ConnectToInterface(const std::string& name,
mojo::InterfacePtr<Interface>* ptr) { mojo::InterfacePtr<Interface>* ptr) {
ConnectParams params(name); return ConnectToInterface(Identity(name, mojom::kInheritUserID), ptr);
return ConnectToInterface(&params, ptr);
} }
// Creates a new instance of this class which may be passed to another thread. // Creates a new instance of this class which may be passed to another thread.
......
...@@ -10,14 +10,6 @@ ...@@ -10,14 +10,6 @@
namespace service_manager { namespace service_manager {
Connector::ConnectParams::ConnectParams(const Identity& target)
: target_(target) {}
Connector::ConnectParams::ConnectParams(const std::string& name)
: target_(name, mojom::kInheritUserID) {}
Connector::ConnectParams::~ConnectParams() {}
ConnectorImpl::ConnectorImpl(mojom::ConnectorPtrInfo unbound_state) ConnectorImpl::ConnectorImpl(mojom::ConnectorPtrInfo unbound_state)
: unbound_state_(std::move(unbound_state)) { : unbound_state_(std::move(unbound_state)) {
thread_checker_.DetachFromThread(); thread_checker_.DetachFromThread();
...@@ -36,50 +28,39 @@ void ConnectorImpl::OnConnectionError() { ...@@ -36,50 +28,39 @@ void ConnectorImpl::OnConnectionError() {
connector_.reset(); connector_.reset();
} }
void ConnectorImpl::Start(
const Identity& identity,
mojom::ServicePtr service,
mojom::PIDReceiverRequest pid_receiver_request) {
if (!BindIfNecessary())
return;
DCHECK(service.is_bound() && pid_receiver_request.is_pending());
connector_->Start(identity,
service.PassInterface().PassHandle(),
std::move(pid_receiver_request));
}
std::unique_ptr<Connection> ConnectorImpl::Connect(const std::string& name) { std::unique_ptr<Connection> ConnectorImpl::Connect(const std::string& name) {
ConnectParams params(name); return Connect(Identity(name, mojom::kInheritUserID));
return Connect(&params);
} }
std::unique_ptr<Connection> ConnectorImpl::Connect(ConnectParams* params) { std::unique_ptr<Connection> ConnectorImpl::Connect(const Identity& target) {
if (!BindIfNecessary()) if (!BindIfNecessary())
return nullptr; return nullptr;
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(params);
mojom::InterfaceProviderPtr remote_interfaces; mojom::InterfaceProviderPtr remote_interfaces;
mojom::InterfaceProviderRequest remote_request(&remote_interfaces); mojom::InterfaceProviderRequest remote_request(&remote_interfaces);
std::unique_ptr<internal::ConnectionImpl> connection( std::unique_ptr<internal::ConnectionImpl> connection(
new internal::ConnectionImpl(params->target(), new internal::ConnectionImpl(target, Connection::State::PENDING));
Connection::State::PENDING)); std::unique_ptr<InterfaceProvider> remote_interface_provider(
if (params->remote_interfaces()) { new InterfaceProvider);
params->remote_interfaces()->Bind(std::move(remote_interfaces)); remote_interface_provider->Bind(std::move(remote_interfaces));
connection->set_remote_interfaces(params->remote_interfaces()); connection->SetRemoteInterfaces(std::move(remote_interface_provider));
} else {
std::unique_ptr<InterfaceProvider> remote_interface_provider(
new InterfaceProvider);
remote_interface_provider->Bind(std::move(remote_interfaces));
connection->SetRemoteInterfaces(std::move(remote_interface_provider));
}
mojom::ServicePtr service; connector_->Connect(target, std::move(remote_request),
mojom::PIDReceiverRequest pid_receiver_request;
params->TakeClientProcessConnection(&service, &pid_receiver_request);
mojom::ClientProcessConnectionPtr client_process_connection;
if (service.is_bound() && pid_receiver_request.is_pending()) {
client_process_connection = mojom::ClientProcessConnection::New();
client_process_connection->service =
service.PassInterface().PassHandle();
client_process_connection->pid_receiver_request =
pid_receiver_request.PassMessagePipe();
} else if (service.is_bound() || pid_receiver_request.is_pending()) {
NOTREACHED() << "If one of service or pid_receiver_request is valid, "
<< "both must be valid.";
return std::move(connection);
}
connector_->Connect(params->target(), std::move(remote_request),
std::move(client_process_connection),
connection->GetConnectCallback()); connection->GetConnectCallback());
return std::move(connection); return std::move(connection);
} }
......
...@@ -24,8 +24,11 @@ class ConnectorImpl : public Connector { ...@@ -24,8 +24,11 @@ class ConnectorImpl : public Connector {
void OnConnectionError(); void OnConnectionError();
// Connector: // Connector:
void Start(const Identity& identity,
mojom::ServicePtr service,
mojom::PIDReceiverRequest pid_receiver_request) override;
std::unique_ptr<Connection> Connect(const std::string& name) override; std::unique_ptr<Connection> Connect(const std::string& name) override;
std::unique_ptr<Connection> Connect(ConnectParams* params) override; std::unique_ptr<Connection> Connect(const Identity& target) override;
std::unique_ptr<Connector> Clone() override; std::unique_ptr<Connector> Clone() override;
void BindRequest(mojom::ConnectorRequest request) override; void BindRequest(mojom::ConnectorRequest request) override;
......
...@@ -67,26 +67,31 @@ interface PIDReceiver { ...@@ -67,26 +67,31 @@ interface PIDReceiver {
SetPID(uint32 pid); SetPID(uint32 pid);
}; };
// Typically, the service manager will start a process for a service the first
// time it receives a connection request for it. This struct allows a client to
// start the process itself and provide the service manager the pipes it needs
// to communicate with it. When an instance of this struct is supplied to
// Connect(), the client owns the lifetime of the child process, not the service
// manager. The service manager binds the |service| pipe, and when it closes
// destroys the associated instance but the process stays alive.
struct ClientProcessConnection {
// Provides the service manager the ability to bind a Service from the client
// process to the instance it creates.
handle<message_pipe> service;
// Allows the client process launcher to tell the service manager the PID of
// the process it created (the pid isn't supplied directly here as the process
// may not have been launched by the time Connect() is called.)
handle<message_pipe> pid_receiver_request;
};
// Encapsulates establishing connections with other Services. // Encapsulates establishing connections with other Services.
interface Connector { interface Connector {
// Typically, the service manager will start a process for a service the first
// time it receives a connection request for it. This struct allows a client
// to start the process itself and provide the service manager the pipes it
// needs to communicate with it. When this function is called, the client owns
// the lifetime of the child process it started, not the service manager. The
// service manager binds the |service| pipe, and when it closes destroys the
// associated instance but the process stays alive.
//
// Parameters:
//
// service
// A pipe to an implementation of Service that the service manager can use
// to communicate with the service.
//
// pid_receiver_request
// Allows the client process launcher to tell the service manager the PID of
// the process it created (the pid isn't supplied directly here as the
// process may not have been launched by the time Connect() is called.)
//
Start(Identity name,
handle<message_pipe> service,
PIDReceiver& pid_receiver_request);
// Requests a connection with another service. The service originating the // Requests a connection with another service. The service originating the
// request is referred to as the "source" and the one receiving the "target". // request is referred to as the "source" and the one receiving the "target".
// //
...@@ -110,10 +115,6 @@ interface Connector { ...@@ -110,10 +115,6 @@ interface Connector {
// are filtered by the security policy described by the source and target // are filtered by the security policy described by the source and target
// service manifests. // service manifests.
// //
// client_process_connection
// When non-null, supplies control pipes the service manager can use to
// bind a process created by the client, instead of creating one itself.
//
// Response parameters: // Response parameters:
// //
// result // result
...@@ -125,9 +126,7 @@ interface Connector { ...@@ -125,9 +126,7 @@ interface Connector {
// resolved by the service manager into a valid user id returned through // resolved by the service manager into a valid user id returned through
// this callback. // this callback.
// //
Connect(Identity target, Connect(Identity target, InterfaceProvider&? remote_interfaces) =>
InterfaceProvider&? remote_interfaces,
ClientProcessConnection? client_process_connection) =>
(ConnectResult result, string user_id); (ConnectResult result, string user_id);
// Clones this Connector so it can be passed to another thread. // Clones this Connector so it can be passed to another thread.
......
...@@ -165,16 +165,6 @@ class ServiceManager::Instance ...@@ -165,16 +165,6 @@ class ServiceManager::Instance
base::Unretained(this))); base::Unretained(this)));
} }
void StartWithClientProcessConnection(
mojom::ClientProcessConnectionPtr client_process_connection) {
mojom::ServicePtr service;
service.Bind(mojom::ServicePtrInfo(
std::move(client_process_connection->service), 0));
pid_receiver_binding_.Bind(
std::move(client_process_connection->pid_receiver_request));
StartWithService(std::move(service));
}
bool StartWithFilePath(const base::FilePath& path) { bool StartWithFilePath(const base::FilePath& path) {
DCHECK(!service_); DCHECK(!service_);
DCHECK(!path.empty()); DCHECK(!path.empty());
...@@ -189,6 +179,10 @@ class ServiceManager::Instance ...@@ -189,6 +179,10 @@ class ServiceManager::Instance
return true; return true;
} }
void BindPIDReceiver(mojom::PIDReceiverRequest request) {
pid_receiver_binding_.Bind(std::move(request));
}
mojom::RunningServiceInfoPtr CreateRunningServiceInfo() const { mojom::RunningServiceInfoPtr CreateRunningServiceInfo() const {
mojom::RunningServiceInfoPtr info(mojom::RunningServiceInfo::New()); mojom::RunningServiceInfoPtr info(mojom::RunningServiceInfo::New());
info->id = id_; info->id = id_;
...@@ -234,18 +228,42 @@ class ServiceManager::Instance ...@@ -234,18 +228,42 @@ class ServiceManager::Instance
}; };
// mojom::Connector implementation: // mojom::Connector implementation:
void Connect(const service_manager::Identity& in_target, void Start(
const Identity& target,
mojo::ScopedMessagePipeHandle service_handle,
mojom::PIDReceiverRequest pid_receiver_request) override {
mojom::ServicePtr service;
service.Bind(mojom::ServicePtrInfo(std::move(service_handle), 0));
ConnectImpl(
target,
mojom::InterfaceProviderRequest(),
std::move(service),
std::move(pid_receiver_request),
base::Bind(
&service_manager::ServiceManager::Instance::EmptyConnectCallback,
weak_factory_.GetWeakPtr()));
}
void Connect(const service_manager::Identity& target,
mojom::InterfaceProviderRequest remote_interfaces, mojom::InterfaceProviderRequest remote_interfaces,
mojom::ClientProcessConnectionPtr client_process_connection,
const ConnectCallback& callback) override { const ConnectCallback& callback) override {
ConnectImpl(target, std::move(remote_interfaces), mojom::ServicePtr(),
mojom::PIDReceiverRequest(), callback);
}
void ConnectImpl(const service_manager::Identity& in_target,
mojom::InterfaceProviderRequest remote_interfaces,
mojom::ServicePtr service,
mojom::PIDReceiverRequest pid_receiver_request,
const ConnectCallback& callback) {
Identity target = in_target; Identity target = in_target;
if (target.user_id() == mojom::kInheritUserID) if (target.user_id() == mojom::kInheritUserID)
target.set_user_id(identity_.user_id()); target.set_user_id(identity_.user_id());
if (!ValidateIdentity(target, callback)) if (!ValidateIdentity(target, callback))
return; return;
if (!ValidateClientProcessConnection(&client_process_connection, target, if (!ValidateClientProcessInfo(&service, &pid_receiver_request, target,
callback)) { callback)) {
return; return;
} }
if (!ValidateConnectionSpec(target, callback)) if (!ValidateConnectionSpec(target, callback))
...@@ -255,7 +273,8 @@ class ServiceManager::Instance ...@@ -255,7 +273,8 @@ class ServiceManager::Instance
params->set_source(identity_); params->set_source(identity_);
params->set_target(target); params->set_target(target);
params->set_remote_interfaces(std::move(remote_interfaces)); params->set_remote_interfaces(std::move(remote_interfaces));
params->set_client_process_connection(std::move(client_process_connection)); params->set_client_process_info(std::move(service),
std::move(pid_receiver_request));
params->set_connect_callback(callback); params->set_connect_callback(callback);
service_manager_->Connect( service_manager_->Connect(
std::move(params), nullptr, weak_factory_.GetWeakPtr()); std::move(params), nullptr, weak_factory_.GetWeakPtr());
...@@ -300,11 +319,12 @@ class ServiceManager::Instance ...@@ -300,11 +319,12 @@ class ServiceManager::Instance
return true; return true;
} }
bool ValidateClientProcessConnection( bool ValidateClientProcessInfo(
mojom::ClientProcessConnectionPtr* client_process_connection, mojom::ServicePtr* service,
mojom::PIDReceiverRequest* pid_receiver_request,
const Identity& target, const Identity& target,
const ConnectCallback& callback) { const ConnectCallback& callback) {
if (!client_process_connection->is_null()) { if (service->is_bound() || pid_receiver_request->is_pending()) {
if (!HasCapability(GetConnectionSpec(), kCapability_ClientProcess)) { if (!HasCapability(GetConnectionSpec(), kCapability_ClientProcess)) {
LOG(ERROR) << "Instance: " << identity_.name() << " attempting " LOG(ERROR) << "Instance: " << identity_.name() << " attempting "
<< "to register an instance for a process it created for " << "to register an instance for a process it created for "
...@@ -316,11 +336,9 @@ class ServiceManager::Instance ...@@ -316,11 +336,9 @@ class ServiceManager::Instance
return false; return false;
} }
if (!(*client_process_connection)->service.is_valid() || if (!service->is_bound() || !pid_receiver_request->is_pending()) {
!(*client_process_connection)->pid_receiver_request.is_valid()) {
LOG(ERROR) << "Must supply both service AND " LOG(ERROR) << "Must supply both service AND "
<< "pid_receiver_request when sending " << "pid_receiver_request when sending client process info";
<< "client_process_connection.";
callback.Run(mojom::ConnectResult::INVALID_ARGUMENT, callback.Run(mojom::ConnectResult::INVALID_ARGUMENT,
mojom::kInheritUserID); mojom::kInheritUserID);
return false; return false;
...@@ -342,7 +360,7 @@ class ServiceManager::Instance ...@@ -342,7 +360,7 @@ class ServiceManager::Instance
InterfaceProviderSpec connection_spec = GetConnectionSpec(); InterfaceProviderSpec connection_spec = GetConnectionSpec();
// TODO(beng): Need to do the following additional policy validation of // TODO(beng): Need to do the following additional policy validation of
// whether this instance is allowed to connect using: // whether this instance is allowed to connect using:
// - a non-null client_process_connection. // - non-null client process info.
if (target.user_id() != identity_.user_id() && if (target.user_id() != identity_.user_id() &&
target.user_id() != mojom::kRootUserID && target.user_id() != mojom::kRootUserID &&
!HasCapability(connection_spec, kCapability_UserID)) { !HasCapability(connection_spec, kCapability_UserID)) {
...@@ -432,6 +450,9 @@ class ServiceManager::Instance ...@@ -432,6 +450,9 @@ class ServiceManager::Instance
OnServiceLost(service_manager_->GetWeakPtr()); OnServiceLost(service_manager_->GetWeakPtr());
} }
void EmptyConnectCallback(mojom::ConnectResult result,
const std::string& user_id) {}
service_manager::ServiceManager* const service_manager_; service_manager::ServiceManager* const service_manager_;
// An id that identifies this instance. Distinct from pid, as a single process // An id that identifies this instance. Distinct from pid, as a single process
...@@ -872,8 +893,6 @@ void ServiceManager::OnGotResolvedName(std::unique_ptr<ConnectParams> params, ...@@ -872,8 +893,6 @@ void ServiceManager::OnGotResolvedName(std::unique_ptr<ConnectParams> params,
source_identity_for_creation = params->source(); source_identity_for_creation = params->source();
} }
mojom::ClientProcessConnectionPtr client_process_connection =
params->TakeClientProcessConnection();
Instance* instance = CreateInstance(source_identity_for_creation, Instance* instance = CreateInstance(source_identity_for_creation,
target, result->interface_provider_specs); target, result->interface_provider_specs);
...@@ -883,11 +902,13 @@ void ServiceManager::OnGotResolvedName(std::unique_ptr<ConnectParams> params, ...@@ -883,11 +902,13 @@ void ServiceManager::OnGotResolvedName(std::unique_ptr<ConnectParams> params,
// If a ServicePtr was provided, there's no more work to do: someone // If a ServicePtr was provided, there's no more work to do: someone
// is already holding a corresponding ServiceRequest. // is already holding a corresponding ServiceRequest.
instance->StartWithService(std::move(service)); instance->StartWithService(std::move(service));
} else if (!client_process_connection.is_null()) { } else if (params->HasClientProcessInfo()) {
// Likewise if a ClientProcessConnection was given via Connect(), it // This branch should be reachable only via a call to RegisterService(). We
// provides the Service proxy to use. // start the instance but return early before we connect to it. Clients will
instance->StartWithClientProcessConnection( // call Connect() with the target identity subsequently.
std::move(client_process_connection)); instance->BindPIDReceiver(params->TakePIDReceiverRequest());
instance->StartWithService(params->TakeService());
return;
} else { } else {
// Otherwise we create a new Service pipe. // Otherwise we create a new Service pipe.
mojom::ServiceRequest request(&service); mojom::ServiceRequest request(&service);
......
...@@ -172,9 +172,8 @@ class ConnectTestApp : public Service, ...@@ -172,9 +172,8 @@ class ConnectTestApp : public Service,
void ConnectToClassAppAsDifferentUser( void ConnectToClassAppAsDifferentUser(
const service_manager::Identity& target, const service_manager::Identity& target,
const ConnectToClassAppAsDifferentUserCallback& callback) override { const ConnectToClassAppAsDifferentUserCallback& callback) override {
Connector::ConnectParams params(target);
std::unique_ptr<Connection> connection = std::unique_ptr<Connection> connection =
context()->connector()->Connect(&params); context()->connector()->Connect(target);
{ {
base::RunLoop loop; base::RunLoop loop;
connection->AddConnectionCompletedClosure(base::Bind(&QuitLoop, &loop)); connection->AddConnectionCompletedClosure(base::Bind(&QuitLoop, &loop));
......
...@@ -116,9 +116,8 @@ class ProvidedService ...@@ -116,9 +116,8 @@ class ProvidedService
void ConnectToClassAppAsDifferentUser( void ConnectToClassAppAsDifferentUser(
const service_manager::Identity& target, const service_manager::Identity& target,
const ConnectToClassAppAsDifferentUserCallback& callback) override { const ConnectToClassAppAsDifferentUserCallback& callback) override {
Connector::ConnectParams params(target);
std::unique_ptr<Connection> connection = std::unique_ptr<Connection> connection =
context()->connector()->Connect(&params); context()->connector()->Connect(target);
{ {
base::RunLoop loop; base::RunLoop loop;
connection->AddConnectionCompletedClosure(loop.QuitClosure()); connection->AddConnectionCompletedClosure(loop.QuitClosure());
......
...@@ -79,8 +79,8 @@ class ConnectTest : public test::ServiceTest, ...@@ -79,8 +79,8 @@ class ConnectTest : public test::ServiceTest,
~ConnectTest() override {} ~ConnectTest() override {}
protected: protected:
std::unique_ptr<Connection> ConnectTo(Connector::ConnectParams* params) { std::unique_ptr<Connection> ConnectTo(const Identity& target) {
std::unique_ptr<Connection> connection = connector()->Connect(params); std::unique_ptr<Connection> connection = connector()->Connect(target);
base::RunLoop loop; base::RunLoop loop;
connection->AddConnectionCompletedClosure(base::Bind(&QuitLoop, &loop)); connection->AddConnectionCompletedClosure(base::Bind(&QuitLoop, &loop));
loop.Run(); loop.Run();
...@@ -175,10 +175,9 @@ TEST_F(ConnectTest, Connect) { ...@@ -175,10 +175,9 @@ TEST_F(ConnectTest, Connect) {
} }
TEST_F(ConnectTest, Instances) { TEST_F(ConnectTest, Instances) {
Connector::ConnectParams params_a( Identity identity_a(kTestAppName, mojom::kInheritUserID, "A");
Identity(kTestAppName, mojom::kInheritUserID, "A")); std::unique_ptr<Connection> connection_a1 = ConnectTo(identity_a);
std::unique_ptr<Connection> connection_a1 = ConnectTo(&params_a); std::unique_ptr<Connection> connection_a2 = ConnectTo(identity_a);
std::unique_ptr<Connection> connection_a2 = ConnectTo(&params_a);
std::string instance_a1, instance_a2; std::string instance_a1, instance_a2;
test::mojom::ConnectTestServicePtr service_a1; test::mojom::ConnectTestServicePtr service_a1;
{ {
...@@ -196,9 +195,8 @@ TEST_F(ConnectTest, Instances) { ...@@ -196,9 +195,8 @@ TEST_F(ConnectTest, Instances) {
} }
EXPECT_EQ(instance_a1, instance_a2); EXPECT_EQ(instance_a1, instance_a2);
Connector::ConnectParams params_b( Identity identity_b(kTestAppName, mojom::kInheritUserID, "B");
Identity(kTestAppName, mojom::kInheritUserID, "B")); std::unique_ptr<Connection> connection_b = ConnectTo(identity_b);
std::unique_ptr<Connection> connection_b = ConnectTo(&params_b);
std::string instance_b; std::string instance_b;
test::mojom::ConnectTestServicePtr service_b; test::mojom::ConnectTestServicePtr service_b;
{ {
...@@ -368,9 +366,8 @@ TEST_F(ConnectTest, AllUsersSingleton) { ...@@ -368,9 +366,8 @@ TEST_F(ConnectTest, AllUsersSingleton) {
// own // own
// synthetic user id for all-user singleton instances). // synthetic user id for all-user singleton instances).
const std::string singleton_userid = base::GenerateGUID(); const std::string singleton_userid = base::GenerateGUID();
Connector::ConnectParams params( Identity singleton_id(kTestSingletonAppName, singleton_userid);
Identity(kTestSingletonAppName, singleton_userid)); std::unique_ptr<Connection> connection = connector()->Connect(singleton_id);
std::unique_ptr<Connection> connection = connector()->Connect(&params);
{ {
base::RunLoop loop; base::RunLoop loop;
connection->AddConnectionCompletedClosure(base::Bind(&QuitLoop, &loop)); connection->AddConnectionCompletedClosure(base::Bind(&QuitLoop, &loop));
......
...@@ -184,11 +184,9 @@ class ServiceManagerTest : public test::ServiceTest, ...@@ -184,11 +184,9 @@ class ServiceManagerTest : public test::ServiceTest,
service_manager::Identity target("service_manager_unittest_target", service_manager::Identity target("service_manager_unittest_target",
service_manager::mojom::kInheritUserID); service_manager::mojom::kInheritUserID);
service_manager::Connector::ConnectParams params(target); connector()->Start(target, std::move(client), MakeRequest(&receiver));
params.set_client_process_connection(std::move(client),
MakeRequest(&receiver));
std::unique_ptr<service_manager::Connection> connection = std::unique_ptr<service_manager::Connection> connection =
connector()->Connect(&params); connector()->Connect(target);
connection->AddConnectionCompletedClosure( connection->AddConnectionCompletedClosure(
base::Bind(&ServiceManagerTest::OnConnectionCompleted, base::Bind(&ServiceManagerTest::OnConnectionCompleted,
base::Unretained(this))); base::Unretained(this)));
......
...@@ -36,7 +36,7 @@ void QuitLoop(base::RunLoop* loop) { ...@@ -36,7 +36,7 @@ void QuitLoop(base::RunLoop* loop) {
std::unique_ptr<Connection> LaunchAndConnectToProcess( std::unique_ptr<Connection> LaunchAndConnectToProcess(
const std::string& target_exe_name, const std::string& target_exe_name,
const Identity target, const Identity& target,
service_manager::Connector* connector, service_manager::Connector* connector,
base::Process* process) { base::Process* process) {
base::FilePath target_path; base::FilePath target_path;
...@@ -74,11 +74,9 @@ std::unique_ptr<Connection> LaunchAndConnectToProcess( ...@@ -74,11 +74,9 @@ std::unique_ptr<Connection> LaunchAndConnectToProcess(
std::move(pipe), 0u)); std::move(pipe), 0u));
service_manager::mojom::PIDReceiverPtr receiver; service_manager::mojom::PIDReceiverPtr receiver;
service_manager::Connector::ConnectParams params(target); connector->Start(target, std::move(client), MakeRequest(&receiver));
params.set_client_process_connection(std::move(client),
MakeRequest(&receiver));
std::unique_ptr<service_manager::Connection> connection = std::unique_ptr<service_manager::Connection> connection =
connector->Connect(&params); connector->Connect(target);
{ {
base::RunLoop loop; base::RunLoop loop;
connection->AddConnectionCompletedClosure(base::Bind(&QuitLoop, &loop)); connection->AddConnectionCompletedClosure(base::Bind(&QuitLoop, &loop));
......
...@@ -25,7 +25,7 @@ namespace test { ...@@ -25,7 +25,7 @@ namespace test {
// manager. // manager.
std::unique_ptr<Connection> LaunchAndConnectToProcess( std::unique_ptr<Connection> LaunchAndConnectToProcess(
const std::string& target_exe_name, const std::string& target_exe_name,
const Identity target, const Identity& target,
service_manager::Connector* connector, service_manager::Connector* connector,
base::Process* process); base::Process* process);
......
...@@ -39,7 +39,7 @@ class ServiceConnector { ...@@ -39,7 +39,7 @@ class ServiceConnector {
service_manager::mojom::blink::InterfaceProviderPtr remoteInterfaces; service_manager::mojom::blink::InterfaceProviderPtr remoteInterfaces;
m_connector->Connect(std::move(remoteIdentity), m_connector->Connect(std::move(remoteIdentity),
MakeRequest(&remoteInterfaces), nullptr, MakeRequest(&remoteInterfaces),
base::Bind(&ServiceConnector::onConnectionCompleted)); base::Bind(&ServiceConnector::onConnectionCompleted));
remoteInterfaces->GetInterface(Interface::Name_, request.PassMessagePipe()); remoteInterfaces->GetInterface(Interface::Name_, request.PassMessagePipe());
......
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