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