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_error_map.h" |
| 6 |
| 7 #include <algorithm> |
| 8 #include <utility> |
| 9 |
| 10 #include "base/logging.h" |
| 11 #include "base/stl_util.h" |
| 12 #include "base/utf_string_conversions.h" |
| 13 #include "ui/base/l10n/l10n_util.h" |
| 14 |
| 15 namespace policy { |
| 16 |
| 17 PolicyErrorMap::PolicyErrorMap() { |
| 18 } |
| 19 |
| 20 PolicyErrorMap::~PolicyErrorMap() { |
| 21 Clear(); |
| 22 } |
| 23 |
| 24 void PolicyErrorMap::AddError(ConfigurationPolicyType policy, int message_id) { |
| 25 string16 error = l10n_util::GetStringUTF16(message_id); |
| 26 map_.insert(std::make_pair(policy, error)); |
| 27 } |
| 28 |
| 29 void PolicyErrorMap::AddError(ConfigurationPolicyType policy, |
| 30 int message_id, |
| 31 const std::string& replacement) { |
| 32 string16 error = l10n_util::GetStringFUTF16(message_id, |
| 33 ASCIIToUTF16(replacement)); |
| 34 map_.insert(std::make_pair(policy, error)); |
| 35 } |
| 36 |
| 37 ListValue* PolicyErrorMap::GetErrors( |
| 38 ConfigurationPolicyType policy) const { |
| 39 std::pair<const_iterator, const_iterator> range = map_.equal_range(policy); |
| 40 |
| 41 if (range.first == range.second) |
| 42 return NULL; |
| 43 |
| 44 ListValue* list = new ListValue(); |
| 45 for (const_iterator it = range.first; it != range.second; ++it) |
| 46 list->Append(Value::CreateStringValue(it->second)); |
| 47 |
| 48 return list; |
| 49 } |
| 50 |
| 51 bool PolicyErrorMap::empty() const { |
| 52 return map_.empty(); |
| 53 } |
| 54 |
| 55 size_t PolicyErrorMap::size() const { |
| 56 return map_.size(); |
| 57 } |
| 58 |
| 59 PolicyErrorMap::const_iterator PolicyErrorMap::begin() const { |
| 60 return map_.begin(); |
| 61 } |
| 62 |
| 63 PolicyErrorMap::const_iterator PolicyErrorMap::end() const { |
| 64 return map_.end(); |
| 65 } |
| 66 |
| 67 void PolicyErrorMap::Clear() { |
| 68 map_.clear(); |
| 69 } |
| 70 |
| 71 } // namespace policy |
OLD | NEW |