esim_mojo_utils.cc 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ash/services/cellular_setup/esim_mojo_utils.h"
  5. #include "ash/services/cellular_setup/public/mojom/esim_manager.mojom.h"
  6. namespace ash::cellular_setup {
  7. mojom::ProfileInstallResult InstallResultFromStatus(
  8. HermesResponseStatus status) {
  9. switch (status) {
  10. case HermesResponseStatus::kSuccess:
  11. return mojom::ProfileInstallResult::kSuccess;
  12. case HermesResponseStatus::kErrorNeedConfirmationCode:
  13. return mojom::ProfileInstallResult::kErrorNeedsConfirmationCode;
  14. case HermesResponseStatus::kErrorInvalidActivationCode:
  15. return mojom::ProfileInstallResult::kErrorInvalidActivationCode;
  16. default:
  17. // Treat all other status codes as installation failure.
  18. return mojom::ProfileInstallResult::kFailure;
  19. }
  20. }
  21. mojom::ProfileState ProfileStateToMojo(CellularESimProfile::State state) {
  22. switch (state) {
  23. case CellularESimProfile::State::kActive:
  24. return mojom::ProfileState::kActive;
  25. case CellularESimProfile::State::kInactive:
  26. return mojom::ProfileState::kInactive;
  27. case CellularESimProfile::State::kPending:
  28. return mojom::ProfileState::kPending;
  29. case CellularESimProfile::State::kInstalling:
  30. return mojom::ProfileState::kInstalling;
  31. }
  32. NOTREACHED() << "Cannot convert invalid profile state "
  33. << static_cast<int>(state);
  34. return mojom::ProfileState::kPending;
  35. }
  36. mojom::ESimOperationResult OperationResultFromStatus(
  37. HermesResponseStatus status) {
  38. switch (status) {
  39. case HermesResponseStatus::kSuccess:
  40. return mojom::ESimOperationResult::kSuccess;
  41. default:
  42. // Treat all other status codes as operation failure.
  43. return mojom::ESimOperationResult::kFailure;
  44. }
  45. }
  46. } // namespace ash::cellular_setup