Commit f973b693 authored by Paul Moy's avatar Paul Moy Committed by Commit Bot

remote_commands: Add DeviceCommandRunRoutine

Add a new device command to run a diagnostic routine
on the device.

DeviceCommandRunRoutineJobTest.*

Bug: chromium:1049762
Test: unit_tests --gtest_filter=
Change-Id: I1234854ecc6e8d3c7a452519c865402f74bfe1e8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2055807
Commit-Queue: Paul Moy <pmoy@chromium.org>
Reviewed-by: default avatarMaksim Ivanov <emaxx@chromium.org>
Cr-Commit-Position: refs/heads/master@{#742715}
parent 8eb67a72
...@@ -1889,6 +1889,8 @@ source_set("chromeos") { ...@@ -1889,6 +1889,8 @@ source_set("chromeos") {
"policy/remote_commands/device_command_refresh_machine_certificate_job.h", "policy/remote_commands/device_command_refresh_machine_certificate_job.h",
"policy/remote_commands/device_command_remote_powerwash_job.cc", "policy/remote_commands/device_command_remote_powerwash_job.cc",
"policy/remote_commands/device_command_remote_powerwash_job.h", "policy/remote_commands/device_command_remote_powerwash_job.h",
"policy/remote_commands/device_command_run_routine_job.cc",
"policy/remote_commands/device_command_run_routine_job.h",
"policy/remote_commands/device_command_screenshot_job.cc", "policy/remote_commands/device_command_screenshot_job.cc",
"policy/remote_commands/device_command_screenshot_job.h", "policy/remote_commands/device_command_screenshot_job.h",
"policy/remote_commands/device_command_set_volume_job.cc", "policy/remote_commands/device_command_set_volume_job.cc",
...@@ -2949,6 +2951,7 @@ source_set("unit_tests") { ...@@ -2949,6 +2951,7 @@ source_set("unit_tests") {
"policy/pre_signin_policy_fetcher_unittest.cc", "policy/pre_signin_policy_fetcher_unittest.cc",
"policy/remote_commands/device_command_get_available_routines_job_unittest.cc", "policy/remote_commands/device_command_get_available_routines_job_unittest.cc",
"policy/remote_commands/device_command_remote_powerwash_job_unittest.cc", "policy/remote_commands/device_command_remote_powerwash_job_unittest.cc",
"policy/remote_commands/device_command_run_routine_job_unittest.cc",
"policy/remote_commands/device_command_screenshot_job_unittest.cc", "policy/remote_commands/device_command_screenshot_job_unittest.cc",
"policy/remote_commands/device_command_set_volume_job_unittest.cc", "policy/remote_commands/device_command_set_volume_job_unittest.cc",
"policy/remote_commands/device_command_start_crd_session_unittest.cc", "policy/remote_commands/device_command_start_crd_session_unittest.cc",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_CHROMEOS_POLICY_REMOTE_COMMANDS_DEVICE_COMMAND_RUN_ROUTINE_JOB_H_
#define CHROME_BROWSER_CHROMEOS_POLICY_REMOTE_COMMANDS_DEVICE_COMMAND_RUN_ROUTINE_JOB_H_
#include "base/memory/weak_ptr.h"
#include "base/values.h"
#include "chromeos/services/cros_healthd/public/mojom/cros_healthd_diagnostics.mojom.h"
#include "components/policy/core/common/remote_commands/remote_command_job.h"
namespace policy {
// This class implements a RemoteCommandJob that runs a diagnostic routine on
// the platform. The RemoteCommandsQueue owns all instances of this class.
class DeviceCommandRunRoutineJob : public RemoteCommandJob {
public:
DeviceCommandRunRoutineJob();
DeviceCommandRunRoutineJob(const DeviceCommandRunRoutineJob&) = delete;
DeviceCommandRunRoutineJob& operator=(const DeviceCommandRunRoutineJob&) =
delete;
~DeviceCommandRunRoutineJob() override;
// RemoteCommandJob:
enterprise_management::RemoteCommand_Type GetType() const override;
private:
class Payload;
// RemoteCommandJob:
bool ParseCommandPayload(const std::string& command_payload) override;
void RunImpl(CallbackWithResult succeeded_callback,
CallbackWithResult failed_callback) override;
void OnCrosHealthdResponseReceived(
CallbackWithResult succeeded_callback,
CallbackWithResult failed_callback,
chromeos::cros_healthd::mojom::RunRoutineResponsePtr response);
// Which routine the DeviceCommandRunRoutineJob will run.
chromeos::cros_healthd::mojom::DiagnosticRoutineEnum routine_enum_;
// Parameters for the routine to be run. See
// chromeos/services/cros_healthd/public/mojom/cros_healthd.mojom for details
// on the parameters accepted by each individual routine.
base::Value params_dict_;
base::WeakPtrFactory<DeviceCommandRunRoutineJob> weak_ptr_factory_{this};
};
} // namespace policy
#endif // CHROME_BROWSER_CHROMEOS_POLICY_REMOTE_COMMANDS_DEVICE_COMMAND_RUN_ROUTINE_JOB_H_
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "chrome/browser/chromeos/policy/remote_commands/device_command_reboot_job.h" #include "chrome/browser/chromeos/policy/remote_commands/device_command_reboot_job.h"
#include "chrome/browser/chromeos/policy/remote_commands/device_command_refresh_machine_certificate_job.h" #include "chrome/browser/chromeos/policy/remote_commands/device_command_refresh_machine_certificate_job.h"
#include "chrome/browser/chromeos/policy/remote_commands/device_command_remote_powerwash_job.h" #include "chrome/browser/chromeos/policy/remote_commands/device_command_remote_powerwash_job.h"
#include "chrome/browser/chromeos/policy/remote_commands/device_command_run_routine_job.h"
#include "chrome/browser/chromeos/policy/remote_commands/device_command_screenshot_job.h" #include "chrome/browser/chromeos/policy/remote_commands/device_command_screenshot_job.h"
#include "chrome/browser/chromeos/policy/remote_commands/device_command_set_volume_job.h" #include "chrome/browser/chromeos/policy/remote_commands/device_command_set_volume_job.h"
#include "chrome/browser/chromeos/policy/remote_commands/device_command_start_crd_session_job.h" #include "chrome/browser/chromeos/policy/remote_commands/device_command_start_crd_session_job.h"
...@@ -57,6 +58,8 @@ DeviceCommandsFactoryChromeOS::BuildJobForType(em::RemoteCommand_Type type, ...@@ -57,6 +58,8 @@ DeviceCommandsFactoryChromeOS::BuildJobForType(em::RemoteCommand_Type type,
return std::make_unique<DeviceCommandRemotePowerwashJob>(service); return std::make_unique<DeviceCommandRemotePowerwashJob>(service);
case em::RemoteCommand_Type_DEVICE_GET_AVAILABLE_DIAGNOSTIC_ROUTINES: case em::RemoteCommand_Type_DEVICE_GET_AVAILABLE_DIAGNOSTIC_ROUTINES:
return std::make_unique<DeviceCommandGetAvailableRoutinesJob>(); return std::make_unique<DeviceCommandGetAvailableRoutinesJob>();
case em::RemoteCommand_Type_DEVICE_RUN_DIAGNOSTIC_ROUTINE:
return std::make_unique<DeviceCommandRunRoutineJob>();
default: default:
// Other types of commands should be sent to UserCommandsFactoryChromeOS // Other types of commands should be sent to UserCommandsFactoryChromeOS
// instead of here. // instead of here.
......
...@@ -2082,6 +2082,9 @@ message RemoteCommand { ...@@ -2082,6 +2082,9 @@ message RemoteCommand {
// Retrieve a list of available diagnostics routines. // Retrieve a list of available diagnostics routines.
DEVICE_GET_AVAILABLE_DIAGNOSTIC_ROUTINES = 9; DEVICE_GET_AVAILABLE_DIAGNOSTIC_ROUTINES = 9;
// Run a given diagnostics routine on the platform.
DEVICE_RUN_DIAGNOSTIC_ROUTINE = 10;
} }
// The command type. // The command type.
...@@ -2101,6 +2104,8 @@ message RemoteCommand { ...@@ -2101,6 +2104,8 @@ message RemoteCommand {
// |DEVICE_SCREENSHOT|: {"fileUploadUrl" : url_string}. // |DEVICE_SCREENSHOT|: {"fileUploadUrl" : url_string}.
// |DEVICE_SET_VOLUME|: {"volume": volume_value}, where volume_value must be // |DEVICE_SET_VOLUME|: {"volume": volume_value}, where volume_value must be
// an integer between 0 and 100. // an integer between 0 and 100.
// |DEVICE_RUN_DIAGNOSTIC_ROUTINE|: {"routine" : routine_enum, "params" :
// params_dict}, where params_dict varies by routine.
optional string payload = 4; optional string payload = 4;
// An identifier for the target this command is for. This is the same as // An identifier for the target this command is for. This is the same as
......
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