Commit 0d1d7a9a authored by Gyuyoung Kim's avatar Gyuyoung Kim Committed by Commit Bot

Migrate Service::OnStart to new Mojo types

This CL applies the new Mojo types to the callback of OnStart
in Service interface.

  - Convert FooRequest to mojo::PendingReceiver.
  - Convert FooAssociatedPtr to AssocitedRemote.
  - Convert FooAssociatedRequest to PendingAssociatedReceiver.
  - Convert AssociatedBindingSet to AssociatedReceiverSet.

Bug: 955171
Change-Id: I7e3efc212a5272ef8c29977e150126c75ea0fc32
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1875009Reviewed-by: default avatarKenneth MacKay <kmackay@chromium.org>
Reviewed-by: default avatarSam McNally <sammc@chromium.org>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Commit-Queue: Gyuyoung Kim <gyuyoung@igalia.com>
Cr-Commit-Position: refs/heads/master@{#709128}
parent 0c7c7a29
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/token.h" #include "base/token.h"
#include "chromecast/external_mojo/external_service_support/external_connector.h" #include "chromecast/external_mojo/external_service_support/external_connector.h"
#include "mojo/public/cpp/bindings/interface_request.h" #include "mojo/public/cpp/bindings/interface_request.h"
#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
#include "services/service_manager/public/cpp/bind_source_info.h" #include "services/service_manager/public/cpp/bind_source_info.h"
#include "services/service_manager/public/cpp/connector.h" #include "services/service_manager/public/cpp/connector.h"
#include "services/service_manager/public/mojom/connector.mojom.h" #include "services/service_manager/public/mojom/connector.mojom.h"
...@@ -24,7 +25,8 @@ namespace { ...@@ -24,7 +25,8 @@ namespace {
void OnStartCallback( void OnStartCallback(
ExternalConnector* connector, ExternalConnector* connector,
service_manager::mojom::ConnectorRequest connector_request, service_manager::mojom::ConnectorRequest connector_request,
service_manager::mojom::ServiceControlAssociatedRequest control_request) { mojo::PendingAssociatedReceiver<service_manager::mojom::ServiceControl>
control_receiver) {
DCHECK(connector); DCHECK(connector);
if (connector_request.is_pending()) { if (connector_request.is_pending()) {
connector->SendChromiumConnectorRequest( connector->SendChromiumConnectorRequest(
......
...@@ -145,7 +145,7 @@ void ServiceBinding::OnStart(const Identity& identity, ...@@ -145,7 +145,7 @@ void ServiceBinding::OnStart(const Identity& identity,
if (!pending_connector_request_.is_pending()) if (!pending_connector_request_.is_pending())
connector_ = Connector::Create(&pending_connector_request_); connector_ = Connector::Create(&pending_connector_request_);
std::move(callback).Run(std::move(pending_connector_request_), std::move(callback).Run(std::move(pending_connector_request_),
mojo::MakeRequest(&service_control_)); service_control_.BindNewEndpointAndPassReceiver());
service_->OnStart(); service_->OnStart();
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/component_export.h" #include "base/component_export.h"
#include "base/macros.h" #include "base/macros.h"
#include "mojo/public/cpp/bindings/associated_remote.h"
#include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/binding_set.h" #include "mojo/public/cpp/bindings/binding_set.h"
#include "mojo/public/cpp/bindings/pending_receiver.h" #include "mojo/public/cpp/bindings/pending_receiver.h"
...@@ -187,7 +188,7 @@ class COMPONENT_EXPORT(SERVICE_MANAGER_CPP) ServiceBinding ...@@ -187,7 +188,7 @@ class COMPONENT_EXPORT(SERVICE_MANAGER_CPP) ServiceBinding
// This instance's control interface to the service manager. Note that this // This instance's control interface to the service manager. Note that this
// is unbound and therefore invalid until OnStart() is called. // is unbound and therefore invalid until OnStart() is called.
mojom::ServiceControlAssociatedPtr service_control_; mojo::AssociatedRemote<mojom::ServiceControl> service_control_;
// Tracks whether |RequestClose()| has been called at least once prior to // Tracks whether |RequestClose()| has been called at least once prior to
// receiving |OnStart()| on a bound ServiceBinding. This ensures that the // receiving |OnStart()| on a bound ServiceBinding. This ensures that the
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "mojo/public/cpp/bindings/associated_binding.h" #include "mojo/public/cpp/bindings/associated_binding.h"
#include "mojo/public/cpp/bindings/binding_set.h" #include "mojo/public/cpp/bindings/binding_set.h"
#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
#include "services/service_manager/public/cpp/service.h" #include "services/service_manager/public/cpp/service.h"
#include "services/service_manager/public/mojom/connector.mojom.h" #include "services/service_manager/public/mojom/connector.mojom.h"
#include "services/service_manager/public/mojom/service.mojom.h" #include "services/service_manager/public/mojom/service.mojom.h"
...@@ -140,20 +141,20 @@ mojom::ServiceRequest TestConnectorFactory::RegisterInstance( ...@@ -140,20 +141,20 @@ mojom::ServiceRequest TestConnectorFactory::RegisterInstance(
void TestConnectorFactory::OnStartResponseHandler( void TestConnectorFactory::OnStartResponseHandler(
const std::string& service_name, const std::string& service_name,
mojom::ConnectorRequest connector_request, mojo::PendingReceiver<mojom::Connector> connector_receiver,
mojom::ServiceControlAssociatedRequest control_request) { mojo::PendingAssociatedReceiver<mojom::ServiceControl> control_receiver) {
impl_->Clone(std::move(connector_request)); impl_->Clone(std::move(connector_receiver));
service_control_bindings_.AddBinding(this, std::move(control_request), service_control_receivers_.Add(this, std::move(control_receiver),
service_name); service_name);
} }
void TestConnectorFactory::RequestQuit() { void TestConnectorFactory::RequestQuit() {
if (ignore_quit_requests_) if (ignore_quit_requests_)
return; return;
service_proxies_.erase(service_control_bindings_.dispatch_context()); service_proxies_.erase(service_control_receivers_.current_context());
service_control_bindings_.RemoveBinding( service_control_receivers_.Remove(
service_control_bindings_.dispatch_binding()); service_control_receivers_.current_receiver());
} }
} // namespace service_manager } // namespace service_manager
...@@ -11,7 +11,8 @@ ...@@ -11,7 +11,8 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/token.h" #include "base/token.h"
#include "mojo/public/cpp/bindings/associated_binding_set.h" #include "mojo/public/cpp/bindings/associated_receiver_set.h"
#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
#include "services/service_manager/public/cpp/connector.h" #include "services/service_manager/public/cpp/connector.h"
#include "services/service_manager/public/mojom/connector.mojom.h" #include "services/service_manager/public/mojom/connector.mojom.h"
#include "services/service_manager/public/mojom/service_control.mojom.h" #include "services/service_manager/public/mojom/service_control.mojom.h"
...@@ -88,8 +89,8 @@ class TestConnectorFactory : public mojom::ServiceControl { ...@@ -88,8 +89,8 @@ class TestConnectorFactory : public mojom::ServiceControl {
private: private:
void OnStartResponseHandler( void OnStartResponseHandler(
const std::string& service_name, const std::string& service_name,
mojom::ConnectorRequest connector_request, mojo::PendingReceiver<mojom::Connector> connector_receiver,
mojom::ServiceControlAssociatedRequest control_request); mojo::PendingAssociatedReceiver<mojom::ServiceControl> control_receiver);
// mojom::ServiceControl: // mojom::ServiceControl:
void RequestQuit() override; void RequestQuit() override;
...@@ -106,8 +107,8 @@ class TestConnectorFactory : public mojom::ServiceControl { ...@@ -106,8 +107,8 @@ class TestConnectorFactory : public mojom::ServiceControl {
// ServiceControl bindings which receive and process RequestQuit requests from // ServiceControl bindings which receive and process RequestQuit requests from
// connected service instances. The associated service name is used as // connected service instances. The associated service name is used as
// context. // context.
mojo::AssociatedBindingSet<mojom::ServiceControl, std::string> mojo::AssociatedReceiverSet<mojom::ServiceControl, std::string>
service_control_bindings_; service_control_receivers_;
bool ignore_unknown_service_requests_ = false; bool ignore_unknown_service_requests_ = false;
bool ignore_quit_requests_ = false; bool ignore_quit_requests_ = false;
......
...@@ -48,8 +48,9 @@ interface Service { ...@@ -48,8 +48,9 @@ interface Service {
// control_request // control_request
// An optional associated ServiceControl request. // An optional associated ServiceControl request.
// //
OnStart(Identity identity) => (Connector&? connector_request, OnStart(Identity identity) =>
associated ServiceControl&? control_request); (pending_receiver<Connector> connector_receiver,
pending_associated_receiver<ServiceControl> control_receiver);
// Called when a request to bind an interface is received from another // Called when a request to bind an interface is received from another
// ("source") service. This is the result of that service calling // ("source") service. This is the result of that service calling
......
...@@ -356,16 +356,16 @@ void ServiceInstance::BindServiceManagerReceiver( ...@@ -356,16 +356,16 @@ void ServiceInstance::BindServiceManagerReceiver(
} }
void ServiceInstance::OnStartCompleted( void ServiceInstance::OnStartCompleted(
mojom::ConnectorRequest connector_request, mojo::PendingReceiver<mojom::Connector> connector_receiver,
mojom::ServiceControlAssociatedRequest control_request) { mojo::PendingAssociatedReceiver<mojom::ServiceControl> control_receiver) {
state_ = mojom::InstanceState::kStarted; state_ = mojom::InstanceState::kStarted;
if (connector_request.is_pending()) { if (connector_receiver.is_valid()) {
connector_receivers_.Add(this, std::move(connector_request)); connector_receivers_.Add(this, std::move(connector_receiver));
connector_receivers_.set_disconnect_handler(base::BindRepeating( connector_receivers_.set_disconnect_handler(base::BindRepeating(
&ServiceInstance::OnConnectorDisconnected, base::Unretained(this))); &ServiceInstance::OnConnectorDisconnected, base::Unretained(this)));
} }
if (control_request.is_pending()) if (control_receiver.is_valid())
control_receiver_.Bind(std::move(control_request)); control_receiver_.Bind(std::move(control_receiver));
service_manager_->NotifyServiceStarted(identity_, pid_); service_manager_->NotifyServiceStarted(identity_, pid_);
MaybeNotifyPidAvailable(); MaybeNotifyPidAvailable();
} }
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "base/process/process_handle.h" #include "base/process/process_handle.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "mojo/public/cpp/bindings/associated_receiver.h" #include "mojo/public/cpp/bindings/associated_receiver.h"
#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
#include "mojo/public/cpp/bindings/pending_receiver.h" #include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h" #include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/receiver_set.h" #include "mojo/public/cpp/bindings/receiver_set.h"
...@@ -108,8 +109,9 @@ class ServiceInstance : public mojom::Connector, ...@@ -108,8 +109,9 @@ class ServiceInstance : public mojom::Connector,
class InterfaceFilter; class InterfaceFilter;
friend class InterfaceFilter; friend class InterfaceFilter;
void OnStartCompleted(mojom::ConnectorRequest connector_request, void OnStartCompleted(
mojom::ServiceControlAssociatedRequest control_request); mojo::PendingReceiver<mojom::Connector> connector_receiver,
mojo::PendingAssociatedReceiver<mojom::ServiceControl> control_receiver);
void OnConnectRequestAcknowledged(); void OnConnectRequestAcknowledged();
void MarkUnreachable(); void MarkUnreachable();
void MaybeNotifyPidAvailable(); void MaybeNotifyPidAvailable();
......
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