#include "services/service_manager/service_instance.h"
#include <set>
#include <utility>
#include "base/containers/contains.h"
#include "base/functional/bind.h"
#include "base/logging.h"
#include "base/ranges/algorithm.h"
#include "base/strings/strcat.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "mojo/public/cpp/bindings/callback_helpers.h"
#include "services/service_manager/public/cpp/constants.h"
#include "services/service_manager/public/mojom/constants.mojom.h"
#include "services/service_manager/service_manager.h"
#include "services/service_manager/service_process_host.h"
#include "ui/base/l10n/l10n_util.h"
#if !BUILDFLAG(IS_IOS)
#include "sandbox/policy/mojom/sandbox.mojom.h"
#include "services/service_manager/service_process_launcher.h"
#endif
namespace service_manager {
namespace {
std::set<std::string> GetRequiredCapabilities(
const Manifest::RequiredCapabilityMap& source_requirements,
const std::string& target_service) { … }
void ReportBlockedInterface(const Manifest::ServiceName& source_service_name,
const Manifest::ServiceName& target_service_name,
const std::string& target_interface_name) { … }
void ReportBlockedStartService(const std::string& source_service_name,
const std::string& target_service_name) { … }
bool AllowsInterface(const Manifest::RequiredCapabilityMap& source_requirements,
const std::string& target_name,
const Manifest::ExposedCapabilityMap& target_capabilities,
const std::string& interface_name) { … }
}
ServiceInstance::ServiceInstance(
service_manager::ServiceManager* service_manager,
const Identity& identity,
const Manifest& manifest)
: … { … }
ServiceInstance::~ServiceInstance() { … }
void ServiceInstance::SetPID(base::ProcessId pid) { … }
void ServiceInstance::StartWithRemote(
mojo::PendingRemote<mojom::Service> remote) { … }
#if !BUILDFLAG(IS_IOS)
bool ServiceInstance::StartWithProcessHost(
std::unique_ptr<ServiceProcessHost> host,
sandbox::mojom::Sandbox sandbox_type) { … }
#endif
void ServiceInstance::BindProcessMetadataReceiver(
mojo::PendingReceiver<mojom::ProcessMetadata> receiver) { … }
bool ServiceInstance::MaybeAcceptConnectionRequest(
const ServiceInstance& source_instance,
const std::string& interface_name,
mojo::ScopedMessagePipeHandle receiving_pipe,
mojom::BindInterfacePriority priority) { … }
bool ServiceInstance::CreatePackagedServiceInstance(
const Identity& packaged_instance_identity,
mojo::PendingReceiver<mojom::Service> receiver,
mojo::PendingRemote<mojom::ProcessMetadata> metadata) { … }
void ServiceInstance::Stop() { … }
mojom::RunningServiceInfoPtr ServiceInstance::CreateRunningServiceInfo() const { … }
void ServiceInstance::BindServiceManagerReceiver(
mojo::PendingReceiver<mojom::ServiceManager> receiver) { … }
void ServiceInstance::OnStartCompleted(
mojo::PendingReceiver<mojom::Connector> connector_receiver,
mojo::PendingAssociatedReceiver<mojom::ServiceControl> control_receiver) { … }
void ServiceInstance::OnConnectRequestAcknowledged() { … }
void ServiceInstance::MarkUnreachable() { … }
void ServiceInstance::MaybeNotifyPidAvailable() { … }
void ServiceInstance::OnServiceDisconnected() { … }
void ServiceInstance::OnConnectorDisconnected() { … }
void ServiceInstance::HandleServiceOrConnectorDisconnection() { … }
bool ServiceInstance::CanConnectToOtherInstance(
const ServiceFilter& target_filter,
const std::optional<std::string>& target_interface_name) { … }
void ServiceInstance::BindInterface(
const ServiceFilter& target_filter,
const std::string& interface_name,
mojo::ScopedMessagePipeHandle receiving_pipe,
mojom::BindInterfacePriority priority,
BindInterfaceCallback callback) { … }
void ServiceInstance::QueryService(const std::string& service_name,
QueryServiceCallback callback) { … }
void ServiceInstance::WarmService(const ServiceFilter& target_filter,
WarmServiceCallback callback) { … }
void ServiceInstance::RegisterServiceInstance(
const Identity& identity,
mojo::ScopedMessagePipeHandle service_remote_handle,
mojo::PendingReceiver<mojom::ProcessMetadata> metadata_receiver,
RegisterServiceInstanceCallback callback) { … }
void ServiceInstance::Clone(mojo::PendingReceiver<mojom::Connector> receiver) { … }
void ServiceInstance::RequestQuit() { … }
void ServiceInstance::AddListener(
mojo::PendingRemote<mojom::ServiceManagerListener> listener) { … }
}