OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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/configuration_policy_reader.h" | 5 #include "chrome/browser/policy/configuration_policy_reader.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
| 10 #include "base/logging.h" |
10 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "base/string16.h" |
11 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
12 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
13 #include "chrome/browser/policy/browser_policy_connector.h" | 15 #include "chrome/browser/policy/browser_policy_connector.h" |
14 #include "chrome/browser/policy/configuration_policy_pref_store.h" | 16 #include "chrome/browser/policy/configuration_policy_pref_store.h" |
15 #include "chrome/browser/policy/policy_map.h" | 17 #include "chrome/browser/policy/policy_map.h" |
16 | 18 |
17 namespace policy { | 19 namespace policy { |
18 | 20 |
19 // This class functions as a container for policy status information used by the | 21 // This class functions as a container for policy status information used by the |
20 // ConfigurationPolicyReader class. It obtains policy values from a | 22 // ConfigurationPolicyReader class. It obtains policy values from a |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 | 72 |
71 void ConfigurationPolicyStatusKeeper::GetPoliciesFromProvider( | 73 void ConfigurationPolicyStatusKeeper::GetPoliciesFromProvider( |
72 ConfigurationPolicyProvider* provider) { | 74 ConfigurationPolicyProvider* provider) { |
73 scoped_ptr<PolicyMap> policies(new PolicyMap()); | 75 scoped_ptr<PolicyMap> policies(new PolicyMap()); |
74 if (!provider->Provide(policies.get())) | 76 if (!provider->Provide(policies.get())) |
75 LOG(WARNING) << "Failed to get policy from provider."; | 77 LOG(WARNING) << "Failed to get policy from provider."; |
76 | 78 |
77 PolicyMap::const_iterator policy = policies->begin(); | 79 PolicyMap::const_iterator policy = policies->begin(); |
78 for ( ; policy != policies->end(); ++policy) { | 80 for ( ; policy != policies->end(); ++policy) { |
79 string16 name = PolicyStatus::GetPolicyName(policy->first); | 81 string16 name = PolicyStatus::GetPolicyName(policy->first); |
80 | 82 DCHECK(!name.empty()); |
81 if (name == string16()) { | |
82 NOTREACHED(); | |
83 } | |
84 | 83 |
85 // TODO(simo) actually determine whether the policy is a user or a device | 84 // TODO(simo) actually determine whether the policy is a user or a device |
86 // one and whether the policy could be enforced or not once this information | 85 // one and whether the policy could be enforced or not once this information |
87 // is available. | 86 // is available. |
88 PolicyStatusInfo* info = new PolicyStatusInfo(name, | 87 PolicyStatusInfo* info = new PolicyStatusInfo(name, |
89 PolicyStatusInfo::USER, | 88 PolicyStatusInfo::USER, |
90 policy_level_, | 89 policy_level_, |
91 policy->second->DeepCopy(), | 90 policy->second->DeepCopy(), |
92 PolicyStatusInfo::ENFORCED, | 91 PolicyStatusInfo::ENFORCED, |
93 string16()); | 92 string16()); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 connector->GetManagedCloudProvider(), PolicyStatusInfo::MANDATORY); | 145 connector->GetManagedCloudProvider(), PolicyStatusInfo::MANDATORY); |
147 } | 146 } |
148 | 147 |
149 // static | 148 // static |
150 ConfigurationPolicyReader* | 149 ConfigurationPolicyReader* |
151 ConfigurationPolicyReader::CreateRecommendedPlatformPolicyReader() { | 150 ConfigurationPolicyReader::CreateRecommendedPlatformPolicyReader() { |
152 BrowserPolicyConnector* connector = | 151 BrowserPolicyConnector* connector = |
153 g_browser_process->browser_policy_connector(); | 152 g_browser_process->browser_policy_connector(); |
154 return new ConfigurationPolicyReader( | 153 return new ConfigurationPolicyReader( |
155 connector->GetRecommendedPlatformProvider(), | 154 connector->GetRecommendedPlatformProvider(), |
156 PolicyStatusInfo::RECOMMENDED); | 155 PolicyStatusInfo::RECOMMENDED); |
157 } | 156 } |
158 | 157 |
159 // static | 158 // static |
160 ConfigurationPolicyReader* | 159 ConfigurationPolicyReader* |
161 ConfigurationPolicyReader::CreateRecommendedCloudPolicyReader() { | 160 ConfigurationPolicyReader::CreateRecommendedCloudPolicyReader() { |
162 BrowserPolicyConnector* connector = | 161 BrowserPolicyConnector* connector = |
163 g_browser_process->browser_policy_connector(); | 162 g_browser_process->browser_policy_connector(); |
164 return new ConfigurationPolicyReader( | 163 return new ConfigurationPolicyReader( |
165 connector->GetRecommendedCloudProvider(), PolicyStatusInfo::RECOMMENDED); | 164 connector->GetRecommendedCloudProvider(), PolicyStatusInfo::RECOMMENDED); |
166 } | 165 } |
167 | 166 |
168 DictionaryValue* ConfigurationPolicyReader::GetPolicyStatus( | 167 DictionaryValue* ConfigurationPolicyReader::GetPolicyStatus( |
169 ConfigurationPolicyType policy) const { | 168 ConfigurationPolicyType policy) const { |
170 return policy_keeper_->GetPolicyStatus(policy); | 169 return policy_keeper_->GetPolicyStatus(policy); |
171 } | 170 } |
172 | 171 |
173 ConfigurationPolicyReader::ConfigurationPolicyReader() | 172 ConfigurationPolicyReader::ConfigurationPolicyReader() |
174 : provider_(NULL), | 173 : provider_(NULL), |
175 policy_level_(PolicyStatusInfo::LEVEL_UNDEFINED), | 174 policy_level_(PolicyStatusInfo::LEVEL_UNDEFINED), |
176 policy_keeper_(NULL) { | 175 policy_keeper_(NULL) { |
177 } | 176 } |
178 | 177 |
179 void ConfigurationPolicyReader::Refresh() { | 178 void ConfigurationPolicyReader::Refresh() { |
180 if (!provider_) | 179 if (!provider_) |
181 return; | 180 return; |
182 | 181 |
183 // Read policy state into a new keeper and swap out old keeper. | 182 policy_keeper_.reset( |
184 scoped_ptr<ConfigurationPolicyStatusKeeper> new_keeper( | |
185 new ConfigurationPolicyStatusKeeper(provider_, policy_level_)); | 183 new ConfigurationPolicyStatusKeeper(provider_, policy_level_)); |
186 policy_keeper_.reset(new_keeper.release()); | |
187 | 184 |
188 FOR_EACH_OBSERVER(Observer, observers_, OnPolicyValuesChanged()); | 185 FOR_EACH_OBSERVER(Observer, observers_, OnPolicyValuesChanged()); |
189 } | 186 } |
190 | 187 |
191 // PolicyStatus | 188 // PolicyStatus |
192 PolicyStatus::PolicyStatus(ConfigurationPolicyReader* managed_platform, | 189 PolicyStatus::PolicyStatus(ConfigurationPolicyReader* managed_platform, |
193 ConfigurationPolicyReader* managed_cloud, | 190 ConfigurationPolicyReader* managed_cloud, |
194 ConfigurationPolicyReader* recommended_platform, | 191 ConfigurationPolicyReader* recommended_platform, |
195 ConfigurationPolicyReader* recommended_cloud) | 192 ConfigurationPolicyReader* recommended_cloud) |
196 : managed_platform_(managed_platform), | 193 : managed_platform_(managed_platform), |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 for ( ; info != unsent_policies.end(); ++info) | 240 for ( ; info != unsent_policies.end(); ++info) |
244 result->Append(*info); | 241 result->Append(*info); |
245 | 242 |
246 return result; | 243 return result; |
247 } | 244 } |
248 | 245 |
249 // static | 246 // static |
250 string16 PolicyStatus::GetPolicyName(ConfigurationPolicyType policy_type) { | 247 string16 PolicyStatus::GetPolicyName(ConfigurationPolicyType policy_type) { |
251 static std::map<ConfigurationPolicyType, string16> name_map; | 248 static std::map<ConfigurationPolicyType, string16> name_map; |
252 static const ConfigurationPolicyProvider::PolicyDefinitionList* | 249 static const ConfigurationPolicyProvider::PolicyDefinitionList* |
253 supported_policies; | 250 supported_policies = NULL; |
254 | 251 |
255 if (!supported_policies) { | 252 if (!supported_policies) { |
256 supported_policies = | 253 supported_policies = |
257 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(); | 254 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(); |
258 | 255 |
259 // Create mapping from ConfigurationPolicyTypes to actual policy names. | 256 // Create mapping from ConfigurationPolicyTypes to actual policy names. |
260 const ConfigurationPolicyProvider::PolicyDefinitionList::Entry* entry = | 257 const ConfigurationPolicyProvider::PolicyDefinitionList::Entry* entry = |
261 supported_policies->begin; | 258 supported_policies->begin; |
262 for ( ; entry != supported_policies->end; ++entry) | 259 for ( ; entry != supported_policies->end; ++entry) |
263 name_map[entry->policy_type] = ASCIIToUTF16(entry->name); | 260 name_map[entry->policy_type] = ASCIIToUTF16(entry->name); |
(...skipping 27 matching lines...) Expand all Loading... |
291 list->Append(mc_policy); | 288 list->Append(mc_policy); |
292 if (rp_policy) | 289 if (rp_policy) |
293 list->Append(rp_policy); | 290 list->Append(rp_policy); |
294 if (rc_policy) | 291 if (rc_policy) |
295 list->Append(rc_policy); | 292 list->Append(rc_policy); |
296 | 293 |
297 return added_policy; | 294 return added_policy; |
298 } | 295 } |
299 | 296 |
300 } // namespace policy | 297 } // namespace policy |
OLD | NEW |