| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/policy/policy_error_map.h" | 5 #include "chrome/browser/policy/policy_error_map.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/string_util.h" |
| 9 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 10 #include "ui/base/l10n/l10n_util.h" | 11 #include "ui/base/l10n/l10n_util.h" |
| 11 #include "ui/base/resource/resource_bundle.h" | 12 #include "ui/base/resource/resource_bundle.h" |
| 12 | 13 |
| 13 namespace policy { | 14 namespace policy { |
| 14 | 15 |
| 15 struct PolicyErrorMap::PendingError { | 16 struct PolicyErrorMap::PendingError { |
| 16 PendingError(ConfigurationPolicyType policy, | 17 PendingError(ConfigurationPolicyType policy, |
| 17 int message_id, | 18 int message_id, |
| 18 const string16& replacement) | 19 const string16& replacement) |
| (...skipping 24 matching lines...) Expand all Loading... |
| 43 void PolicyErrorMap::AddError(ConfigurationPolicyType policy, int message_id) { | 44 void PolicyErrorMap::AddError(ConfigurationPolicyType policy, int message_id) { |
| 44 AddError(PendingError(policy, message_id)); | 45 AddError(PendingError(policy, message_id)); |
| 45 } | 46 } |
| 46 | 47 |
| 47 void PolicyErrorMap::AddError(ConfigurationPolicyType policy, | 48 void PolicyErrorMap::AddError(ConfigurationPolicyType policy, |
| 48 int message_id, | 49 int message_id, |
| 49 const std::string& replacement) { | 50 const std::string& replacement) { |
| 50 AddError(PendingError(policy, message_id, ASCIIToUTF16(replacement))); | 51 AddError(PendingError(policy, message_id, ASCIIToUTF16(replacement))); |
| 51 } | 52 } |
| 52 | 53 |
| 53 ListValue* PolicyErrorMap::GetErrors(ConfigurationPolicyType policy) { | 54 string16 PolicyErrorMap::GetErrors(ConfigurationPolicyType policy) { |
| 54 CheckReadyAndConvert(); | 55 CheckReadyAndConvert(); |
| 55 std::pair<const_iterator, const_iterator> range = map_.equal_range(policy); | 56 std::pair<const_iterator, const_iterator> range = map_.equal_range(policy); |
| 56 | 57 std::vector<string16> list; |
| 57 if (range.first == range.second) | |
| 58 return NULL; | |
| 59 | |
| 60 ListValue* list = new ListValue(); | |
| 61 for (const_iterator it = range.first; it != range.second; ++it) | 58 for (const_iterator it = range.first; it != range.second; ++it) |
| 62 list->Append(Value::CreateStringValue(it->second)); | 59 list.push_back(it->second); |
| 63 | 60 return JoinString(list, ' '); |
| 64 return list; | |
| 65 } | 61 } |
| 66 | 62 |
| 67 bool PolicyErrorMap::empty() { | 63 bool PolicyErrorMap::empty() { |
| 68 CheckReadyAndConvert(); | 64 CheckReadyAndConvert(); |
| 69 return map_.empty(); | 65 return map_.empty(); |
| 70 } | 66 } |
| 71 | 67 |
| 72 size_t PolicyErrorMap::size() { | 68 size_t PolicyErrorMap::size() { |
| 73 CheckReadyAndConvert(); | 69 CheckReadyAndConvert(); |
| 74 return map_.size(); | 70 return map_.size(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 | 104 |
| 109 void PolicyErrorMap::CheckReadyAndConvert() { | 105 void PolicyErrorMap::CheckReadyAndConvert() { |
| 110 DCHECK(IsReady()); | 106 DCHECK(IsReady()); |
| 111 for (size_t i = 0; i < pending_.size(); ++i) { | 107 for (size_t i = 0; i < pending_.size(); ++i) { |
| 112 Convert(pending_[i]); | 108 Convert(pending_[i]); |
| 113 } | 109 } |
| 114 pending_.clear(); | 110 pending_.clear(); |
| 115 } | 111 } |
| 116 | 112 |
| 117 } // namespace policy | 113 } // namespace policy |
| OLD | NEW |