// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module service_manager.mojom;
import "services/service_manager/public/mojom/connector.mojom";
enum InstanceState {
// The instance has been created by the Service Manager but has not yet
// started running. A ServiceManagerListener which observes an instance in
// this state during |OnInit()| will not observe an |OnServiceCreated()|
// message for that instance. Instead the next message received regarding that
// instance will be either |OnServiceStarted()| or |OnServiceFailedToStart()|.
kCreated,
// The instance is running and accepting interface requests from the Service
// Manager. A ServiceManagerListener which observes an instance in this state
// during |OnInit()| will not observe an |OnServiceCreated()|,
// |OnServiceStarted()|, or |OnServiceFailedToStart()| message for that
// instance. If the instance did not have a valid |pid| during |OnInit()|, the
// listener may receive on |OnServicePIDReceived()| message at some point in
// the future. The only other event the listener may observe for that instance
// is |OnServiceStopped()|.
kStarted,
// The instance is still running and may be connected to other service
// instances in the system, but it is no longer reachable through the Service
// Manager. A ServiceManagerListener which observes an instance in this state
// during |OnInit()| can expect to eventually observe an |OnServiceStopped()|
// event for that instance. No other events will be observed regarding that
// instance.
kUnreachable,
};
struct RunningServiceInfo {
Identity identity;
uint32 pid;
InstanceState state;
};
// Implemented by a client that wishes to be informed when the list of running
// services changes.
interface ServiceManagerListener {
// Called once when the listener is added via
// ServiceManager::AddInstanceListener() to provide the initial list of
// services that the listener observes changes against.
OnInit(array<RunningServiceInfo> running_services);
// Called when the Service Manager has started tracking a Service. This
// happens when the Service Manager first handles a request to launch the
// Service, before a process is created for it.
//
// TODO(crbug.com/41428001): This should just take an Identity instead
// of a RunningServiceInfo. Newly created service instances never have a PID
// and are always in the |kCreated| state.
OnServiceCreated(RunningServiceInfo service);
// Called when a pid is available for the service. This could be because the
// Service Manager created a process for it, or because an existing one was
// assigned to it.
//
// NOTE: Implementations should ignore |pid_deprecated|. This message will
// eventually be followed by OnServicePIDReceived for the corresponding
// |identity|, as the instance's PID is not guaranteed to be known when this
// method is invoked.
OnServiceStarted(Identity identity, uint32 pid_deprecated);
// Called when a PID is available for the service. Guaranteed to be called
// some time after OnServiceStarted, unless OnServiceStopped is called first.
OnServicePIDReceived(Identity identity, uint32 pid);
// Called when a service failed to start. (typically because it was shutdown
// before the manager heard back from the service).
OnServiceFailedToStart(Identity identity);
// Called when the Service Manager has stopped tracking a service. (i.e. when
// it has ended/quit).
OnServiceStopped(Identity identity);
};
interface ServiceManager {
// The listener is removed when the |listener| pipe is closed.
AddListener(pending_remote<ServiceManagerListener> listener);
};