Chromium Code Reviews| 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_map.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( | |
| 18 string16 name, | |
| 19 PolicySourceType source_type, | |
| 20 PolicyLevel level, | |
| 21 Value* value, | |
| 22 PolicyStatus status, | |
| 23 string16 error_message) : name(name), | |
|
Mattias Nissler (ping if slow)
2011/08/09 13:20:40
line break before :
simo
2011/08/10 14:28:19
Done.
| |
| 24 source_type(source_type), | |
| 25 level(level), | |
| 26 value(value), | |
| 27 status(status), | |
| 28 error_message(error_message) { | |
| 29 } | |
| 30 | |
| 31 PolicyStatusInfo::~PolicyStatusInfo() { | |
| 32 } | |
| 33 | |
| 34 DictionaryValue* PolicyStatusInfo::GetDictionaryValue() const { | |
| 35 string16 level_string = getPolicyLevelString(level); | |
| 36 string16 source_type_string = getSourceTypeString(source_type); | |
| 37 string16 status_message = status == ENFORCED ? ASCIIToUTF16("ok") | |
| 38 : error_message; | |
| 39 DictionaryValue* result = new DictionaryValue(); | |
| 40 result->SetString("name", name); | |
| 41 result->SetString("level", level_string); | |
| 42 result->SetString("source_type", source_type_string); | |
| 43 result->Set("value", value.get()->DeepCopy()); | |
| 44 result->SetBoolean("set", level != LEVEL_UNDEFINED); | |
| 45 result->SetString("status", status_message); | |
| 46 | |
| 47 return result; | |
| 48 } | |
| 49 | |
| 50 bool PolicyStatusInfo::Equals(const PolicyStatusInfo* other_info) const { | |
| 51 return name == other_info->name && | |
| 52 source_type == other_info->source_type && | |
| 53 level == other_info->level && | |
| 54 value.get()->Equals(other_info->value.get()) && | |
|
Mattias Nissler (ping if slow)
2011/08/09 13:20:40
don't need the .get(), scoped_ptr has an operator-
simo
2011/08/10 14:28:19
Done.
| |
| 55 status == other_info->status && | |
| 56 error_message == other_info->error_message; | |
| 57 } | |
| 58 | |
| 59 PolicyStatusInfo* PolicyStatusInfo::DeepCopy() const { | |
| 60 PolicyStatusInfo* info = new PolicyStatusInfo(name, | |
| 61 source_type, | |
| 62 level, | |
| 63 value.get()->DeepCopy(), | |
| 64 status, | |
| 65 error_message); | |
| 66 return info; | |
| 67 } | |
| 68 | |
| 69 // static | |
| 70 string16 PolicyStatusInfo::getSourceTypeString(PolicySourceType source_type) { | |
| 71 static string16 strings[] = { ASCIIToUTF16("user"), | |
| 72 ASCIIToUTF16("device"), | |
| 73 ASCIIToUTF16("undefined")}; | |
| 74 return strings[source_type]; | |
| 75 } | |
| 76 | |
| 77 // static | |
| 78 string16 PolicyStatusInfo::getPolicyLevelString(PolicyLevel level) { | |
| 79 static string16 strings[] = { ASCIIToUTF16("mandatory"), | |
| 80 ASCIIToUTF16("recommended"), | |
| 81 ASCIIToUTF16("undefined")}; | |
| 82 return strings[level]; | |
| 83 } | |
| 84 | |
|
Mattias Nissler (ping if slow)
2011/08/09 13:20:40
only one newline
simo
2011/08/10 14:28:19
Done.
| |
| 85 | |
| 86 // PolicyStatusMap | |
| 87 PolicyStatusMap::PolicyStatusMap() { | |
| 88 } | |
| 89 | |
| 90 PolicyStatusMap::~PolicyStatusMap() { | |
| 91 } | |
| 92 | |
| 93 const PolicyStatusInfo* PolicyStatusMap::Get( | |
| 94 ConfigurationPolicyType policy) const { | |
| 95 const_iterator entry = map_.find(policy); | |
| 96 return entry != map_.end() ? entry->second : NULL; | |
| 97 } | |
| 98 | |
| 99 void PolicyStatusMap::Set(ConfigurationPolicyType policy, | |
| 100 PolicyStatusInfo* info) { | |
| 101 std::swap(map_[policy], info); | |
| 102 delete info; | |
| 103 } | |
| 104 | |
| 105 bool PolicyStatusMap::empty() const { | |
| 106 return map_.empty(); | |
| 107 } | |
| 108 | |
| 109 size_t PolicyStatusMap::size() const { | |
| 110 return map_.size(); | |
| 111 } | |
| 112 | |
| 113 PolicyStatusMap::const_iterator PolicyStatusMap::begin() const { | |
| 114 return map_.begin(); | |
| 115 } | |
| 116 | |
| 117 PolicyStatusMap::const_iterator PolicyStatusMap::end() const { | |
| 118 return map_.end(); | |
| 119 } | |
| 120 | |
| 121 void PolicyStatusMap::Clear() { | |
| 122 for (PolicyStatusMapType::iterator i = map_.begin(); i != map_.end(); ++i) | |
| 123 delete i->second; | |
| 124 map_.clear(); | |
| 125 } | |
| 126 | |
| 127 } // policy | |
|
Mattias Nissler (ping if slow)
2011/08/09 13:20:40
namespace policy
simo
2011/08/10 14:28:19
Done.
| |
| OLD | NEW |