Skip to content

Commit

Permalink
Files app: Use cros_disks enums
Browse files Browse the repository at this point in the history
This removes the duplicated definitions of several enums: DeviceType,
MountError, FormatError, PartitionError, RenameError.

BUG=b:255702808

Change-Id: Ib884f0c968bceceda28c1e64840366190c0c122c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3995242
Commit-Queue: François Degros <fdegros@chromium.org>
Reviewed-by: Marcello Salomao <msalomao@google.com>
Cr-Commit-Position: refs/heads/main@{#1067423}
  • Loading branch information
fdegros authored and Chromium LUCI CQ committed Nov 4, 2022
1 parent 054b260 commit 749cb9d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 243 deletions.
150 changes: 19 additions & 131 deletions chromeos/ash/components/dbus/cros_disks/cros_disks_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -564,147 +564,35 @@ class CrosDisksClientImpl : public CrosDisksClient {

std::ostream& operator<<(std::ostream& out, const MountType type) {
switch (type) {
#define PRINT_TYPE(s) \
case MountType::s: \
#define PRINT(s) \
case MountType::k##s: \
return out << #s;
PRINT_TYPE(kInvalid)
PRINT_TYPE(kDevice)
PRINT_TYPE(kArchive)
PRINT_TYPE(kNetworkStorage)
#undef PRINT_TYPE
PRINT(Invalid)
PRINT(Device)
PRINT(Archive)
PRINT(NetworkStorage)
#undef PRINT
}

return out << std::underlying_type_t<MountType>(type);
}

std::ostream& operator<<(std::ostream& out, const DeviceType type) {
switch (type) {
#define PRINT_TYPE(s) \
case DeviceType::s: \
return out << #s;
PRINT_TYPE(kUnknown)
PRINT_TYPE(kUSB)
PRINT_TYPE(kSD)
PRINT_TYPE(kOpticalDisc)
PRINT_TYPE(kMobile)
PRINT_TYPE(kDVD)
#undef PRINT_TYPE
}

return out << std::underlying_type_t<DeviceType>(type);
}

std::ostream& operator<<(std::ostream& out, const MountError error) {
switch (error) {
#define PRINT_ERROR(s) \
case MountError::s: \
return out << #s;
PRINT_ERROR(kSuccess)
PRINT_ERROR(kUnknownError)
PRINT_ERROR(kInternalError)
PRINT_ERROR(kInvalidArgument)
PRINT_ERROR(kInvalidPath)
PRINT_ERROR(kPathAlreadyMounted)
PRINT_ERROR(kPathNotMounted)
PRINT_ERROR(kDirectoryCreationFailed)
PRINT_ERROR(kInvalidMountOptions)
PRINT_ERROR(kInvalidUnmountOptions)
PRINT_ERROR(kInsufficientPermissions)
PRINT_ERROR(kMountProgramNotFound)
PRINT_ERROR(kMountProgramFailed)
PRINT_ERROR(kInvalidDevicePath)
PRINT_ERROR(kUnknownFilesystem)
PRINT_ERROR(kUnsupportedFilesystem)
PRINT_ERROR(kInvalidArchive)
PRINT_ERROR(kNeedPassword)
PRINT_ERROR(kInProgress)
PRINT_ERROR(kCancelled)
PRINT_ERROR(kBusy)
#undef PRINT_ERROR
}

return out << std::underlying_type_t<MountError>(error);
}

std::ostream& operator<<(std::ostream& out, const RenameError error) {
switch (error) {
#define PRINT_ERROR(s) \
case RenameError::s: \
return out << #s;
PRINT_ERROR(kSuccess)
PRINT_ERROR(kUnknownError)
PRINT_ERROR(kInternalError)
PRINT_ERROR(kInvalidDevicePath)
PRINT_ERROR(kDeviceBeingRenamed)
PRINT_ERROR(kUnsupportedFilesystem)
PRINT_ERROR(kRenameProgramNotFound)
PRINT_ERROR(kRenameProgramFailed)
PRINT_ERROR(kDeviceNotAllowed)
PRINT_ERROR(kLongName)
PRINT_ERROR(kInvalidCharacter)
#undef PRINT_ERROR
}

return out << std::underlying_type_t<RenameError>(error);
}

std::ostream& operator<<(std::ostream& out, const FormatError error) {
switch (error) {
#define PRINT_ERROR(s) \
case FormatError::s: \
return out << #s;
PRINT_ERROR(kSuccess)
PRINT_ERROR(kUnknownError)
PRINT_ERROR(kInternalError)
PRINT_ERROR(kInvalidDevicePath)
PRINT_ERROR(kDeviceBeingFormatted)
PRINT_ERROR(kUnsupportedFilesystem)
PRINT_ERROR(kFormatProgramNotFound)
PRINT_ERROR(kFormatProgramFailed)
PRINT_ERROR(kDeviceNotAllowed)
PRINT_ERROR(kInvalidOptions)
PRINT_ERROR(kLongName)
PRINT_ERROR(kInvalidCharacter)
#undef PRINT_ERROR
}

return out << std::underlying_type_t<FormatError>(error);
}

std::ostream& operator<<(std::ostream& out, const PartitionError error) {
switch (error) {
#define PRINT_ERROR(s) \
case PartitionError::s: \
return out << #s;
PRINT_ERROR(kSuccess)
PRINT_ERROR(kUnknownError)
PRINT_ERROR(kInternalError)
PRINT_ERROR(kInvalidDevicePath)
PRINT_ERROR(kDeviceBeingPartitioned)
PRINT_ERROR(kProgramNotFound)
PRINT_ERROR(kProgramFailed)
PRINT_ERROR(kDeviceNotAllowed)
#undef PRINT_ERROR
}

return out << std::underlying_type_t<PartitionError>(error);
return out << "MountType(" << std::underlying_type_t<MountType>(type) << ")";
}

std::ostream& operator<<(std::ostream& out, const MountEventType event) {
switch (event) {
#define PRINT_ERROR(s) \
case MountEventType::s: \
#define PRINT(s) \
case MountEventType::k##s: \
return out << #s;
PRINT_ERROR(kDiskAdded)
PRINT_ERROR(kDiskRemoved)
PRINT_ERROR(kDiskChanged)
PRINT_ERROR(kDeviceAdded)
PRINT_ERROR(kDeviceRemoved)
PRINT_ERROR(kDeviceScanned)
#undef PRINT_ERROR
PRINT(DiskAdded)
PRINT(DiskRemoved)
PRINT(DiskChanged)
PRINT(DeviceAdded)
PRINT(DeviceRemoved)
PRINT(DeviceScanned)
#undef PRINT
}

return out << std::underlying_type_t<MountEventType>(event);
return out << "MountEventType("
<< std::underlying_type_t<MountEventType>(event) << ")";
}

std::ostream& operator<<(std::ostream& out, const MountPoint& entry) {
Expand Down
119 changes: 7 additions & 112 deletions chromeos/ash/components/dbus/cros_disks/cros_disks_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "base/strings/string_piece.h"
#include "chromeos/dbus/common/dbus_client.h"
#include "chromeos/dbus/common/dbus_method_call_status.h"
#include "third_party/cros_system_api/dbus/cros-disks/dbus-constants.h"

namespace base {
class FilePath;
Expand All @@ -27,11 +28,14 @@ namespace dbus {
class Response;
}

// TODO(crbug.com/1368408): Most of these are partially or completely duplicated
// in third_party/dbus/service_constants.h. We should probably use enums from
// service_contstants directly.
namespace ash {

using cros_disks::DeviceType;
using cros_disks::FormatError;
using cros_disks::MountError;
using cros_disks::PartitionError;
using cros_disks::RenameError;

// Enum describing types of mount used by cros-disks.
enum class MountType {
kInvalid,
Expand All @@ -44,115 +48,6 @@ enum class MountType {
COMPONENT_EXPORT(ASH_DBUS_CROS_DISKS)
std::ostream& operator<<(std::ostream& out, MountType type);

// Type of device.
// The numeric values must match cros_disks::DeviceMediaType.
enum class DeviceType {
kUnknown = 0,
kUSB = 1, // USB stick.
kSD = 2, // SD card.
kOpticalDisc = 3, // e.g. Optical disc excluding DVD.
kMobile = 4, // Storage on a mobile device (e.g. Android).
kDVD = 5, // DVD.

kMaxValue = 5,
};

// Output operator for logging.
COMPONENT_EXPORT(ASH_DBUS_CROS_DISKS)
std::ostream& operator<<(std::ostream& out, DeviceType type);

// Mount error code used by cros-disks.
//
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class MountError {
kSuccess = 0,
kUnknownError = 1,
kInternalError = 2,
kInvalidArgument = 3,
kInvalidPath = 4,
kPathAlreadyMounted = 5,
kPathNotMounted = 6,
kDirectoryCreationFailed = 7,
kInvalidMountOptions = 8,
kInvalidUnmountOptions = 9,
kInsufficientPermissions = 10,
kMountProgramNotFound = 11,
kMountProgramFailed = 12,
kInvalidDevicePath = 13,
kUnknownFilesystem = 14,
kUnsupportedFilesystem = 15,
kInvalidArchive = 16,
kNeedPassword = 17,
kInProgress = 18,
kCancelled = 19,
kBusy = 20,
kMaxValue = 20,
};

// Output operator for logging.
COMPONENT_EXPORT(ASH_DBUS_CROS_DISKS)
std::ostream& operator<<(std::ostream& out, MountError error);

// Rename error reported by cros-disks.
enum class RenameError {
kSuccess,
kUnknownError,
kInternalError,
kInvalidDevicePath,
kDeviceBeingRenamed,
kUnsupportedFilesystem,
kRenameProgramNotFound,
kRenameProgramFailed,
kDeviceNotAllowed,
kLongName,
kInvalidCharacter,
};

// Output operator for logging.
COMPONENT_EXPORT(ASH_DBUS_CROS_DISKS)
std::ostream& operator<<(std::ostream& out, RenameError error);

// Format error reported by cros-disks.
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
// See enum CrosDisksClientFormatError in tools/metrics/histograms/enums.xml.
enum class FormatError {
kSuccess = 0,
kUnknownError = 1,
kInternalError = 2,
kInvalidDevicePath = 3,
kDeviceBeingFormatted = 4,
kUnsupportedFilesystem = 5,
kFormatProgramNotFound = 6,
kFormatProgramFailed = 7,
kDeviceNotAllowed = 8,
kInvalidOptions = 9,
kLongName = 10,
kInvalidCharacter = 11,
kMaxValue = 11,
};

// Output operator for logging.
COMPONENT_EXPORT(ASH_DBUS_CROS_DISKS)
std::ostream& operator<<(std::ostream& out, FormatError error);

// Partition error reported by cros-disks.
enum class PartitionError {
kSuccess = 0,
kUnknownError = 1,
kInternalError = 2,
kInvalidDevicePath = 3,
kDeviceBeingPartitioned = 4,
kProgramNotFound = 5,
kProgramFailed = 6,
kDeviceNotAllowed = 7,
};

// Output operator for logging.
COMPONENT_EXPORT(ASH_DBUS_CROS_DISKS)
std::ostream& operator<<(std::ostream& out, PartitionError error);

// Event type each corresponding to a signal sent from cros-disks.
enum class MountEventType {
kDiskAdded,
Expand Down

0 comments on commit 749cb9d

Please sign in to comment.