Chromium Code Reviews| Index: chrome/browser/policy/policy_status_map.cc |
| diff --git a/chrome/browser/policy/policy_status_map.cc b/chrome/browser/policy/policy_status_map.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f4896b4977c43d766a3eac50012c808db39501ea |
| --- /dev/null |
| +++ b/chrome/browser/policy/policy_status_map.cc |
| @@ -0,0 +1,127 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/policy/policy_status_map.h" |
| + |
| +#include <algorithm> |
| + |
| +#include "base/utf_string_conversions.h" |
| + |
| +namespace policy { |
| + |
| +// PolicyStatusInfo |
| +PolicyStatusInfo::PolicyStatusInfo() { |
| +} |
| + |
| +PolicyStatusInfo::PolicyStatusInfo( |
| + string16 name, |
| + PolicySourceType source_type, |
| + PolicyLevel level, |
| + Value* value, |
| + PolicyStatus status, |
| + 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.
|
| + source_type(source_type), |
| + level(level), |
| + value(value), |
| + status(status), |
| + error_message(error_message) { |
| +} |
| + |
| +PolicyStatusInfo::~PolicyStatusInfo() { |
| +} |
| + |
| +DictionaryValue* PolicyStatusInfo::GetDictionaryValue() const { |
| + string16 level_string = getPolicyLevelString(level); |
| + string16 source_type_string = getSourceTypeString(source_type); |
| + string16 status_message = status == ENFORCED ? ASCIIToUTF16("ok") |
| + : error_message; |
| + DictionaryValue* result = new DictionaryValue(); |
| + result->SetString("name", name); |
| + result->SetString("level", level_string); |
| + result->SetString("source_type", source_type_string); |
| + result->Set("value", value.get()->DeepCopy()); |
| + result->SetBoolean("set", level != LEVEL_UNDEFINED); |
| + result->SetString("status", status_message); |
| + |
| + return result; |
| +} |
| + |
| +bool PolicyStatusInfo::Equals(const PolicyStatusInfo* other_info) const { |
| + return name == other_info->name && |
| + source_type == other_info->source_type && |
| + level == other_info->level && |
| + 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.
|
| + status == other_info->status && |
| + error_message == other_info->error_message; |
| +} |
| + |
| +PolicyStatusInfo* PolicyStatusInfo::DeepCopy() const { |
| + PolicyStatusInfo* info = new PolicyStatusInfo(name, |
| + source_type, |
| + level, |
| + value.get()->DeepCopy(), |
| + status, |
| + error_message); |
| + return info; |
| +} |
| + |
| +// static |
| +string16 PolicyStatusInfo::getSourceTypeString(PolicySourceType source_type) { |
| + static string16 strings[] = { ASCIIToUTF16("user"), |
| + ASCIIToUTF16("device"), |
| + ASCIIToUTF16("undefined")}; |
| + return strings[source_type]; |
| +} |
| + |
| +// static |
| +string16 PolicyStatusInfo::getPolicyLevelString(PolicyLevel level) { |
| + static string16 strings[] = { ASCIIToUTF16("mandatory"), |
| + ASCIIToUTF16("recommended"), |
| + ASCIIToUTF16("undefined")}; |
| + return strings[level]; |
| +} |
| + |
|
Mattias Nissler (ping if slow)
2011/08/09 13:20:40
only one newline
simo
2011/08/10 14:28:19
Done.
|
| + |
| +// PolicyStatusMap |
| +PolicyStatusMap::PolicyStatusMap() { |
| +} |
| + |
| +PolicyStatusMap::~PolicyStatusMap() { |
| +} |
| + |
| +const PolicyStatusInfo* PolicyStatusMap::Get( |
| + ConfigurationPolicyType policy) const { |
| + const_iterator entry = map_.find(policy); |
| + return entry != map_.end() ? entry->second : NULL; |
| +} |
| + |
| +void PolicyStatusMap::Set(ConfigurationPolicyType policy, |
| + PolicyStatusInfo* info) { |
| + std::swap(map_[policy], info); |
| + delete info; |
| +} |
| + |
| +bool PolicyStatusMap::empty() const { |
| + return map_.empty(); |
| +} |
| + |
| +size_t PolicyStatusMap::size() const { |
| + return map_.size(); |
| +} |
| + |
| +PolicyStatusMap::const_iterator PolicyStatusMap::begin() const { |
| + return map_.begin(); |
| +} |
| + |
| +PolicyStatusMap::const_iterator PolicyStatusMap::end() const { |
| + return map_.end(); |
| +} |
| + |
| +void PolicyStatusMap::Clear() { |
| + for (PolicyStatusMapType::iterator i = map_.begin(); i != map_.end(); ++i) |
| + delete i->second; |
| + map_.clear(); |
| +} |
| + |
| +} // policy |
|
Mattias Nissler (ping if slow)
2011/08/09 13:20:40
namespace policy
simo
2011/08/10 14:28:19
Done.
|