Skip to content

Commit e6e4bce

Browse files
CaslynCommit Bot
authored andcommitted
[component_manager] *_routed_async functions take PartialAbsoluteMoniker
This CL refactors the calls in these functions: - `on_scoped_framework_capability_routed_async` in binder.rs - `on_collection_capability_routed_async` in collection.rs .. to take a `PartialAbsoluteMoniker` directly, instead of an `AbsoluteMoniker` that eventually gets converted with `.to_partial()`. Additionally the unused AbsoluteMoniker parameter is removed from `on_capability_routed_async` in hub.rs The reason for this CL is to reduce the scope of `AbsoluteMoniker`, when using `PartialAbsoluteMoniker` can be used directly instead. Bug: 87407 Change-Id: I0f2eb836205aa9b20035fe35e868eaad21461722 Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/637493 Reviewed-by: Yegor Pomortsev <[email protected]> Commit-Queue: Caslyn Tonelli <[email protected]>
1 parent 9ab9980 commit e6e4bce

File tree

3 files changed

+10
-17
lines changed

3 files changed

+10
-17
lines changed

src/sys/component_manager/src/binder.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use {
1919
cm_util::channel,
2020
fuchsia_zircon as zx,
2121
lazy_static::lazy_static,
22-
moniker::{AbsoluteMoniker, AbsoluteMonikerBase, ExtendedMoniker},
22+
moniker::{AbsoluteMonikerBase, ExtendedMoniker, PartialAbsoluteMoniker},
2323
routing::capability_source::{ComponentCapability, InternalCapability},
2424
std::{
2525
path::PathBuf,
@@ -115,16 +115,15 @@ impl BinderCapabilityHost {
115115
async fn on_scoped_framework_capability_routed_async<'a>(
116116
self: Arc<Self>,
117117
source: WeakComponentInstance,
118-
target_moniker: AbsoluteMoniker,
118+
target_moniker: PartialAbsoluteMoniker,
119119
capability: &'a InternalCapability,
120120
capability_provider: Option<Box<dyn CapabilityProvider>>,
121121
) -> Result<Option<Box<dyn CapabilityProvider>>, ModelError> {
122122
// If some other capability has already been installed, then there's nothing to
123123
// do here.
124124
if capability_provider.is_none() && capability.matches_protocol(&BINDER_SERVICE) {
125125
let model = self.model.upgrade().ok_or(ModelError::ModelNotAvailable)?;
126-
let target =
127-
WeakComponentInstance::new(&model.look_up(&target_moniker.to_partial()).await?);
126+
let target = WeakComponentInstance::new(&model.look_up(&target_moniker).await?);
128127
Ok(Some(Box::new(BinderCapabilityProvider::new(source, target))
129128
as Box<dyn CapabilityProvider>))
130129
} else {
@@ -151,7 +150,7 @@ impl Hook for BinderCapabilityHost {
151150
*capability_provider = self
152151
.on_scoped_framework_capability_routed_async(
153152
component.clone(),
154-
target_moniker.clone(),
153+
target_moniker.to_partial().clone(),
155154
&capability,
156155
capability_provider.take(),
157156
)

src/sys/component_manager/src/collection.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use {
1515
},
1616
async_trait::async_trait,
1717
cm_rust::CapabilityTypeName,
18-
moniker::{AbsoluteMoniker, AbsoluteMonikerBase, ExtendedMoniker},
18+
moniker::{AbsoluteMonikerBase, ExtendedMoniker, PartialAbsoluteMoniker},
1919
routing::capability_source::{AggregateCapability, AggregateCapabilityProvider},
2020
std::sync::{Arc, Weak},
2121
};
@@ -42,16 +42,15 @@ impl CollectionCapabilityHost {
4242
async fn on_collection_capability_routed_async(
4343
self: Arc<Self>,
4444
source: WeakComponentInstance,
45-
target_moniker: AbsoluteMoniker,
45+
target_moniker: PartialAbsoluteMoniker,
4646
aggregate_capability_provider: Box<dyn AggregateCapabilityProvider<ComponentInstance>>,
4747
capability: &AggregateCapability,
4848
capability_provider: Option<Box<dyn CapabilityProvider>>,
4949
) -> Result<Option<Box<dyn CapabilityProvider>>, ModelError> {
5050
// If some other capability has already been installed, then there's nothing to do here.
5151
if capability_provider.is_none() && capability.type_name() == CapabilityTypeName::Service {
5252
let model = self.model.upgrade().ok_or(ModelError::ModelNotAvailable)?;
53-
let target =
54-
WeakComponentInstance::new(&model.look_up(&target_moniker.to_partial()).await?);
53+
let target = WeakComponentInstance::new(&model.look_up(&target_moniker).await?);
5554

5655
Ok(Some(Box::new(
5756
CollectionServiceDirectoryProvider::create(
@@ -91,7 +90,7 @@ impl Hook for CollectionCapabilityHost {
9190
*capability_provider = self
9291
.on_collection_capability_routed_async(
9392
component.clone(),
94-
target_moniker.clone(),
93+
target_moniker.to_partial().clone(),
9594
aggregate_capability_provider.clone_boxed(),
9695
&capability,
9796
capability_provider.take(),

src/sys/component_manager/src/model/hub.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,6 @@ impl Hub {
623623
/// provide a hub directory.
624624
async fn on_capability_routed_async(
625625
self: Arc<Self>,
626-
_target_moniker: &AbsoluteMoniker,
627626
source: CapabilitySource,
628627
capability_provider: Arc<Mutex<Option<Box<dyn CapabilityProvider>>>>,
629628
) -> Result<(), ModelError> {
@@ -665,12 +664,8 @@ impl Hook for Hub {
665664
.unwrap_instance_moniker_or(ModelError::UnexpectedComponentManagerMoniker)?;
666665
match &event.result {
667666
Ok(EventPayload::CapabilityRouted { source, capability_provider }) => {
668-
self.on_capability_routed_async(
669-
target_moniker,
670-
source.clone(),
671-
capability_provider.clone(),
672-
)
673-
.await?;
667+
self.on_capability_routed_async(source.clone(), capability_provider.clone())
668+
.await?;
674669
}
675670
Ok(EventPayload::Purged) => {
676671
self.on_purged_async(target_moniker).await?;

0 commit comments

Comments
 (0)