OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_number_conversions.h" |
9 #include "base/string_util.h" | 10 #include "base/string_util.h" |
10 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
11 #include "grit/generated_resources.h" | 12 #include "grit/generated_resources.h" |
12 #include "ui/base/l10n/l10n_util.h" | 13 #include "ui/base/l10n/l10n_util.h" |
13 #include "ui/base/resource/resource_bundle.h" | 14 #include "ui/base/resource/resource_bundle.h" |
14 | 15 |
15 namespace policy { | 16 namespace policy { |
16 | 17 |
17 struct PolicyErrorMap::PendingError { | 18 struct PolicyErrorMap::PendingError { |
18 PendingError(const std::string& policy, | 19 PendingError(const std::string& policy, |
19 const std::string& subkey, | 20 const std::string& subkey, |
| 21 int index, |
20 int message_id, | 22 int message_id, |
21 const std::string& replacement) | 23 const std::string& replacement) |
22 : policy(policy), | 24 : policy(policy), |
23 subkey(subkey), | 25 subkey(subkey), |
| 26 index(index), |
24 message_id(message_id), | 27 message_id(message_id), |
25 has_replacement(true), | 28 has_replacement(true), |
26 replacement(replacement) {} | 29 replacement(replacement) {} |
27 | 30 |
28 PendingError(const std::string& policy, | 31 PendingError(const std::string& policy, |
29 const std::string& subkey, | 32 const std::string& subkey, |
| 33 int index, |
30 int message_id) | 34 int message_id) |
31 : policy(policy), | 35 : policy(policy), |
32 subkey(subkey), | 36 subkey(subkey), |
| 37 index(index), |
33 message_id(message_id), | 38 message_id(message_id), |
34 has_replacement(false) {} | 39 has_replacement(false) {} |
35 | 40 |
36 std::string policy; | 41 std::string policy; |
37 std::string subkey; | 42 std::string subkey; |
| 43 int index; |
38 int message_id; | 44 int message_id; |
39 bool has_replacement; | 45 bool has_replacement; |
40 std::string replacement; | 46 std::string replacement; |
41 }; | 47 }; |
42 | 48 |
43 PolicyErrorMap::PolicyErrorMap() { | 49 PolicyErrorMap::PolicyErrorMap() { |
44 } | 50 } |
45 | 51 |
46 PolicyErrorMap::~PolicyErrorMap() { | 52 PolicyErrorMap::~PolicyErrorMap() { |
47 } | 53 } |
48 | 54 |
49 bool PolicyErrorMap::IsReady() const { | 55 bool PolicyErrorMap::IsReady() const { |
50 return ui::ResourceBundle::HasSharedInstance(); | 56 return ui::ResourceBundle::HasSharedInstance(); |
51 } | 57 } |
52 | 58 |
53 void PolicyErrorMap::AddError(const std::string& policy, int message_id) { | 59 void PolicyErrorMap::AddError(const std::string& policy, int message_id) { |
54 AddError(PendingError(policy, std::string(), message_id)); | 60 AddError(PendingError(policy, std::string(), -1, message_id)); |
55 } | 61 } |
56 | 62 |
57 void PolicyErrorMap::AddError(const std::string& policy, | 63 void PolicyErrorMap::AddError(const std::string& policy, |
58 const std::string& subkey, | 64 const std::string& subkey, |
59 int message_id) { | 65 int message_id) { |
60 AddError(PendingError(policy, subkey, message_id)); | 66 AddError(PendingError(policy, subkey, -1, message_id)); |
| 67 } |
| 68 |
| 69 void PolicyErrorMap::AddError(const std::string& policy, |
| 70 int index, |
| 71 int message_id) { |
| 72 AddError(PendingError(policy, std::string(), index, message_id)); |
61 } | 73 } |
62 | 74 |
63 void PolicyErrorMap::AddError(const std::string& policy, | 75 void PolicyErrorMap::AddError(const std::string& policy, |
64 int message_id, | 76 int message_id, |
65 const std::string& replacement) { | 77 const std::string& replacement) { |
66 AddError(PendingError(policy, std::string(), message_id, replacement)); | 78 AddError(PendingError(policy, std::string(), -1, message_id, replacement)); |
67 } | 79 } |
68 | 80 |
69 void PolicyErrorMap::AddError(const std::string& policy, | 81 void PolicyErrorMap::AddError(const std::string& policy, |
70 const std::string& subkey, | 82 const std::string& subkey, |
71 int message_id, | 83 int message_id, |
72 const std::string& replacement) { | 84 const std::string& replacement) { |
73 AddError(PendingError(policy, subkey, message_id, replacement)); | 85 AddError(PendingError(policy, subkey, -1, message_id, replacement)); |
| 86 } |
| 87 |
| 88 void PolicyErrorMap::AddError(const std::string& policy, |
| 89 int index, |
| 90 int message_id, |
| 91 const std::string& replacement) { |
| 92 AddError(PendingError(policy, std::string(), index, message_id, replacement)); |
74 } | 93 } |
75 | 94 |
76 string16 PolicyErrorMap::GetErrors(const std::string& policy) { | 95 string16 PolicyErrorMap::GetErrors(const std::string& policy) { |
77 CheckReadyAndConvert(); | 96 CheckReadyAndConvert(); |
78 std::pair<const_iterator, const_iterator> range = map_.equal_range(policy); | 97 std::pair<const_iterator, const_iterator> range = map_.equal_range(policy); |
79 std::vector<string16> list; | 98 std::vector<string16> list; |
80 for (const_iterator it = range.first; it != range.second; ++it) | 99 for (const_iterator it = range.first; it != range.second; ++it) |
81 list.push_back(it->second); | 100 list.push_back(it->second); |
82 return JoinString(list, '\n'); | 101 return JoinString(list, '\n'); |
83 } | 102 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 submessage = l10n_util::GetStringFUTF16(error.message_id, | 140 submessage = l10n_util::GetStringFUTF16(error.message_id, |
122 ASCIIToUTF16(error.replacement)); | 141 ASCIIToUTF16(error.replacement)); |
123 } else { | 142 } else { |
124 submessage = l10n_util::GetStringUTF16(error.message_id); | 143 submessage = l10n_util::GetStringUTF16(error.message_id); |
125 } | 144 } |
126 string16 message; | 145 string16 message; |
127 if (!error.subkey.empty()) { | 146 if (!error.subkey.empty()) { |
128 message = l10n_util::GetStringFUTF16(IDS_POLICY_SUBKEY_ERROR, | 147 message = l10n_util::GetStringFUTF16(IDS_POLICY_SUBKEY_ERROR, |
129 ASCIIToUTF16(error.subkey), | 148 ASCIIToUTF16(error.subkey), |
130 submessage); | 149 submessage); |
| 150 } else if (error.index >= 0) { |
| 151 message = l10n_util::GetStringFUTF16(IDS_POLICY_LIST_ENTRY_ERROR, |
| 152 base::IntToString16(error.index), |
| 153 submessage); |
131 } else { | 154 } else { |
132 message = submessage; | 155 message = submessage; |
133 } | 156 } |
134 map_.insert(std::make_pair(error.policy, message)); | 157 map_.insert(std::make_pair(error.policy, message)); |
135 } | 158 } |
136 | 159 |
137 void PolicyErrorMap::CheckReadyAndConvert() { | 160 void PolicyErrorMap::CheckReadyAndConvert() { |
138 DCHECK(IsReady()); | 161 DCHECK(IsReady()); |
139 for (size_t i = 0; i < pending_.size(); ++i) { | 162 for (size_t i = 0; i < pending_.size(); ++i) { |
140 Convert(pending_[i]); | 163 Convert(pending_[i]); |
141 } | 164 } |
142 pending_.clear(); | 165 pending_.clear(); |
143 } | 166 } |
144 | 167 |
145 } // namespace policy | 168 } // namespace policy |
OLD | NEW |