OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/policy/core/browser/policy_error_map.h" | 5 #include "components/policy/core/browser/policy_error_map.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 AddError(PendingError(policy, subkey, -1, message_id, replacement)); | 85 AddError(PendingError(policy, subkey, -1, message_id, replacement)); |
86 } | 86 } |
87 | 87 |
88 void PolicyErrorMap::AddError(const std::string& policy, | 88 void PolicyErrorMap::AddError(const std::string& policy, |
89 int index, | 89 int index, |
90 int message_id, | 90 int message_id, |
91 const std::string& replacement) { | 91 const std::string& replacement) { |
92 AddError(PendingError(policy, std::string(), index, message_id, replacement)); | 92 AddError(PendingError(policy, std::string(), index, message_id, replacement)); |
93 } | 93 } |
94 | 94 |
95 string16 PolicyErrorMap::GetErrors(const std::string& policy) { | 95 base::string16 PolicyErrorMap::GetErrors(const std::string& policy) { |
96 CheckReadyAndConvert(); | 96 CheckReadyAndConvert(); |
97 std::pair<const_iterator, const_iterator> range = map_.equal_range(policy); | 97 std::pair<const_iterator, const_iterator> range = map_.equal_range(policy); |
98 std::vector<string16> list; | 98 std::vector<base::string16> list; |
99 for (const_iterator it = range.first; it != range.second; ++it) | 99 for (const_iterator it = range.first; it != range.second; ++it) |
100 list.push_back(it->second); | 100 list.push_back(it->second); |
101 return JoinString(list, '\n'); | 101 return JoinString(list, '\n'); |
102 } | 102 } |
103 | 103 |
104 bool PolicyErrorMap::empty() { | 104 bool PolicyErrorMap::empty() { |
105 CheckReadyAndConvert(); | 105 CheckReadyAndConvert(); |
106 return map_.empty(); | 106 return map_.empty(); |
107 } | 107 } |
108 | 108 |
(...skipping 19 matching lines...) Expand all Loading... |
128 | 128 |
129 void PolicyErrorMap::AddError(const PendingError& error) { | 129 void PolicyErrorMap::AddError(const PendingError& error) { |
130 if (IsReady()) { | 130 if (IsReady()) { |
131 Convert(error); | 131 Convert(error); |
132 } else { | 132 } else { |
133 pending_.push_back(error); | 133 pending_.push_back(error); |
134 } | 134 } |
135 } | 135 } |
136 | 136 |
137 void PolicyErrorMap::Convert(const PendingError& error) { | 137 void PolicyErrorMap::Convert(const PendingError& error) { |
138 string16 submessage; | 138 base::string16 submessage; |
139 if (error.has_replacement) { | 139 if (error.has_replacement) { |
140 submessage = l10n_util::GetStringFUTF16(error.message_id, | 140 submessage = l10n_util::GetStringFUTF16(error.message_id, |
141 ASCIIToUTF16(error.replacement)); | 141 ASCIIToUTF16(error.replacement)); |
142 } else { | 142 } else { |
143 submessage = l10n_util::GetStringUTF16(error.message_id); | 143 submessage = l10n_util::GetStringUTF16(error.message_id); |
144 } | 144 } |
145 string16 message; | 145 base::string16 message; |
146 if (!error.subkey.empty()) { | 146 if (!error.subkey.empty()) { |
147 message = l10n_util::GetStringFUTF16(IDS_POLICY_SUBKEY_ERROR, | 147 message = l10n_util::GetStringFUTF16(IDS_POLICY_SUBKEY_ERROR, |
148 ASCIIToUTF16(error.subkey), | 148 ASCIIToUTF16(error.subkey), |
149 submessage); | 149 submessage); |
150 } else if (error.index >= 0) { | 150 } else if (error.index >= 0) { |
151 message = l10n_util::GetStringFUTF16(IDS_POLICY_LIST_ENTRY_ERROR, | 151 message = l10n_util::GetStringFUTF16(IDS_POLICY_LIST_ENTRY_ERROR, |
152 base::IntToString16(error.index), | 152 base::IntToString16(error.index), |
153 submessage); | 153 submessage); |
154 } else { | 154 } else { |
155 message = submessage; | 155 message = submessage; |
156 } | 156 } |
157 map_.insert(std::make_pair(error.policy, message)); | 157 map_.insert(std::make_pair(error.policy, message)); |
158 } | 158 } |
159 | 159 |
160 void PolicyErrorMap::CheckReadyAndConvert() { | 160 void PolicyErrorMap::CheckReadyAndConvert() { |
161 DCHECK(IsReady()); | 161 DCHECK(IsReady()); |
162 for (size_t i = 0; i < pending_.size(); ++i) { | 162 for (size_t i = 0; i < pending_.size(); ++i) { |
163 Convert(pending_[i]); | 163 Convert(pending_[i]); |
164 } | 164 } |
165 pending_.clear(); | 165 pending_.clear(); |
166 } | 166 } |
167 | 167 |
168 } // namespace policy | 168 } // namespace policy |
OLD | NEW |