Commit b70d28c8 authored by Trent Begin's avatar Trent Begin Committed by Commit Bot

cros_healthd: start service connection on startup

This change creates a connection with the cros_healthd service factory
when the service connection is created. This will eventually allow
Chrome services (NetworkHealth and NetworkDiagnostics) to be passed to
cros_healthd when Chrome starts.

Bug: chromium:1057739
Change-Id: I0b2142d40adeac4d1991b22642b4555acbf31b97
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2303362
Commit-Queue: Trent Begin <tbegin@chromium.org>
Reviewed-by: default avatarPaul Moy <pmoy@chromium.org>
Reviewed-by: default avatarJesse Schettler <jschettler@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#791845}
parent d48b58c7
......@@ -165,6 +165,7 @@
#include "chromeos/network/network_cert_loader.h"
#include "chromeos/network/network_handler.h"
#include "chromeos/network/portal_detector/network_portal_detector_stub.h"
#include "chromeos/services/cros_healthd/public/cpp/service_connection.h"
#include "chromeos/system/statistics_provider.h"
#include "chromeos/tpm/install_attributes.h"
#include "chromeos/tpm/tpm_token_loader.h"
......@@ -903,6 +904,11 @@ void ChromeBrowserMainPartsChromeos::PostProfileInit() {
network_health::NetworkHealthService::GetInstance();
DCHECK(network_health_service);
// Create the service connection to cros_healthd.
cros_healthd::ServiceConnection* cros_healthd =
cros_healthd::ServiceConnection::GetInstance();
DCHECK(cros_healthd);
// Initialize input methods.
input_method::InputMethodManager* manager =
input_method::InputMethodManager::Get();
......
......@@ -31,7 +31,7 @@ class CrosHealthdClientImpl : public CrosHealthdClient {
// CrosHealthdClient overrides:
mojo::Remote<cros_healthd::mojom::CrosHealthdServiceFactory>
BootstrapMojoConnection(
base::OnceCallback<void(bool success)> result_callback) override {
BootstrapMojoConnectionCallback result_callback) override {
mojo::PlatformChannel platform_channel;
// Prepare a Mojo invitation to send through |platform_channel|.
......@@ -79,7 +79,7 @@ class CrosHealthdClientImpl : public CrosHealthdClient {
// Passes the success/failure of |dbus_response| on to |result_callback|.
void OnBootstrapMojoConnectionResponse(
base::OnceCallback<void(bool success)> result_callback,
BootstrapMojoConnectionCallback result_callback,
dbus::Response* const dbus_response) {
const bool success = dbus_response != nullptr;
std::move(result_callback).Run(success);
......
......@@ -26,6 +26,9 @@ namespace chromeos {
// Mojo connection to the cros_healthd daemon.
class COMPONENT_EXPORT(CROS_HEALTHD) CrosHealthdClient {
public:
using BootstrapMojoConnectionCallback =
base::OnceCallback<void(bool success)>;
// Creates and initializes the global instance. |bus| must not be null.
static void Initialize(dbus::Bus* bus);
......@@ -39,10 +42,9 @@ class COMPONENT_EXPORT(CROS_HEALTHD) CrosHealthdClient {
static CrosHealthdClient* Get();
// Uses D-Bus to bootstrap the Mojo connection between the cros_healthd daemon
// and the browser. Returns a bound remote
// and the browser. Returns a bound remote.
virtual mojo::Remote<cros_healthd::mojom::CrosHealthdServiceFactory>
BootstrapMojoConnection(
base::OnceCallback<void(bool success)> result_callback) = 0;
BootstrapMojoConnection(BootstrapMojoConnectionCallback) = 0;
protected:
// Initialize/Shutdown should be used instead.
......
......@@ -34,7 +34,7 @@ FakeCrosHealthdClient* FakeCrosHealthdClient::Get() {
mojo::Remote<mojom::CrosHealthdServiceFactory>
FakeCrosHealthdClient::BootstrapMojoConnection(
base::OnceCallback<void(bool success)> result_callback) {
BootstrapMojoConnectionCallback result_callback) {
mojo::Remote<mojom::CrosHealthdServiceFactory> remote(
receiver_.BindNewPipeAndPassRemote());
......
......@@ -35,7 +35,7 @@ class COMPONENT_EXPORT(CROS_HEALTHD) FakeCrosHealthdClient
// CrosHealthdClient overrides:
mojo::Remote<mojom::CrosHealthdServiceFactory> BootstrapMojoConnection(
base::OnceCallback<void(bool success)> result_callback) override;
BootstrapMojoConnectionCallback result_callback) override;
// Set the list of routines that will be used in the response to any
// GetAvailableRoutines IPCs received.
......
......@@ -115,7 +115,7 @@ class ServiceConnectionImpl : public ServiceConnection {
// Binds the factory interface |cros_healthd_service_factory_| to an
// implementation in the cros_healthd daemon, if it is not already bound. The
// binding is accomplished via D-Bus bootstrap.
void BindCrosHealthdServiceFactoryIfNeeded();
void EnsureCrosHealthdServiceFactoryIsBound();
// Uses |cros_healthd_service_factory_| to bind the diagnostics service remote
// to an implementation in the cros_healethd daemon, if it is not already
......@@ -346,26 +346,30 @@ void ServiceConnectionImpl::ProbeProcessInfo(
void ServiceConnectionImpl::GetDiagnosticsService(
mojom::CrosHealthdDiagnosticsServiceRequest service) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
BindCrosHealthdServiceFactoryIfNeeded();
EnsureCrosHealthdServiceFactoryIsBound();
cros_healthd_service_factory_->GetDiagnosticsService(std::move(service));
}
void ServiceConnectionImpl::GetProbeService(
mojom::CrosHealthdProbeServiceRequest service) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
BindCrosHealthdServiceFactoryIfNeeded();
EnsureCrosHealthdServiceFactoryIsBound();
cros_healthd_service_factory_->GetProbeService(std::move(service));
}
void ServiceConnectionImpl::BindCrosHealthdServiceFactoryIfNeeded() {
void ServiceConnectionImpl::EnsureCrosHealthdServiceFactoryIsBound() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (cros_healthd_service_factory_.is_bound())
return;
cros_healthd_service_factory_ =
CrosHealthdClient::Get()->BootstrapMojoConnection(base::BindOnce(
&ServiceConnectionImpl::OnBootstrapMojoConnectionResponse,
auto* client = CrosHealthdClient::Get();
if (!client)
return;
cros_healthd_service_factory_ = client->BootstrapMojoConnection(
base::BindOnce(&ServiceConnectionImpl::OnBootstrapMojoConnectionResponse,
base::Unretained(this)));
cros_healthd_service_factory_.set_disconnect_handler(base::BindOnce(
&ServiceConnectionImpl::OnDisconnect, base::Unretained(this)));
}
......@@ -375,7 +379,7 @@ void ServiceConnectionImpl::BindCrosHealthdDiagnosticsServiceIfNeeded() {
if (cros_healthd_diagnostics_service_.is_bound())
return;
BindCrosHealthdServiceFactoryIfNeeded();
EnsureCrosHealthdServiceFactoryIsBound();
cros_healthd_service_factory_->GetDiagnosticsService(
cros_healthd_diagnostics_service_.BindNewPipeAndPassReceiver());
cros_healthd_diagnostics_service_.set_disconnect_handler(base::BindOnce(
......@@ -387,7 +391,7 @@ void ServiceConnectionImpl::BindCrosHealthdEventServiceIfNeeded() {
if (cros_healthd_event_service_.is_bound())
return;
BindCrosHealthdServiceFactoryIfNeeded();
EnsureCrosHealthdServiceFactoryIsBound();
cros_healthd_service_factory_->GetEventService(
cros_healthd_event_service_.BindNewPipeAndPassReceiver());
cros_healthd_event_service_.set_disconnect_handler(base::BindOnce(
......@@ -399,7 +403,7 @@ void ServiceConnectionImpl::BindCrosHealthdProbeServiceIfNeeded() {
if (cros_healthd_probe_service_.is_bound())
return;
BindCrosHealthdServiceFactoryIfNeeded();
EnsureCrosHealthdServiceFactoryIsBound();
cros_healthd_service_factory_->GetProbeService(
cros_healthd_probe_service_.BindNewPipeAndPassReceiver());
cros_healthd_probe_service_.set_disconnect_handler(base::BindOnce(
......@@ -408,6 +412,7 @@ void ServiceConnectionImpl::BindCrosHealthdProbeServiceIfNeeded() {
ServiceConnectionImpl::ServiceConnectionImpl() {
DETACH_FROM_SEQUENCE(sequence_checker_);
EnsureCrosHealthdServiceFactoryIsBound();
}
void ServiceConnectionImpl::OnDisconnect() {
......@@ -418,6 +423,8 @@ void ServiceConnectionImpl::OnDisconnect() {
cros_healthd_probe_service_.reset();
cros_healthd_diagnostics_service_.reset();
cros_healthd_event_service_.reset();
EnsureCrosHealthdServiceFactoryIsBound();
}
void ServiceConnectionImpl::OnBootstrapMojoConnectionResponse(
......
......@@ -451,6 +451,7 @@ TEST_F(CrosHealthdServiceConnectionTest, AddPowerObserver) {
run_loop.Run();
}
// Test that we can probe telemetry info.
TEST_F(CrosHealthdServiceConnectionTest, ProbeTelemetryInfo) {
auto response = mojom::TelemetryInfo::New();
FakeCrosHealthdClient::Get()->SetProbeTelemetryInfoResponseForTesting(
......
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