Commit b1e3f7d7 authored by Sergey Ulanov's avatar Sergey Ulanov Committed by Commit Bot

[fuchsia] Use components incoming services to for MetricsRecorder

Previously cast runner was using agent_url to connect MetricsRecorder.
That doesn't work correctly: the agent that created the component may
not provide MetricsRecorder. Updated it to use components
incoming_directory. This ensures that MetricsRecorder request is routed
properly to the agent that implements the service.

Bug: b/157669687
Change-Id: I891ebd852278fd98b543076f82562dbcd416005e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2360417
Commit-Queue: Sergey Ulanov <sergeyu@chromium.org>
Auto-Submit: Sergey Ulanov <sergeyu@chromium.org>
Reviewed-by: default avatarKevin Marshall <kmarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#799011}
parent d191658e
......@@ -358,6 +358,5 @@ void CastRunner::OnMetricsRecorderServiceRequest(
reinterpret_cast<CastComponent*>(main_context_->GetAnyComponent());
DCHECK(component);
component->agent_manager()->ConnectToAgentService(
component->application_config().agent_url(), std::move(request));
component->startup_context()->svc()->Connect(std::move(request));
}
......@@ -878,23 +878,19 @@ TEST_F(CastRunnerIntegrationTest, LegacyMetricsRedirect) {
CreateComponentContext(component_url);
EXPECT_NE(component_context_, nullptr);
base::RunLoop run_loop;
// Add MetricsRecorder the the component's incoming_services.
component_services_.AddPublicService(
std::make_unique<vfs::Service>(
[&run_loop](zx::channel request, async_dispatcher_t* dispatcher) {
run_loop.Quit();
}),
fuchsia::legacymetrics::MetricsRecorder::Name_);
StartCastComponent(component_url);
// Wait until we see the CastRunner connect to the LegacyMetrics service.
base::RunLoop run_loop;
component_state_created_callback_ = base::BindOnce(
[](FakeComponentState** component_state,
base::RepeatingClosure quit_closure) {
(*component_state)
->outgoing_directory()
->AddPublicService(
std::make_unique<vfs::Service>(
[quit_closure](zx::channel, async_dispatcher_t*) {
quit_closure.Run();
}),
fuchsia::legacymetrics::MetricsRecorder::Name_);
},
base::Unretained(&component_state_), run_loop.QuitClosure());
// Wait until we see the CastRunner connect to the MetricsRecorder service.
run_loop.Run();
}
......
......@@ -60,6 +60,12 @@ class WebComponent : public fuchsia::sys::ComponentController,
WebContentRunner* runner() const { return runner_; }
// Returns the component's startup context (e.g. incoming services, public
// service directory, etc).
base::fuchsia::StartupContext* startup_context() const {
return startup_context_.get();
}
protected:
// fuchsia::sys::ComponentController implementation.
void Kill() override;
......@@ -89,12 +95,6 @@ class WebComponent : public fuchsia::sys::ComponentController,
virtual void DestroyComponent(int64_t exit_code,
fuchsia::sys::TerminationReason reason);
// Returns the component's startup context (e.g. incoming services, public
// service directory, etc).
base::fuchsia::StartupContext* startup_context() const {
return startup_context_.get();
}
private:
WebContentRunner* const runner_ = nullptr;
const std::unique_ptr<base::fuchsia::StartupContext> startup_context_;
......
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