Commit 799df523 authored by Khushal's avatar Khushal Committed by Commit Bot

services: Allow cloning disconnected Connectors.

If the unbound state is invalid, cloning the connector can fail and
returns null. Instead create a new Connector with invalid state to
avoid having callers guard against this case.

R=rockot@chromium.org

Bug: 792340
Change-Id: I39ba3253048f4599586d0fb94d7f1d91404f1ace
Reviewed-on: https://chromium-review.googlesource.com/812498
Commit-Queue: Khushal <khushalsagar@chromium.org>
Reviewed-by: default avatarKen Rockot <rockot@chromium.org>
Cr-Commit-Position: refs/heads/master@{#522371}
parent 8def47f8
...@@ -87,12 +87,11 @@ void Connector::BindInterface(const Identity& target, ...@@ -87,12 +87,11 @@ void Connector::BindInterface(const Identity& target,
} }
std::unique_ptr<Connector> Connector::Clone() { std::unique_ptr<Connector> Connector::Clone() {
if (!BindConnectorIfNecessary()) mojom::ConnectorPtrInfo connector;
return nullptr; auto request = mojo::MakeRequest(&connector);
if (BindConnectorIfNecessary())
mojom::ConnectorPtr connector; connector_->Clone(std::move(request));
connector_->Clone(mojo::MakeRequest(&connector)); return std::make_unique<Connector>(std::move(connector));
return std::make_unique<Connector>(connector.PassInterface());
} }
bool Connector::IsBound() const { bool Connector::IsBound() const {
......
...@@ -582,4 +582,9 @@ TEST_F(ServiceManagerTest, ClientProcessCapabilityEnforced) { ...@@ -582,4 +582,9 @@ TEST_F(ServiceManagerTest, ClientProcessCapabilityEnforced) {
EXPECT_EQ(1u, instances().size()); EXPECT_EQ(1u, instances().size());
} }
TEST_F(ServiceManagerTest, ClonesDisconnectedConnectors) {
Connector connector((mojom::ConnectorPtrInfo()));
EXPECT_TRUE(connector.Clone());
}
} // namespace service_manager } // namespace service_manager
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