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