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