Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(261)

Side by Side Diff: chrome/browser/policy/policy_error_map.cc

Issue 10316022: Wire up the policy for controlling pinned apps in the ash launcher. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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),
24 message_id(message_id), 26 message_id(message_id),
Joao da Silva 2012/05/03 18:41:22 Don't you want to store the |index| here?
Mattias Nissler (ping if slow) 2012/05/03 20:13:04 Yes, definitely. Thanks for catching. Done.
25 has_replacement(true), 27 has_replacement(true),
26 replacement(replacement) {} 28 replacement(replacement) {}
27 29
28 PendingError(const std::string& policy, 30 PendingError(const std::string& policy,
29 const std::string& subkey, 31 const std::string& subkey,
32 int index,
30 int message_id) 33 int message_id)
31 : policy(policy), 34 : policy(policy),
32 subkey(subkey), 35 subkey(subkey),
33 message_id(message_id), 36 message_id(message_id),
Joao da Silva 2012/05/03 18:41:22 Same
Mattias Nissler (ping if slow) 2012/05/03 20:13:04 Done.
34 has_replacement(false) {} 37 has_replacement(false) {}
35 38
36 std::string policy; 39 std::string policy;
37 std::string subkey; 40 std::string subkey;
41 int index;
38 int message_id; 42 int message_id;
39 bool has_replacement; 43 bool has_replacement;
40 std::string replacement; 44 std::string replacement;
41 }; 45 };
42 46
43 PolicyErrorMap::PolicyErrorMap() { 47 PolicyErrorMap::PolicyErrorMap() {
44 } 48 }
45 49
46 PolicyErrorMap::~PolicyErrorMap() { 50 PolicyErrorMap::~PolicyErrorMap() {
47 } 51 }
48 52
49 bool PolicyErrorMap::IsReady() const { 53 bool PolicyErrorMap::IsReady() const {
50 return ui::ResourceBundle::HasSharedInstance(); 54 return ui::ResourceBundle::HasSharedInstance();
51 } 55 }
52 56
53 void PolicyErrorMap::AddError(const std::string& policy, int message_id) { 57 void PolicyErrorMap::AddError(const std::string& policy, int message_id) {
54 AddError(PendingError(policy, std::string(), message_id)); 58 AddError(PendingError(policy, std::string(), -1, message_id));
55 } 59 }
56 60
57 void PolicyErrorMap::AddError(const std::string& policy, 61 void PolicyErrorMap::AddError(const std::string& policy,
58 const std::string& subkey, 62 const std::string& subkey,
59 int message_id) { 63 int message_id) {
60 AddError(PendingError(policy, subkey, message_id)); 64 AddError(PendingError(policy, subkey, -1, message_id));
65 }
66
67 void PolicyErrorMap::AddError(const std::string& policy,
68 int index,
69 int message_id) {
70 AddError(PendingError(policy, std::string(), index, message_id));
61 } 71 }
62 72
63 void PolicyErrorMap::AddError(const std::string& policy, 73 void PolicyErrorMap::AddError(const std::string& policy,
64 int message_id, 74 int message_id,
65 const std::string& replacement) { 75 const std::string& replacement) {
66 AddError(PendingError(policy, std::string(), message_id, replacement)); 76 AddError(PendingError(policy, std::string(), -1, message_id, replacement));
67 } 77 }
68 78
69 void PolicyErrorMap::AddError(const std::string& policy, 79 void PolicyErrorMap::AddError(const std::string& policy,
70 const std::string& subkey, 80 const std::string& subkey,
71 int message_id, 81 int message_id,
72 const std::string& replacement) { 82 const std::string& replacement) {
73 AddError(PendingError(policy, subkey, message_id, replacement)); 83 AddError(PendingError(policy, subkey, -1, message_id, replacement));
84 }
85
86 void PolicyErrorMap::AddError(const std::string& policy,
87 int index,
88 int message_id,
89 const std::string& replacement) {
90 AddError(PendingError(policy, std::string(), index, message_id, replacement));
74 } 91 }
75 92
76 string16 PolicyErrorMap::GetErrors(const std::string& policy) { 93 string16 PolicyErrorMap::GetErrors(const std::string& policy) {
77 CheckReadyAndConvert(); 94 CheckReadyAndConvert();
78 std::pair<const_iterator, const_iterator> range = map_.equal_range(policy); 95 std::pair<const_iterator, const_iterator> range = map_.equal_range(policy);
79 std::vector<string16> list; 96 std::vector<string16> list;
80 for (const_iterator it = range.first; it != range.second; ++it) 97 for (const_iterator it = range.first; it != range.second; ++it)
81 list.push_back(it->second); 98 list.push_back(it->second);
82 return JoinString(list, '\n'); 99 return JoinString(list, '\n');
83 } 100 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 submessage = l10n_util::GetStringFUTF16(error.message_id, 138 submessage = l10n_util::GetStringFUTF16(error.message_id,
122 ASCIIToUTF16(error.replacement)); 139 ASCIIToUTF16(error.replacement));
123 } else { 140 } else {
124 submessage = l10n_util::GetStringUTF16(error.message_id); 141 submessage = l10n_util::GetStringUTF16(error.message_id);
125 } 142 }
126 string16 message; 143 string16 message;
127 if (!error.subkey.empty()) { 144 if (!error.subkey.empty()) {
128 message = l10n_util::GetStringFUTF16(IDS_POLICY_SUBKEY_ERROR, 145 message = l10n_util::GetStringFUTF16(IDS_POLICY_SUBKEY_ERROR,
129 ASCIIToUTF16(error.subkey), 146 ASCIIToUTF16(error.subkey),
130 submessage); 147 submessage);
148 } else if (error.index >= 0) {
149 message = l10n_util::GetStringFUTF16(IDS_POLICY_LIST_ENTRY_ERROR,
150 base::IntToString16(error.index),
151 submessage);
131 } else { 152 } else {
132 message = submessage; 153 message = submessage;
133 } 154 }
134 map_.insert(std::make_pair(error.policy, message)); 155 map_.insert(std::make_pair(error.policy, message));
135 } 156 }
136 157
137 void PolicyErrorMap::CheckReadyAndConvert() { 158 void PolicyErrorMap::CheckReadyAndConvert() {
138 DCHECK(IsReady()); 159 DCHECK(IsReady());
139 for (size_t i = 0; i < pending_.size(); ++i) { 160 for (size_t i = 0; i < pending_.size(); ++i) {
140 Convert(pending_[i]); 161 Convert(pending_[i]);
141 } 162 }
142 pending_.clear(); 163 pending_.clear();
143 } 164 }
144 165
145 } // namespace policy 166 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698