| 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_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "grit/generated_resources.h" | 11 #include "grit/generated_resources.h" |
| 12 #include "ui/base/l10n/l10n_util.h" | 12 #include "ui/base/l10n/l10n_util.h" |
| 13 #include "ui/base/resource/resource_bundle.h" | 13 #include "ui/base/resource/resource_bundle.h" |
| 14 | 14 |
| 15 namespace policy { | 15 namespace policy { |
| 16 | 16 |
| 17 struct PolicyErrorMap::PendingError { | 17 struct PolicyErrorMap::PendingError { |
| 18 PendingError(ConfigurationPolicyType policy, | 18 PendingError(const std::string& policy, |
| 19 const std::string& subkey, | 19 const std::string& subkey, |
| 20 int message_id, | 20 int message_id, |
| 21 const std::string& replacement) | 21 const std::string& replacement) |
| 22 : policy(policy), | 22 : policy(policy), |
| 23 subkey(subkey), | 23 subkey(subkey), |
| 24 message_id(message_id), | 24 message_id(message_id), |
| 25 has_replacement(true), | 25 has_replacement(true), |
| 26 replacement(replacement) {} | 26 replacement(replacement) {} |
| 27 | 27 |
| 28 PendingError(ConfigurationPolicyType policy, | 28 PendingError(const std::string& policy, |
| 29 const std::string& subkey, | 29 const std::string& subkey, |
| 30 int message_id) | 30 int message_id) |
| 31 : policy(policy), | 31 : policy(policy), |
| 32 subkey(subkey), | 32 subkey(subkey), |
| 33 message_id(message_id), | 33 message_id(message_id), |
| 34 has_replacement(false) {} | 34 has_replacement(false) {} |
| 35 | 35 |
| 36 ConfigurationPolicyType policy; | 36 std::string policy; |
| 37 std::string subkey; | 37 std::string subkey; |
| 38 int message_id; | 38 int message_id; |
| 39 bool has_replacement; | 39 bool has_replacement; |
| 40 std::string replacement; | 40 std::string replacement; |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 PolicyErrorMap::PolicyErrorMap() { | 43 PolicyErrorMap::PolicyErrorMap() { |
| 44 } | 44 } |
| 45 | 45 |
| 46 PolicyErrorMap::~PolicyErrorMap() { | 46 PolicyErrorMap::~PolicyErrorMap() { |
| 47 } | 47 } |
| 48 | 48 |
| 49 bool PolicyErrorMap::IsReady() const { | 49 bool PolicyErrorMap::IsReady() const { |
| 50 return ui::ResourceBundle::HasSharedInstance(); | 50 return ui::ResourceBundle::HasSharedInstance(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 void PolicyErrorMap::AddError(ConfigurationPolicyType policy, int message_id) { | 53 void PolicyErrorMap::AddError(const std::string& policy, int message_id) { |
| 54 AddError(PendingError(policy, std::string(), message_id)); | 54 AddError(PendingError(policy, std::string(), message_id)); |
| 55 } | 55 } |
| 56 | 56 |
| 57 void PolicyErrorMap::AddError(ConfigurationPolicyType policy, | 57 void PolicyErrorMap::AddError(const std::string& policy, |
| 58 const std::string& subkey, | 58 const std::string& subkey, |
| 59 int message_id) { | 59 int message_id) { |
| 60 AddError(PendingError(policy, subkey, message_id)); | 60 AddError(PendingError(policy, subkey, message_id)); |
| 61 } | 61 } |
| 62 | 62 |
| 63 void PolicyErrorMap::AddError(ConfigurationPolicyType policy, | 63 void PolicyErrorMap::AddError(const std::string& policy, |
| 64 int message_id, | 64 int message_id, |
| 65 const std::string& replacement) { | 65 const std::string& replacement) { |
| 66 AddError(PendingError(policy, std::string(), message_id, replacement)); | 66 AddError(PendingError(policy, std::string(), message_id, replacement)); |
| 67 } | 67 } |
| 68 | 68 |
| 69 void PolicyErrorMap::AddError(ConfigurationPolicyType policy, | 69 void PolicyErrorMap::AddError(const std::string& policy, |
| 70 const std::string& subkey, | 70 const std::string& subkey, |
| 71 int message_id, | 71 int message_id, |
| 72 const std::string& replacement) { | 72 const std::string& replacement) { |
| 73 AddError(PendingError(policy, subkey, message_id, replacement)); | 73 AddError(PendingError(policy, subkey, message_id, replacement)); |
| 74 } | 74 } |
| 75 | 75 |
| 76 string16 PolicyErrorMap::GetErrors(ConfigurationPolicyType policy) { | 76 string16 PolicyErrorMap::GetErrors(const std::string& policy) { |
| 77 CheckReadyAndConvert(); | 77 CheckReadyAndConvert(); |
| 78 std::pair<const_iterator, const_iterator> range = map_.equal_range(policy); | 78 std::pair<const_iterator, const_iterator> range = map_.equal_range(policy); |
| 79 std::vector<string16> list; | 79 std::vector<string16> list; |
| 80 for (const_iterator it = range.first; it != range.second; ++it) | 80 for (const_iterator it = range.first; it != range.second; ++it) |
| 81 list.push_back(it->second); | 81 list.push_back(it->second); |
| 82 return JoinString(list, '\n'); | 82 return JoinString(list, '\n'); |
| 83 } | 83 } |
| 84 | 84 |
| 85 bool PolicyErrorMap::empty() { | 85 bool PolicyErrorMap::empty() { |
| 86 CheckReadyAndConvert(); | 86 CheckReadyAndConvert(); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 | 136 |
| 137 void PolicyErrorMap::CheckReadyAndConvert() { | 137 void PolicyErrorMap::CheckReadyAndConvert() { |
| 138 DCHECK(IsReady()); | 138 DCHECK(IsReady()); |
| 139 for (size_t i = 0; i < pending_.size(); ++i) { | 139 for (size_t i = 0; i < pending_.size(); ++i) { |
| 140 Convert(pending_[i]); | 140 Convert(pending_[i]); |
| 141 } | 141 } |
| 142 pending_.clear(); | 142 pending_.clear(); |
| 143 } | 143 } |
| 144 | 144 |
| 145 } // namespace policy | 145 } // namespace policy |
| OLD | NEW |