Skip to content

Commit

Permalink
Introduce DeviceCommandFetchSupportPacketJob class
Browse files Browse the repository at this point in the history
DeviceCommandFetchSupportPacketJob will execute FETCH_SUPPORT_PACKET
remote command. Introduce the class (the contents will be filled in
follow-up CL as a TODO). Sync FETCH_SUPPORT_PACKET command type in
device_management.proto in google3. Add the enum values for histograms
for the new command type.

Bug: b:264399756
Change-Id: I5837cd3a2550341118859a33f80700e6c214852c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4274929
Reviewed-by: Pavol Marko <pmarko@chromium.org>
Commit-Queue: Irem Uguz <iremuguz@google.com>
Reviewed-by: Igor Ruvinov <igorruvinov@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1108870}
  • Loading branch information
Irem Uguz authored and Chromium LUCI CQ committed Feb 23, 2023
1 parent 1528450 commit 2c946a4
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 1 deletion.
3 changes: 3 additions & 0 deletions chrome/browser/ash/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -2425,6 +2425,8 @@ source_set("ash") {
"policy/remote_commands/device_command_fetch_crd_availability_info_job.h",
"policy/remote_commands/device_command_fetch_status_job.cc",
"policy/remote_commands/device_command_fetch_status_job.h",
"policy/remote_commands/device_command_fetch_support_packet_job.cc",
"policy/remote_commands/device_command_fetch_support_packet_job.h",
"policy/remote_commands/device_command_get_available_routines_job.cc",
"policy/remote_commands/device_command_get_available_routines_job.h",
"policy/remote_commands/device_command_get_routine_update_job.cc",
Expand Down Expand Up @@ -3382,6 +3384,7 @@ source_set("ash") {
"//chrome/browser/policy/messaging_layer/proto:crd_event_proto",
"//chrome/browser/profiles:profile",
"//chrome/browser/safe_browsing",
"//chrome/browser/support_tool:support_tool_proto",
"//chrome/browser/ui/webui/ash/crostini_upgrader:mojo_bindings_headers",
"//chrome/browser/ui/webui/bluetooth_internals:mojo_bindings",
"//chrome/browser/web_applications",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ash/policy/remote_commands/device_command_fetch_support_packet_job.h"

#include <string>
#include <utility>

#include "chrome/browser/support_tool/data_collection_module.pb.h"
#include "components/policy/proto/device_management_backend.pb.h"

namespace policy {

DeviceCommandFetchSupportPacketJob::DeviceCommandFetchSupportPacketJob() =
default;

DeviceCommandFetchSupportPacketJob::~DeviceCommandFetchSupportPacketJob() =
default;

enterprise_management::RemoteCommand_Type
DeviceCommandFetchSupportPacketJob::GetType() const {
return enterprise_management::RemoteCommand_Type_FETCH_SUPPORT_PACKET;
}

void DeviceCommandFetchSupportPacketJob::RunImpl(
CallbackWithResult result_callback) {
result_callback_ = std::move(result_callback);
// TODO(b/264399756): The contents will be filled in the follow-up CL.
}

bool DeviceCommandFetchSupportPacketJob::ParseCommandPayload(
const std::string& command_payload) {
return support_packet_details_.ParseFromString(command_payload);
}

} // namespace policy
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_ASH_POLICY_REMOTE_COMMANDS_DEVICE_COMMAND_FETCH_SUPPORT_PACKET_JOB_H_
#define CHROME_BROWSER_ASH_POLICY_REMOTE_COMMANDS_DEVICE_COMMAND_FETCH_SUPPORT_PACKET_JOB_H_

#include <memory>
#include <string>

#include "base/memory/weak_ptr.h"
#include "chrome/browser/support_tool/data_collection_module.pb.h"
#include "components/policy/core/common/remote_commands/remote_command_job.h"
#include "components/policy/proto/device_management_backend.pb.h"

namespace policy {

class DeviceCommandFetchSupportPacketJob : public RemoteCommandJob {
public:
DeviceCommandFetchSupportPacketJob();

DeviceCommandFetchSupportPacketJob(
const DeviceCommandFetchSupportPacketJob&) = delete;
DeviceCommandFetchSupportPacketJob& operator=(
const DeviceCommandFetchSupportPacketJob&) = delete;

~DeviceCommandFetchSupportPacketJob() override;

// RemoteCommandJob:
enterprise_management::RemoteCommand_Type GetType() const override;

protected:
// RemoteCommandJob:
void RunImpl(CallbackWithResult result_callback) override;
// Parses `command_payload` into SupportPacketDetails proto message.
bool ParseCommandPayload(const std::string& command_payload) override;

private:
// The details of requested support packet. Contains details like data
// collectors, PII types, case ID etc.
support_tool::SupportPacketDetails support_packet_details_;
// The callback to run when the execution of RemoteCommandJob has finished.
CallbackWithResult result_callback_;
base::WeakPtrFactory<DeviceCommandFetchSupportPacketJob> weak_ptr_factory_{
this};
};

} // namespace policy

#endif // CHROME_BROWSER_ASH_POLICY_REMOTE_COMMANDS_DEVICE_COMMAND_FETCH_SUPPORT_PACKET_JOB_H_
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "chrome/browser/ash/policy/remote_commands/crd_host_delegate.h"
#include "chrome/browser/ash/policy/remote_commands/device_command_fetch_crd_availability_info_job.h"
#include "chrome/browser/ash/policy/remote_commands/device_command_fetch_status_job.h"
#include "chrome/browser/ash/policy/remote_commands/device_command_fetch_support_packet_job.h"
#include "chrome/browser/ash/policy/remote_commands/device_command_get_available_routines_job.h"
#include "chrome/browser/ash/policy/remote_commands/device_command_get_routine_update_job.h"
#include "chrome/browser/ash/policy/remote_commands/device_command_reboot_job.h"
Expand Down Expand Up @@ -72,6 +73,8 @@ std::unique_ptr<RemoteCommandJob> DeviceCommandsFactoryAsh::BuildJobForType(
return std::make_unique<DeviceCommandResetEuiccJob>();
case RemoteCommand::FETCH_CRD_AVAILABILITY_INFO:
return std::make_unique<DeviceCommandFetchCrdAvailabilityInfoJob>();
case RemoteCommand::FETCH_SUPPORT_PACKET:
return std::make_unique<DeviceCommandFetchSupportPacketJob>();

case RemoteCommand::COMMAND_ECHO_TEST:
case RemoteCommand::USER_ARC_COMMAND:
Expand Down
1 change: 1 addition & 0 deletions components/policy/core/common/cloud/enterprise_metrics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const char kMetricUserRemoteCommandReceived[] =
// Enterprise.UserRemoteCommand.Executed.DeviceResetEuicc
// Enterprise.UserRemoteCommand.Executed.BrowserRotateAttestationCredential
// Enterprise.UserRemoteCommand.Executed.FetchCrdAvailabilityInfo
// Enterprise.UserRemoteCommand.Executed.FetchSupportPacket
const char kMetricUserRemoteCommandExecutedTemplate[] =
"Enterprise.UserRemoteCommand.Executed.%s";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ std::string ToString(enterprise_management::RemoteCommand::Type type) {
CASE(DEVICE_RESET_EUICC);
CASE(BROWSER_ROTATE_ATTESTATION_CREDENTIAL);
CASE(FETCH_CRD_AVAILABILITY_INFO);
CASE(FETCH_SUPPORT_PACKET);
}
return base::StringPrintf("Unknown type %i", type);
#undef CASE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ RemoteCommandsService::MetricReceivedRemoteCommand RemoteCommandMetricFromType(
return Metric::kBrowserRotateAttestationCredential;
case em::RemoteCommand_Type_FETCH_CRD_AVAILABILITY_INFO:
return Metric::kFetchCrdAvailabilityInfo;
case em::RemoteCommand_Type_FETCH_SUPPORT_PACKET:
return Metric::kFetchSupportPacket;
}

// None of possible types matched. May indicate that there is new unhandled
Expand Down Expand Up @@ -112,6 +114,8 @@ const char* RemoteCommandTypeToString(em::RemoteCommand_Type type) {
return "BrowserRotateAttestationCredential";
case em::RemoteCommand_Type_FETCH_CRD_AVAILABILITY_INFO:
return "FetchCrdAvailabilityInfo";
case em::RemoteCommand_Type_FETCH_SUPPORT_PACKET:
return "FetchSupportPacket";
}

NOTREACHED() << "Unknown command type: " << type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ class POLICY_EXPORT RemoteCommandsService
kDeviceResetEuicc = 19,
kBrowserRotateAttestationCredential = 20,
kFetchCrdAvailabilityInfo = 21,
kFetchSupportPacket = 22,
// Used by UMA histograms. Shall refer to the last enumeration.
kMaxValue = kFetchCrdAvailabilityInfo
kMaxValue = kFetchSupportPacket
};

// Signature type that will be used for the requests.
Expand Down
3 changes: 3 additions & 0 deletions components/policy/proto/device_management_backend.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2810,6 +2810,9 @@ message RemoteCommand {
// Fetch information that determines the availability of CRD on the device.
FETCH_CRD_AVAILABILITY_INFO = 15;

// Fetch the logs from the Support Tool on managed ChromeOS devices.
FETCH_SUPPORT_PACKET = 16;

// Please update metrics after adding a new item - see the comment above.
}

Expand Down
1 change: 1 addition & 0 deletions tools/metrics/histograms/enums.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88817,6 +88817,7 @@ https://www.dmtf.org/sites/default/files/standards/documents/DSP0134_2.7.1.pdf
<int value="18" label="Clear the cache and cookies command"/>
<int value="19" label="Resets the cellular EUICC command"/>
<int value="20" label="Rotate attestation credentials command"/>
<int value="21" label="Fetch support packet command"/>
</enum>

<enum name="RemoteHungProcessTerminateReason">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ chromium-metrics-reviews@google.com.
<variant name=".DeviceWipeUsers" summary="Wipe users"/>
<variant name=".FetchCrdAvailabilityInfo"
summary="Fetch CRD availability info"/>
<variant name=".FetchSupportPacket" summary="Fetch support packet"/>
<variant name=".UserArcCommand" summary="ARC command"/>
</variants>

Expand Down

0 comments on commit 2c946a4

Please sign in to comment.