OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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/policy_status_info.h" |
| 6 |
| 7 #include <algorithm> |
| 8 |
| 9 #include "base/utf_string_conversions.h" |
| 10 |
| 11 namespace policy { |
| 12 |
| 13 // PolicyStatusInfo |
| 14 PolicyStatusInfo::PolicyStatusInfo() { |
| 15 } |
| 16 |
| 17 PolicyStatusInfo::PolicyStatusInfo(const PolicyStatusInfo& rhs) |
| 18 : name(rhs.name), |
| 19 source_type(rhs.source_type), |
| 20 level(rhs.level), |
| 21 status(rhs.status), |
| 22 error_message(rhs.error_message) { |
| 23 if (rhs.value.get()) |
| 24 value.reset(rhs.value->DeepCopy()); |
| 25 else |
| 26 value.reset(NULL); |
| 27 } |
| 28 |
| 29 PolicyStatusInfo::PolicyStatusInfo( |
| 30 string16 name, |
| 31 PolicySourceType source_type, |
| 32 PolicyLevel level, |
| 33 Value* value, |
| 34 PolicyStatus status, |
| 35 string16 error_message) |
| 36 : name(name), |
| 37 source_type(source_type), |
| 38 level(level), |
| 39 value(value), |
| 40 status(status), |
| 41 error_message(error_message) { |
| 42 } |
| 43 |
| 44 PolicyStatusInfo::~PolicyStatusInfo() { |
| 45 } |
| 46 |
| 47 PolicyStatusInfo& PolicyStatusInfo::operator=(const PolicyStatusInfo& rhs) { |
| 48 name = rhs.name; |
| 49 source_type = rhs.source_type; |
| 50 level = rhs.level; |
| 51 status = rhs.status; |
| 52 error_message = rhs.error_message; |
| 53 if (rhs.value.get()) |
| 54 value.reset(rhs.value->DeepCopy()); |
| 55 else |
| 56 value.reset(NULL); |
| 57 return *this; |
| 58 } |
| 59 |
| 60 DictionaryValue* PolicyStatusInfo::GetDictionaryValue() const { |
| 61 string16 level_string = getPolicyLevelString(level); |
| 62 string16 source_type_string = getSourceTypeString(source_type); |
| 63 string16 status_message = status == ENFORCED ? ASCIIToUTF16("ok") |
| 64 : error_message; |
| 65 DictionaryValue* result = new DictionaryValue(); |
| 66 result->SetString("name", name); |
| 67 result->SetString("level", level_string); |
| 68 result->SetString("source_type", source_type_string); |
| 69 result->Set("value", value->DeepCopy()); |
| 70 result->SetBoolean("set", level != LEVEL_UNDEFINED); |
| 71 result->SetString("status", status_message); |
| 72 |
| 73 return result; |
| 74 } |
| 75 |
| 76 bool PolicyStatusInfo::Equals(const PolicyStatusInfo* other_info) const { |
| 77 return name == other_info->name && |
| 78 source_type == other_info->source_type && |
| 79 level == other_info->level && |
| 80 value->Equals(other_info->value.get()) && |
| 81 status == other_info->status && |
| 82 error_message == other_info->error_message; |
| 83 } |
| 84 |
| 85 // static |
| 86 string16 PolicyStatusInfo::getSourceTypeString(PolicySourceType source_type) { |
| 87 static string16 strings[] = { ASCIIToUTF16("user"), |
| 88 ASCIIToUTF16("device"), |
| 89 ASCIIToUTF16("undefined") }; |
| 90 return strings[source_type]; |
| 91 } |
| 92 |
| 93 // static |
| 94 string16 PolicyStatusInfo::getPolicyLevelString(PolicyLevel level) { |
| 95 static string16 strings[] = { ASCIIToUTF16("mandatory"), |
| 96 ASCIIToUTF16("recommended"), |
| 97 ASCIIToUTF16("undefined") }; |
| 98 return strings[level]; |
| 99 } |
| 100 |
| 101 } // namespace policy |
OLD | NEW |