Chromium Code Reviews| Index: chrome/browser/policy/policy_error_map.cc |
| diff --git a/chrome/browser/policy/policy_error_map.cc b/chrome/browser/policy/policy_error_map.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e093e853d685c9a7a8157092252a21be9a7078b3 |
| --- /dev/null |
| +++ b/chrome/browser/policy/policy_error_map.cc |
| @@ -0,0 +1,75 @@ |
| +// 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_error_map.h" |
| + |
| +#include <algorithm> |
| + |
| +#include "base/logging.h" |
| +#include "base/stl_util.h" |
| +#include "base/utf_string_conversions.h" |
| +#include "ui/base/l10n/l10n_util.h" |
| + |
| +namespace policy { |
| + |
| +PolicyErrorMap::PolicyErrorMap() { |
| +} |
| + |
| +PolicyErrorMap::~PolicyErrorMap() { |
| + Clear(); |
| +} |
| + |
| +void PolicyErrorMap::AddError(ConfigurationPolicyType policy, int message_id) { |
| + string16 error = l10n_util::GetStringUTF16(message_id); |
| + Insert(policy, error); |
| +} |
| + |
| +void PolicyErrorMap::AddError(ConfigurationPolicyType policy, |
| + int message_id, |
| + std::string replacement) { |
| + string16 error = l10n_util::GetStringFUTF16(message_id, |
| + ASCIIToUTF16(replacement)); |
| + Insert(policy, error); |
| +} |
| + |
| +ListValue* PolicyErrorMap::GetErrors( |
| + ConfigurationPolicyType policy) const { |
| + std::pair<const_iterator, const_iterator> range = map_.equal_range(policy); |
| + |
| + if (range.first == range.second) |
| + return NULL; |
| + |
| + ListValue* list = new ListValue(); |
| + for (const_iterator it = range.first; it != range.second; ++it) |
| + list->Append(Value::CreateStringValue(it->second)); |
| + |
| + return list; |
| +} |
| + |
| +bool PolicyErrorMap::empty() const { |
| + return map_.empty(); |
| +} |
| + |
| +size_t PolicyErrorMap::size() const { |
| + return map_.size(); |
| +} |
| + |
| +PolicyErrorMap::const_iterator PolicyErrorMap::begin() const { |
| + return map_.begin(); |
| +} |
| + |
| +PolicyErrorMap::const_iterator PolicyErrorMap::end() const { |
| + return map_.end(); |
| +} |
| + |
| +void PolicyErrorMap::Clear() { |
| + map_.clear(); |
| +} |
| + |
| +void PolicyErrorMap::Insert(ConfigurationPolicyType policy, string16 error) { |
| + map_.insert( |
| + std::pair<ConfigurationPolicyType, string16>(policy, error)); |
|
Mattias Nissler (ping if slow)
2011/09/26 13:30:48
You can use std::make_pair to avoid the explicit t
simo
2011/09/29 09:33:08
Done.
|
| +} |
| + |
| +} // namespace policy |