Commit 7f109b2a authored by Paul Moy's avatar Paul Moy Committed by Commit Bot

cros_healthd: change to new interface

Update Chrome's copy of cros_healthd.mojom to stay in
sync with Chrome OS's copy, and change cros_healthd's
ServiceConnection to work with the new mojo interface.

Bug: chromium:1040161
Test: chromeos_unittests --gtest_filter=CrosHealthdServiceConnectionTest.*
Change-Id: If3b0fba44bcea71e8221dd86f9a9ad8f772b05e0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1992586
Commit-Queue: Paul Moy <pmoy@chromium.org>
Reviewed-by: default avatarJorge Lucangeli Obes <jorgelo@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#730974}
parent fbbbe23b
...@@ -29,7 +29,8 @@ class CrosHealthdClientImpl : public CrosHealthdClient { ...@@ -29,7 +29,8 @@ class CrosHealthdClientImpl : public CrosHealthdClient {
~CrosHealthdClientImpl() override = default; ~CrosHealthdClientImpl() override = default;
// CrosHealthdClient overrides: // CrosHealthdClient overrides:
mojo::Remote<cros_healthd::mojom::CrosHealthdService> BootstrapMojoConnection( mojo::Remote<cros_healthd::mojom::CrosHealthdServiceFactory>
BootstrapMojoConnection(
base::OnceCallback<void(bool success)> result_callback) override { base::OnceCallback<void(bool success)> result_callback) override {
mojo::PlatformChannel platform_channel; mojo::PlatformChannel platform_channel;
...@@ -44,9 +45,10 @@ class CrosHealthdClientImpl : public CrosHealthdClient { ...@@ -44,9 +45,10 @@ class CrosHealthdClientImpl : public CrosHealthdClient {
// Bind our end of |pipe| to our CrosHealthdService remote. The daemon // Bind our end of |pipe| to our CrosHealthdService remote. The daemon
// should bind its end to a CrosHealthdService implementation. // should bind its end to a CrosHealthdService implementation.
mojo::Remote<cros_healthd::mojom::CrosHealthdService> cros_healthd_service; mojo::Remote<cros_healthd::mojom::CrosHealthdServiceFactory>
cros_healthd_service.Bind( cros_healthd_service_factory;
mojo::PendingRemote<cros_healthd::mojom::CrosHealthdService>( cros_healthd_service_factory.Bind(
mojo::PendingRemote<cros_healthd::mojom::CrosHealthdServiceFactory>(
std::move(pipe), 0u /* version */)); std::move(pipe), 0u /* version */));
dbus::MethodCall method_call( dbus::MethodCall method_call(
...@@ -63,7 +65,7 @@ class CrosHealthdClientImpl : public CrosHealthdClient { ...@@ -63,7 +65,7 @@ class CrosHealthdClientImpl : public CrosHealthdClient {
&CrosHealthdClientImpl::OnBootstrapMojoConnectionResponse, &CrosHealthdClientImpl::OnBootstrapMojoConnectionResponse,
weak_ptr_factory_.GetWeakPtr(), std::move(result_callback))); weak_ptr_factory_.GetWeakPtr(), std::move(result_callback)));
return cros_healthd_service; return cros_healthd_service_factory;
} }
void Init(dbus::Bus* const bus) { void Init(dbus::Bus* const bus) {
......
...@@ -40,7 +40,7 @@ class COMPONENT_EXPORT(CROS_HEALTHD) CrosHealthdClient { ...@@ -40,7 +40,7 @@ class COMPONENT_EXPORT(CROS_HEALTHD) CrosHealthdClient {
// 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::CrosHealthdService> virtual mojo::Remote<cros_healthd::mojom::CrosHealthdServiceFactory>
BootstrapMojoConnection( BootstrapMojoConnection(
base::OnceCallback<void(bool success)> result_callback) = 0; base::OnceCallback<void(bool success)> result_callback) = 0;
......
...@@ -32,10 +32,10 @@ FakeCrosHealthdClient* FakeCrosHealthdClient::Get() { ...@@ -32,10 +32,10 @@ FakeCrosHealthdClient* FakeCrosHealthdClient::Get() {
return g_instance; return g_instance;
} }
mojo::Remote<mojom::CrosHealthdService> mojo::Remote<mojom::CrosHealthdServiceFactory>
FakeCrosHealthdClient::BootstrapMojoConnection( FakeCrosHealthdClient::BootstrapMojoConnection(
base::OnceCallback<void(bool success)> result_callback) { base::OnceCallback<void(bool success)> result_callback) {
mojo::Remote<mojom::CrosHealthdService> remote( mojo::Remote<mojom::CrosHealthdServiceFactory> remote(
receiver_.BindNewPipeAndPassRemote()); receiver_.BindNewPipeAndPassRemote());
std::move(result_callback).Run(/*success=*/true); std::move(result_callback).Run(/*success=*/true);
......
...@@ -34,7 +34,7 @@ class COMPONENT_EXPORT(CROS_HEALTHD) FakeCrosHealthdClient ...@@ -34,7 +34,7 @@ class COMPONENT_EXPORT(CROS_HEALTHD) FakeCrosHealthdClient
static FakeCrosHealthdClient* Get(); static FakeCrosHealthdClient* Get();
// CrosHealthdClient overrides: // CrosHealthdClient overrides:
mojo::Remote<mojom::CrosHealthdService> BootstrapMojoConnection( mojo::Remote<mojom::CrosHealthdServiceFactory> BootstrapMojoConnection(
base::OnceCallback<void(bool success)> result_callback) override; base::OnceCallback<void(bool success)> 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
...@@ -56,7 +56,7 @@ class COMPONENT_EXPORT(CROS_HEALTHD) FakeCrosHealthdClient ...@@ -56,7 +56,7 @@ class COMPONENT_EXPORT(CROS_HEALTHD) FakeCrosHealthdClient
private: private:
FakeCrosHealthdService fake_service_; FakeCrosHealthdService fake_service_;
mojo::Receiver<mojom::CrosHealthdService> receiver_{&fake_service_}; mojo::Receiver<mojom::CrosHealthdServiceFactory> receiver_{&fake_service_};
DISALLOW_COPY_AND_ASSIGN(FakeCrosHealthdClient); DISALLOW_COPY_AND_ASSIGN(FakeCrosHealthdClient);
}; };
......
...@@ -12,6 +12,16 @@ namespace cros_healthd { ...@@ -12,6 +12,16 @@ namespace cros_healthd {
FakeCrosHealthdService::FakeCrosHealthdService() = default; FakeCrosHealthdService::FakeCrosHealthdService() = default;
FakeCrosHealthdService::~FakeCrosHealthdService() = default; FakeCrosHealthdService::~FakeCrosHealthdService() = default;
void FakeCrosHealthdService::GetProbeService(
mojom::CrosHealthdProbeServiceRequest service) {
probe_receiver_set_.Add(this, std::move(service));
}
void FakeCrosHealthdService::GetDiagnosticsService(
mojom::CrosHealthdDiagnosticsServiceRequest service) {
diagnostics_receiver_set_.Add(this, std::move(service));
}
void FakeCrosHealthdService::GetAvailableRoutines( void FakeCrosHealthdService::GetAvailableRoutines(
GetAvailableRoutinesCallback callback) { GetAvailableRoutinesCallback callback) {
std::move(callback).Run(available_routines_); std::move(callback).Run(available_routines_);
......
...@@ -11,16 +11,29 @@ ...@@ -11,16 +11,29 @@
#include "chromeos/services/cros_healthd/public/mojom/cros_healthd.mojom.h" #include "chromeos/services/cros_healthd/public/mojom/cros_healthd.mojom.h"
#include "chromeos/services/cros_healthd/public/mojom/cros_healthd_diagnostics.mojom.h" #include "chromeos/services/cros_healthd/public/mojom/cros_healthd_diagnostics.mojom.h"
#include "chromeos/services/cros_healthd/public/mojom/cros_healthd_probe.mojom.h" #include "chromeos/services/cros_healthd/public/mojom/cros_healthd_probe.mojom.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
namespace chromeos { namespace chromeos {
namespace cros_healthd { namespace cros_healthd {
class FakeCrosHealthdService final : public mojom::CrosHealthdService { // This class serves as a fake for all three of cros_healthd's mojo interfaces.
// The factory methods bind to receivers held within FakeCrosHealtdService, and
// all requests on each of the interfaces are fulfilled by
// FakeCrosHealthdService.
class FakeCrosHealthdService final
: public mojom::CrosHealthdServiceFactory,
public mojom::CrosHealthdDiagnosticsService,
public mojom::CrosHealthdProbeService {
public: public:
FakeCrosHealthdService(); FakeCrosHealthdService();
~FakeCrosHealthdService() override; ~FakeCrosHealthdService() override;
// CrosHealthdService overrides: // CrosHealthdServiceFactory overrides:
void GetProbeService(mojom::CrosHealthdProbeServiceRequest service) override;
void GetDiagnosticsService(
mojom::CrosHealthdDiagnosticsServiceRequest service) override;
// CrosHealthdDiagnosticsService overrides:
void GetAvailableRoutines(GetAvailableRoutinesCallback callback) override; void GetAvailableRoutines(GetAvailableRoutinesCallback callback) override;
void GetRoutineUpdate(int32_t id, void GetRoutineUpdate(int32_t id,
mojom::DiagnosticRoutineCommandEnum command, mojom::DiagnosticRoutineCommandEnum command,
...@@ -38,6 +51,8 @@ class FakeCrosHealthdService final : public mojom::CrosHealthdService { ...@@ -38,6 +51,8 @@ class FakeCrosHealthdService final : public mojom::CrosHealthdService {
RunBatteryHealthRoutineCallback callback) override; RunBatteryHealthRoutineCallback callback) override;
void RunSmartctlCheckRoutine( void RunSmartctlCheckRoutine(
RunSmartctlCheckRoutineCallback callback) override; RunSmartctlCheckRoutineCallback callback) override;
// CrosHealthdProbeService overrides:
void ProbeTelemetryInfo( void ProbeTelemetryInfo(
const std::vector<mojom::ProbeCategoryEnum>& categories, const std::vector<mojom::ProbeCategoryEnum>& categories,
ProbeTelemetryInfoCallback callback) override; ProbeTelemetryInfoCallback callback) override;
...@@ -71,6 +86,11 @@ class FakeCrosHealthdService final : public mojom::CrosHealthdService { ...@@ -71,6 +86,11 @@ class FakeCrosHealthdService final : public mojom::CrosHealthdService {
// Used as the response to any ProbeTelemetryInfo IPCs received. // Used as the response to any ProbeTelemetryInfo IPCs received.
mojom::TelemetryInfoPtr telemetry_response_info_{mojom::TelemetryInfo::New()}; mojom::TelemetryInfoPtr telemetry_response_info_{mojom::TelemetryInfo::New()};
// Allows the remote end to call the probe and diagnostics service methods.
mojo::ReceiverSet<mojom::CrosHealthdProbeService> probe_receiver_set_;
mojo::ReceiverSet<mojom::CrosHealthdDiagnosticsService>
diagnostics_receiver_set_;
DISALLOW_COPY_AND_ASSIGN(FakeCrosHealthdService); DISALLOW_COPY_AND_ASSIGN(FakeCrosHealthdService);
}; };
......
...@@ -23,7 +23,8 @@ class ServiceConnection { ...@@ -23,7 +23,8 @@ class ServiceConnection {
// src/chromeos/service/cros_healthd/public/mojom/cros_healthd.mojom for // src/chromeos/service/cros_healthd/public/mojom/cros_healthd.mojom for
// details. // details.
virtual void GetAvailableRoutines( virtual void GetAvailableRoutines(
mojom::CrosHealthdService::GetAvailableRoutinesCallback callback) = 0; mojom::CrosHealthdDiagnosticsService::GetAvailableRoutinesCallback
callback) = 0;
// Send a command to an existing routine. Also returns status information // Send a command to an existing routine. Also returns status information
// for the routine. See // for the routine. See
...@@ -33,14 +34,16 @@ class ServiceConnection { ...@@ -33,14 +34,16 @@ class ServiceConnection {
int32_t id, int32_t id,
mojom::DiagnosticRoutineCommandEnum command, mojom::DiagnosticRoutineCommandEnum command,
bool include_output, bool include_output,
mojom::CrosHealthdService::GetRoutineUpdateCallback callback) = 0; mojom::CrosHealthdDiagnosticsService::GetRoutineUpdateCallback
callback) = 0;
// Requests that cros_healthd runs the urandom routine. See // Requests that cros_healthd runs the urandom routine. See
// src/chromeos/service/cros_healthd/public/mojom/cros_healthd.mojom for // src/chromeos/service/cros_healthd/public/mojom/cros_healthd.mojom for
// details. // details.
virtual void RunUrandomRoutine( virtual void RunUrandomRoutine(
uint32_t length_seconds, uint32_t length_seconds,
mojom::CrosHealthdService::RunUrandomRoutineCallback callback) = 0; mojom::CrosHealthdDiagnosticsService::RunUrandomRoutineCallback
callback) = 0;
// Requests that cros_healthd runs the battery capacity routine. See // Requests that cros_healthd runs the battery capacity routine. See
// src/chromeos/service/cros_healthd/public/mojom/cros_healthd.mojom for // src/chromeos/service/cros_healthd/public/mojom/cros_healthd.mojom for
...@@ -48,7 +51,7 @@ class ServiceConnection { ...@@ -48,7 +51,7 @@ class ServiceConnection {
virtual void RunBatteryCapacityRoutine( virtual void RunBatteryCapacityRoutine(
uint32_t low_mah, uint32_t low_mah,
uint32_t high_mah, uint32_t high_mah,
mojom::CrosHealthdService::RunBatteryCapacityRoutineCallback mojom::CrosHealthdDiagnosticsService::RunBatteryCapacityRoutineCallback
callback) = 0; callback) = 0;
// Requests that cros_healthd runs the battery health routine. See // Requests that cros_healthd runs the battery health routine. See
...@@ -57,20 +60,22 @@ class ServiceConnection { ...@@ -57,20 +60,22 @@ class ServiceConnection {
virtual void RunBatteryHealthRoutine( virtual void RunBatteryHealthRoutine(
uint32_t maximum_cycle_count, uint32_t maximum_cycle_count,
uint32_t percent_battery_wear_allowed, uint32_t percent_battery_wear_allowed,
mojom::CrosHealthdService::RunBatteryHealthRoutineCallback callback) = 0; mojom::CrosHealthdDiagnosticsService::RunBatteryHealthRoutineCallback
callback) = 0;
// Requests that cros_healthd runs the smartcl check routine. See // Requests that cros_healthd runs the smartcl check routine. See
// src/chromeos/service/cros_healthd/public/mojom/cros_healthd.mojom for // src/chromeos/service/cros_healthd/public/mojom/cros_healthd.mojom for
// details. // details.
virtual void RunSmartctlCheckRoutine( virtual void RunSmartctlCheckRoutine(
mojom::CrosHealthdService::RunSmartctlCheckRoutineCallback callback) = 0; mojom::CrosHealthdDiagnosticsService::RunSmartctlCheckRoutineCallback
callback) = 0;
// Gather pieces of information about the platform. See // Gather pieces of information about the platform. See
// src/chromeos/service/cros_healthd/public/mojom/cros_healthd.mojom for // src/chromeos/service/cros_healthd/public/mojom/cros_healthd.mojom for
// details. // details.
virtual void ProbeTelemetryInfo( virtual void ProbeTelemetryInfo(
const std::vector<mojom::ProbeCategoryEnum>& categories_to_test, const std::vector<mojom::ProbeCategoryEnum>& categories_to_test,
mojom::CrosHealthdService::ProbeTelemetryInfoCallback callback) = 0; mojom::CrosHealthdProbeService::ProbeTelemetryInfoCallback callback) = 0;
protected: protected:
ServiceConnection() = default; ServiceConnection() = default;
......
...@@ -13,9 +13,17 @@ module chromeos.cros_healthd.mojom; ...@@ -13,9 +13,17 @@ module chromeos.cros_healthd.mojom;
import "chromeos/services/cros_healthd/public/mojom/cros_healthd_diagnostics.mojom"; import "chromeos/services/cros_healthd/public/mojom/cros_healthd_diagnostics.mojom";
import "chromeos/services/cros_healthd/public/mojom/cros_healthd_probe.mojom"; import "chromeos/services/cros_healthd/public/mojom/cros_healthd_probe.mojom";
// Interface exposed by the cros_healthd daemon. // Factory interface which allows remote ends to request implementations of the
interface CrosHealthdService { // probe or diagnostics services.
// ------------------- Start of diagnostics definitions --------------------- interface CrosHealthdServiceFactory {
// Returns a bound interface to the diagnostics service.
GetDiagnosticsService(CrosHealthdDiagnosticsService& service);
// Returns a bound interface to the probe service.
GetProbeService(CrosHealthdProbeService& service);
};
// Diagnostics interface exposed by the cros_healthd daemon.
interface CrosHealthdDiagnosticsService {
// Returns an array of all diagnostic routines that the platform supports. // Returns an array of all diagnostic routines that the platform supports.
GetAvailableRoutines() GetAvailableRoutines()
=> (array<DiagnosticRoutineEnum> available_routines); => (array<DiagnosticRoutineEnum> available_routines);
...@@ -98,20 +106,11 @@ interface CrosHealthdService { ...@@ -98,20 +106,11 @@ interface CrosHealthdService {
// * |response| - contains a unique identifier and status for the created // * |response| - contains a unique identifier and status for the created
// routine. // routine.
RunSmartctlCheckRoutine() => (RunRoutineResponse response); RunSmartctlCheckRoutine() => (RunRoutineResponse response);
};
// ------------------- End of diagnostics definitions ----------------------- // Probe interface exposed by the cros_healthd daemon.
interface CrosHealthdProbeService {
// ------------------- Start of probe definitions --------------------- // Returns telemetry information for the desired categories.
// Returns telemetry information for the desired categories. This IPC is
// exposed so that the browser can pull data from cros_healthd. The browser
// will periodically call ProbeTelemetryInfo and upload the results to the EMM
// API in the cloud, where the data collected from cros_healthd will be made
// available to OEMs. Since the browser is making requests and cros_healthd is
// replying, we can consider cros_healthd the privileged side of this
// communication. ProbeTelemetryInfo only returns parsed data, so the browser
// will not do any parsing. cros_healthd does not process input that could be
// controlled by a malicious attacker.
// //
// The request: // The request:
// * |categories| - list of each of the categories that ProbeTelemetryInfo // * |categories| - list of each of the categories that ProbeTelemetryInfo
...@@ -123,6 +122,4 @@ interface CrosHealthdService { ...@@ -123,6 +122,4 @@ interface CrosHealthdService {
// will be non-null. // will be non-null.
ProbeTelemetryInfo(array<ProbeCategoryEnum> categories) ProbeTelemetryInfo(array<ProbeCategoryEnum> categories)
=> (TelemetryInfo telemetry_info); => (TelemetryInfo telemetry_info);
// ------------------- End of probe definitions -----------------------
}; };
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