• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "components/policy/core/browser/cloud/message_util.h"
6 
7 #include "base/logging.h"
8 #include "grit/component_strings.h"
9 #include "ui/base/l10n/l10n_util.h"
10 
11 namespace policy {
12 
13 namespace {
14 
GetIDSForDMStatus(DeviceManagementStatus status)15 int GetIDSForDMStatus(DeviceManagementStatus status) {
16   switch (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_POLICY_NOT_FOUND:
46       return IDS_POLICY_DM_STATUS_SERVICE_POLICY_NOT_FOUND;
47   }
48   NOTREACHED() << "Unhandled DM status " << status;
49   return IDS_POLICY_DM_STATUS_UNKNOWN_ERROR;
50 }
51 
GetIDSForValidationStatus(CloudPolicyValidatorBase::Status status)52 int GetIDSForValidationStatus(CloudPolicyValidatorBase::Status status) {
53   switch (status) {
54     case CloudPolicyValidatorBase::VALIDATION_OK:
55       return IDS_POLICY_VALIDATION_OK;
56     case CloudPolicyValidatorBase::VALIDATION_BAD_INITIAL_SIGNATURE:
57       return IDS_POLICY_VALIDATION_BAD_INITIAL_SIGNATURE;
58     case CloudPolicyValidatorBase::VALIDATION_BAD_SIGNATURE:
59       return IDS_POLICY_VALIDATION_BAD_SIGNATURE;
60     case CloudPolicyValidatorBase::VALIDATION_ERROR_CODE_PRESENT:
61       return IDS_POLICY_VALIDATION_ERROR_CODE_PRESENT;
62     case CloudPolicyValidatorBase::VALIDATION_PAYLOAD_PARSE_ERROR:
63       return IDS_POLICY_VALIDATION_PAYLOAD_PARSE_ERROR;
64     case CloudPolicyValidatorBase::VALIDATION_WRONG_POLICY_TYPE:
65       return IDS_POLICY_VALIDATION_WRONG_POLICY_TYPE;
66     case CloudPolicyValidatorBase::VALIDATION_WRONG_SETTINGS_ENTITY_ID:
67       return IDS_POLICY_VALIDATION_WRONG_SETTINGS_ENTITY_ID;
68     case CloudPolicyValidatorBase::VALIDATION_BAD_TIMESTAMP:
69       return IDS_POLICY_VALIDATION_BAD_TIMESTAMP;
70     case CloudPolicyValidatorBase::VALIDATION_WRONG_TOKEN:
71       return IDS_POLICY_VALIDATION_WRONG_TOKEN;
72     case CloudPolicyValidatorBase::VALIDATION_BAD_USERNAME:
73       return IDS_POLICY_VALIDATION_BAD_USERNAME;
74     case CloudPolicyValidatorBase::VALIDATION_POLICY_PARSE_ERROR:
75       return IDS_POLICY_VALIDATION_POLICY_PARSE_ERROR;
76   }
77   NOTREACHED() << "Unhandled validation status " << status;
78   return IDS_POLICY_VALIDATION_UNKNOWN_ERROR;
79 }
80 
GetIDSForStoreStatus(CloudPolicyStore::Status status)81 int GetIDSForStoreStatus(CloudPolicyStore::Status status) {
82   switch (status) {
83     case CloudPolicyStore::STATUS_OK:
84       return IDS_POLICY_STORE_STATUS_OK;
85     case CloudPolicyStore::STATUS_LOAD_ERROR:
86       return IDS_POLICY_STORE_STATUS_LOAD_ERROR;
87     case CloudPolicyStore::STATUS_STORE_ERROR:
88       return IDS_POLICY_STORE_STATUS_STORE_ERROR;
89     case CloudPolicyStore::STATUS_PARSE_ERROR:
90       return IDS_POLICY_STORE_STATUS_PARSE_ERROR;
91     case CloudPolicyStore::STATUS_SERIALIZE_ERROR:
92       return IDS_POLICY_STORE_STATUS_SERIALIZE_ERROR;
93     case CloudPolicyStore::STATUS_VALIDATION_ERROR:
94       // This is handled separately below to include the validation error.
95       break;
96     case CloudPolicyStore::STATUS_BAD_STATE:
97       return IDS_POLICY_STORE_STATUS_BAD_STATE;
98   }
99   NOTREACHED() << "Unhandled store status " << status;
100   return IDS_POLICY_STORE_STATUS_UNKNOWN_ERROR;
101 }
102 
103 }  // namespace
104 
FormatDeviceManagementStatus(DeviceManagementStatus status)105 string16 FormatDeviceManagementStatus(DeviceManagementStatus status) {
106   return l10n_util::GetStringUTF16(GetIDSForDMStatus(status));
107 }
108 
FormatValidationStatus(CloudPolicyValidatorBase::Status validation_status)109 string16 FormatValidationStatus(
110     CloudPolicyValidatorBase::Status validation_status) {
111   return l10n_util::GetStringUTF16(
112       GetIDSForValidationStatus(validation_status));
113 }
114 
FormatStoreStatus(CloudPolicyStore::Status store_status,CloudPolicyValidatorBase::Status validation_status)115 string16 FormatStoreStatus(CloudPolicyStore::Status store_status,
116                            CloudPolicyValidatorBase::Status validation_status) {
117   if (store_status == CloudPolicyStore::STATUS_VALIDATION_ERROR) {
118     return l10n_util::GetStringFUTF16(
119         IDS_POLICY_STORE_STATUS_VALIDATION_ERROR,
120         l10n_util::GetStringUTF16(
121             GetIDSForValidationStatus(validation_status)));
122   }
123 
124   return l10n_util::GetStringUTF16(GetIDSForStoreStatus(store_status));
125 }
126 
127 }  // namespace policy
128