OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/device_management_policy_cache.h" | 5 #include "chrome/browser/policy/device_management_policy_cache.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/task.h" | 12 #include "base/task.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "chrome/browser/browser_thread.h" | 14 #include "chrome/browser/browser_thread.h" |
| 15 #include "chrome/browser/policy/proto/device_management_constants.h" |
15 #include "chrome/browser/policy/proto/device_management_local.pb.h" | 16 #include "chrome/browser/policy/proto/device_management_local.pb.h" |
16 | 17 |
17 using google::protobuf::RepeatedField; | 18 using google::protobuf::RepeatedField; |
18 using google::protobuf::RepeatedPtrField; | 19 using google::protobuf::RepeatedPtrField; |
19 | 20 |
20 namespace policy { | 21 namespace policy { |
21 | 22 |
22 // Saves policy information to a file. | 23 // Saves policy information to a file. |
23 class PersistPolicyTask : public Task { | 24 class PersistPolicyTask : public Task { |
24 public: | 25 public: |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 } | 216 } |
216 | 217 |
217 // static | 218 // static |
218 DictionaryValue* DeviceManagementPolicyCache::DecodePolicy( | 219 DictionaryValue* DeviceManagementPolicyCache::DecodePolicy( |
219 const em::DevicePolicyResponse& policy) { | 220 const em::DevicePolicyResponse& policy) { |
220 DictionaryValue* result = new DictionaryValue; | 221 DictionaryValue* result = new DictionaryValue; |
221 RepeatedPtrField<em::DevicePolicySetting>::const_iterator setting; | 222 RepeatedPtrField<em::DevicePolicySetting>::const_iterator setting; |
222 for (setting = policy.setting().begin(); | 223 for (setting = policy.setting().begin(); |
223 setting != policy.setting().end(); | 224 setting != policy.setting().end(); |
224 ++setting) { | 225 ++setting) { |
| 226 // Wrong policy key? Skip. |
| 227 if (setting->policy_key().compare(kChromeDevicePolicySettingKey) != 0) |
| 228 continue; |
| 229 |
225 // No policy value? Skip. | 230 // No policy value? Skip. |
226 if (!setting->has_policy_value()) | 231 if (!setting->has_policy_value()) |
227 continue; | 232 continue; |
228 | 233 |
229 // Iterate through all the name-value pairs wrapped in |setting|. | 234 // Iterate through all the name-value pairs wrapped in |setting|. |
230 const em::GenericSetting& policy_value(setting->policy_value()); | 235 const em::GenericSetting& policy_value(setting->policy_value()); |
231 RepeatedPtrField<em::GenericNamedValue>::const_iterator named_value; | 236 RepeatedPtrField<em::GenericNamedValue>::const_iterator named_value; |
232 for (named_value = policy_value.named_value().begin(); | 237 for (named_value = policy_value.named_value().begin(); |
233 named_value != policy_value.named_value().end(); | 238 named_value != policy_value.named_value().end(); |
234 ++named_value) { | 239 ++named_value) { |
235 if (named_value->has_value()) { | 240 if (named_value->has_value()) { |
236 Value* decoded_value = | 241 Value* decoded_value = |
237 DeviceManagementPolicyCache::DecodeValue(named_value->value()); | 242 DeviceManagementPolicyCache::DecodeValue(named_value->value()); |
238 if (decoded_value) | 243 if (decoded_value) |
239 result->Set(named_value->name(), decoded_value); | 244 result->Set(named_value->name(), decoded_value); |
240 } | 245 } |
241 } | 246 } |
242 } | 247 } |
243 return result; | 248 return result; |
244 } | 249 } |
245 | 250 |
246 } // namespace policy | 251 } // namespace policy |
OLD | NEW |