1 // Copyright (c) 2012 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.
5 #include "components/policy/core/browser/cloud/message_util.h"
7 #include "base/logging.h"
8 #include "grit/components_strings.h"
9 #include "ui/base/l10n/l10n_util.h"
15 int GetIDSForDMStatus(DeviceManagementStatus status
) {
17 case DM_STATUS_SUCCESS
:
18 return IDS_POLICY_DM_STATUS_SUCCESS
;
19 case DM_STATUS_REQUEST_INVALID
:
20 return IDS_POLICY_DM_STATUS_REQUEST_INVALID
;
21 case DM_STATUS_REQUEST_FAILED
:
22 return IDS_POLICY_DM_STATUS_REQUEST_FAILED
;
23 case DM_STATUS_TEMPORARY_UNAVAILABLE
:
24 return IDS_POLICY_DM_STATUS_TEMPORARY_UNAVAILABLE
;
25 case DM_STATUS_HTTP_STATUS_ERROR
:
26 return IDS_POLICY_DM_STATUS_HTTP_STATUS_ERROR
;
27 case DM_STATUS_RESPONSE_DECODING_ERROR
:
28 return IDS_POLICY_DM_STATUS_RESPONSE_DECODING_ERROR
;
29 case DM_STATUS_SERVICE_MANAGEMENT_NOT_SUPPORTED
:
30 return IDS_POLICY_DM_STATUS_SERVICE_MANAGEMENT_NOT_SUPPORTED
;
31 case DM_STATUS_SERVICE_DEVICE_NOT_FOUND
:
32 return IDS_POLICY_DM_STATUS_SERVICE_DEVICE_NOT_FOUND
;
33 case DM_STATUS_SERVICE_MANAGEMENT_TOKEN_INVALID
:
34 return IDS_POLICY_DM_STATUS_SERVICE_MANAGEMENT_TOKEN_INVALID
;
35 case DM_STATUS_SERVICE_ACTIVATION_PENDING
:
36 return IDS_POLICY_DM_STATUS_SERVICE_ACTIVATION_PENDING
;
37 case DM_STATUS_SERVICE_INVALID_SERIAL_NUMBER
:
38 return IDS_POLICY_DM_STATUS_SERVICE_INVALID_SERIAL_NUMBER
;
39 case DM_STATUS_SERVICE_DEVICE_ID_CONFLICT
:
40 return IDS_POLICY_DM_STATUS_SERVICE_DEVICE_ID_CONFLICT
;
41 case DM_STATUS_SERVICE_MISSING_LICENSES
:
42 return IDS_POLICY_DM_STATUS_SERVICE_MISSING_LICENSES
;
43 case DM_STATUS_SERVICE_DEPROVISIONED
:
44 return IDS_POLICY_DM_STATUS_SERVICE_DEPROVISIONED
;
45 case DM_STATUS_SERVICE_DOMAIN_MISMATCH
:
46 return IDS_POLICY_DM_STATUS_SERVICE_DOMAIN_MISMATCH
;
47 case DM_STATUS_SERVICE_POLICY_NOT_FOUND
:
48 return IDS_POLICY_DM_STATUS_SERVICE_POLICY_NOT_FOUND
;
50 NOTREACHED() << "Unhandled DM status " << status
;
51 return IDS_POLICY_DM_STATUS_UNKNOWN_ERROR
;
54 int GetIDSForValidationStatus(CloudPolicyValidatorBase::Status status
) {
56 case CloudPolicyValidatorBase::VALIDATION_OK
:
57 return IDS_POLICY_VALIDATION_OK
;
58 case CloudPolicyValidatorBase::VALIDATION_BAD_INITIAL_SIGNATURE
:
59 return IDS_POLICY_VALIDATION_BAD_INITIAL_SIGNATURE
;
60 case CloudPolicyValidatorBase::VALIDATION_BAD_SIGNATURE
:
61 return IDS_POLICY_VALIDATION_BAD_SIGNATURE
;
62 case CloudPolicyValidatorBase::VALIDATION_ERROR_CODE_PRESENT
:
63 return IDS_POLICY_VALIDATION_ERROR_CODE_PRESENT
;
64 case CloudPolicyValidatorBase::VALIDATION_PAYLOAD_PARSE_ERROR
:
65 return IDS_POLICY_VALIDATION_PAYLOAD_PARSE_ERROR
;
66 case CloudPolicyValidatorBase::VALIDATION_WRONG_POLICY_TYPE
:
67 return IDS_POLICY_VALIDATION_WRONG_POLICY_TYPE
;
68 case CloudPolicyValidatorBase::VALIDATION_WRONG_SETTINGS_ENTITY_ID
:
69 return IDS_POLICY_VALIDATION_WRONG_SETTINGS_ENTITY_ID
;
70 case CloudPolicyValidatorBase::VALIDATION_BAD_TIMESTAMP
:
71 return IDS_POLICY_VALIDATION_BAD_TIMESTAMP
;
72 case CloudPolicyValidatorBase::VALIDATION_WRONG_TOKEN
:
73 return IDS_POLICY_VALIDATION_WRONG_TOKEN
;
74 case CloudPolicyValidatorBase::VALIDATION_BAD_USERNAME
:
75 return IDS_POLICY_VALIDATION_BAD_USERNAME
;
76 case CloudPolicyValidatorBase::VALIDATION_POLICY_PARSE_ERROR
:
77 return IDS_POLICY_VALIDATION_POLICY_PARSE_ERROR
;
78 case CloudPolicyValidatorBase::VALIDATION_BAD_KEY_VERIFICATION_SIGNATURE
:
79 return IDS_POLICY_VALIDATION_BAD_KEY_VERIFICATION_SIGNATURE
;
80 case CloudPolicyValidatorBase::VALIDATION_STATUS_SIZE
:
83 NOTREACHED() << "Unhandled validation status " << status
;
84 return IDS_POLICY_VALIDATION_UNKNOWN_ERROR
;
87 int GetIDSForStoreStatus(CloudPolicyStore::Status status
) {
89 case CloudPolicyStore::STATUS_OK
:
90 return IDS_POLICY_STORE_STATUS_OK
;
91 case CloudPolicyStore::STATUS_LOAD_ERROR
:
92 return IDS_POLICY_STORE_STATUS_LOAD_ERROR
;
93 case CloudPolicyStore::STATUS_STORE_ERROR
:
94 return IDS_POLICY_STORE_STATUS_STORE_ERROR
;
95 case CloudPolicyStore::STATUS_PARSE_ERROR
:
96 return IDS_POLICY_STORE_STATUS_PARSE_ERROR
;
97 case CloudPolicyStore::STATUS_SERIALIZE_ERROR
:
98 return IDS_POLICY_STORE_STATUS_SERIALIZE_ERROR
;
99 case CloudPolicyStore::STATUS_VALIDATION_ERROR
:
100 // This is handled separately below to include the validation error.
102 case CloudPolicyStore::STATUS_BAD_STATE
:
103 return IDS_POLICY_STORE_STATUS_BAD_STATE
;
105 NOTREACHED() << "Unhandled store status " << status
;
106 return IDS_POLICY_STORE_STATUS_UNKNOWN_ERROR
;
111 base::string16
FormatDeviceManagementStatus(DeviceManagementStatus status
) {
112 return l10n_util::GetStringUTF16(GetIDSForDMStatus(status
));
115 base::string16
FormatValidationStatus(
116 CloudPolicyValidatorBase::Status validation_status
) {
117 return l10n_util::GetStringUTF16(
118 GetIDSForValidationStatus(validation_status
));
121 base::string16
FormatStoreStatus(
122 CloudPolicyStore::Status store_status
,
123 CloudPolicyValidatorBase::Status validation_status
) {
124 if (store_status
== CloudPolicyStore::STATUS_VALIDATION_ERROR
) {
125 return l10n_util::GetStringFUTF16(
126 IDS_POLICY_STORE_STATUS_VALIDATION_ERROR
,
127 l10n_util::GetStringUTF16(
128 GetIDSForValidationStatus(validation_status
)));
131 return l10n_util::GetStringUTF16(GetIDSForStoreStatus(store_status
));
134 } // namespace policy