#include "chrome/browser/device_api/device_attribute_api.h"
#include "base/functional/callback.h"
#include "build/chromeos_buildflags.h"
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include <optional>
#include <string_view>
#include "chrome/browser/ash/policy/core/browser_policy_connector_ash.h"
#include "chrome/browser/ash/policy/handlers/device_name_policy_handler.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_process_platform_part.h"
#include "chromeos/ash/components/system/statistics_provider.h"
#elif BUILDFLAG(IS_CHROMEOS_LACROS)
#include <optional>
#include "chromeos/lacros/lacros_service.h"
#endif
DeviceAPIService;
DeviceAttributeResultPtr;
namespace {
Result;
constexpr char kNotAffiliatedErrorMessage[] = …;
constexpr char kNotAllowedOriginErrorMessage[] = …;
#if !BUILDFLAG(IS_CHROMEOS)
const char kNotSupportedPlatformErrorMessage[] = …;
#endif
#if BUILDFLAG(IS_CHROMEOS_LACROS)
void AdaptLacrosResult(
DeviceAPIService::GetDirectoryIdCallback callback,
crosapi::mojom::DeviceAttributesStringResultPtr lacros_result) {
if (lacros_result->is_error_message()) {
std::move(callback).Run(
Result::NewErrorMessage(lacros_result->get_error_message()));
} else if (lacros_result->get_contents().empty()) {
std::move(callback).Run(Result::NewAttribute(std::optional<std::string>()));
} else {
std::move(callback).Run(
Result::NewAttribute(lacros_result->get_contents()));
}
}
#endif
}
DeviceAttributeApiImpl::DeviceAttributeApiImpl() = default;
DeviceAttributeApiImpl::~DeviceAttributeApiImpl() = default;
void DeviceAttributeApiImpl::ReportNotAffiliatedError(
base::OnceCallback<void(DeviceAttributeResultPtr)> callback) { … }
void DeviceAttributeApiImpl::ReportNotAllowedError(
base::OnceCallback<void(DeviceAttributeResultPtr)> callback) { … }
void DeviceAttributeApiImpl::GetDirectoryId(
DeviceAPIService::GetDirectoryIdCallback callback) { … }
void DeviceAttributeApiImpl::GetHostname(
DeviceAPIService::GetHostnameCallback callback) { … }
void DeviceAttributeApiImpl::GetSerialNumber(
DeviceAPIService::GetSerialNumberCallback callback) { … }
void DeviceAttributeApiImpl::GetAnnotatedAssetId(
DeviceAPIService::GetAnnotatedAssetIdCallback callback) { … }
void DeviceAttributeApiImpl::GetAnnotatedLocation(
DeviceAPIService::GetAnnotatedLocationCallback callback) { … }