1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
// 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_ENROLLMENT_AUTO_ENROLLMENT_STATE_H_
#define CHROME_BROWSER_ASH_POLICY_ENROLLMENT_AUTO_ENROLLMENT_STATE_H_
#include <optional>
#include <string_view>
#include <variant>
#include "base/types/expected.h"
#include "components/policy/core/common/cloud/cloud_policy_constants.h"
namespace policy {
struct DMServerJobResult;
// Indicates the result of state determination.
enum class AutoEnrollmentResult {
// Check completed successfully, enrollment should be triggered.
kEnrollment,
// Check completed successfully, enrollment not applicable.
kNoEnrollment,
// Check completed successfully, device is disabled.
kDisabled,
// Check completed successfully, enrollment is suggested but not enforced.
kSuggestedEnrollment,
};
// Represents a state determination error due to a timeout.
struct AutoEnrollmentSafeguardTimeoutError {
constexpr bool operator==(const AutoEnrollmentSafeguardTimeoutError&) const =
default;
};
// Represents an error while retrieving state keys.
struct AutoEnrollmentStateKeysRetrievalError {
constexpr bool operator==(
const AutoEnrollmentStateKeysRetrievalError&) const = default;
};
// Represents an error during state determination request to DMServer. May
// be caused by connection error, server error, or invalid request.
struct AutoEnrollmentDMServerError {
static AutoEnrollmentDMServerError FromDMServerJobResult(
const DMServerJobResult& result);
constexpr bool operator==(const AutoEnrollmentDMServerError&) const = default;
DeviceManagementStatus dm_error;
std::optional<int> network_error;
};
// Represents an error due to an invalid response from DMServer.
struct AutoEnrollmentStateAvailabilityResponseError {
constexpr bool operator==(
const AutoEnrollmentStateAvailabilityResponseError&) const = default;
};
// Represents an internal error in PSM library during initial state
// determination.
struct AutoEnrollmentPsmError {
constexpr bool operator==(const AutoEnrollmentPsmError&) const = default;
};
// Represents an error due to an invalid response from DMServer.
struct AutoEnrollmentStateRetrievalResponseError {
constexpr bool operator==(
const AutoEnrollmentStateRetrievalResponseError&) const = default;
};
using AutoEnrollmentError =
std::variant<AutoEnrollmentSafeguardTimeoutError,
AutoEnrollmentStateKeysRetrievalError,
AutoEnrollmentDMServerError,
AutoEnrollmentStateAvailabilityResponseError,
AutoEnrollmentPsmError,
AutoEnrollmentStateRetrievalResponseError>;
// Indicates the current state of the auto-enrollment check.
using AutoEnrollmentState =
base::expected<AutoEnrollmentResult, AutoEnrollmentError>;
std::string AutoEnrollmentStateToString(const AutoEnrollmentState& state);
} // namespace policy
#endif // CHROME_BROWSER_ASH_POLICY_ENROLLMENT_AUTO_ENROLLMENT_STATE_H_
|