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_loader_mac.h" | 5 #include "chrome/browser/policy/policy_loader_mac.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/mac/foundation_util.h" | 11 #include "base/mac/foundation_util.h" |
12 #include "base/mac/scoped_cftyperef.h" | 12 #include "base/mac/scoped_cftyperef.h" |
13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
14 #include "base/platform_file.h" | 14 #include "base/platform_file.h" |
15 #include "base/sequenced_task_runner.h" | 15 #include "base/sequenced_task_runner.h" |
16 #include "base/strings/sys_string_conversions.h" | 16 #include "base/strings/sys_string_conversions.h" |
17 #include "base/values.h" | 17 #include "base/values.h" |
18 #include "chrome/browser/policy/external_data_fetcher.h" | 18 #include "chrome/browser/policy/external_data_fetcher.h" |
19 #include "chrome/browser/policy/policy_bundle.h" | 19 #include "chrome/browser/policy/policy_bundle.h" |
20 #include "chrome/browser/policy/policy_domain_descriptor.h" | 20 #include "chrome/browser/policy/policy_domain_descriptor.h" |
21 #include "chrome/browser/policy/policy_load_status.h" | 21 #include "chrome/browser/policy/policy_load_status.h" |
22 #include "chrome/browser/policy/policy_map.h" | 22 #include "chrome/browser/policy/policy_map.h" |
23 #include "chrome/browser/policy/preferences_mac.h" | 23 #include "chrome/browser/policy/preferences_mac.h" |
24 #include "components/policy/core/common/policy_schema.h" | 24 #include "components/policy/core/common/schema.h" |
25 #include "policy/policy_constants.h" | 25 #include "policy/policy_constants.h" |
26 | 26 |
27 using base::mac::CFCast; | 27 using base::mac::CFCast; |
28 using base::ScopedCFTypeRef; | 28 using base::ScopedCFTypeRef; |
29 | 29 |
30 namespace policy { | 30 namespace policy { |
31 | 31 |
32 namespace { | 32 namespace { |
33 | 33 |
34 // Callback function for CFDictionaryApplyFunction. |key| and |value| are an | 34 // Callback function for CFDictionaryApplyFunction. |key| and |value| are an |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 id_prefix + it_schema->first, it_schema->second, &policy); | 203 id_prefix + it_schema->first, it_schema->second, &policy); |
204 if (!policy.empty()) { | 204 if (!policy.empty()) { |
205 bundle->Get(PolicyNamespace(descriptor->domain(), it_schema->first)) | 205 bundle->Get(PolicyNamespace(descriptor->domain(), it_schema->first)) |
206 .Swap(&policy); | 206 .Swap(&policy); |
207 } | 207 } |
208 } | 208 } |
209 } | 209 } |
210 | 210 |
211 void PolicyLoaderMac::LoadPolicyForComponent( | 211 void PolicyLoaderMac::LoadPolicyForComponent( |
212 const std::string& bundle_id_string, | 212 const std::string& bundle_id_string, |
213 const PolicySchema* schema, | 213 Schema schema, |
214 PolicyMap* policy) { | 214 PolicyMap* policy) { |
215 // TODO(joaodasilva): extensions may be registered in a PolicyDomainDescriptor | 215 // TODO(joaodasilva): extensions may be registered in a PolicyDomainDescriptor |
216 // without a PolicySchema, to allow a graceful update of the Legacy Browser | 216 // without a schema, to allow a graceful update of the Legacy Browser Support |
217 // Support extension on Windows. Remove this temporary check once that support | 217 // extension on Windows. Remove this check once that support is removed. |
218 // is removed. | 218 if (!schema.valid()) |
219 if (!schema) | |
220 return; | 219 return; |
221 | 220 |
222 base::ScopedCFTypeRef<CFStringRef> bundle_id( | 221 base::ScopedCFTypeRef<CFStringRef> bundle_id( |
223 base::SysUTF8ToCFStringRef(bundle_id_string)); | 222 base::SysUTF8ToCFStringRef(bundle_id_string)); |
224 preferences_->AppSynchronize(bundle_id); | 223 preferences_->AppSynchronize(bundle_id); |
225 | 224 |
226 const PolicySchemaMap* map = schema->GetProperties(); | 225 for (Schema::Iterator it = schema.GetPropertiesIterator(); |
227 if (!map) { | 226 !it.IsAtEnd(); it.Advance()) { |
228 NOTREACHED(); | |
229 return; | |
230 } | |
231 | |
232 for (PolicySchemaMap::const_iterator it = map->begin(); | |
233 it != map->end(); ++it) { | |
234 base::ScopedCFTypeRef<CFStringRef> pref_name( | 227 base::ScopedCFTypeRef<CFStringRef> pref_name( |
235 base::SysUTF8ToCFStringRef(it->first)); | 228 base::SysUTF8ToCFStringRef(it.key())); |
236 base::ScopedCFTypeRef<CFPropertyListRef> value( | 229 base::ScopedCFTypeRef<CFPropertyListRef> value( |
237 preferences_->CopyAppValue(pref_name, bundle_id)); | 230 preferences_->CopyAppValue(pref_name, bundle_id)); |
238 if (!value.get()) | 231 if (!value.get()) |
239 continue; | 232 continue; |
240 bool forced = | 233 bool forced = |
241 preferences_->AppValueIsForced(pref_name, bundle_id); | 234 preferences_->AppValueIsForced(pref_name, bundle_id); |
242 PolicyLevel level = forced ? POLICY_LEVEL_MANDATORY : | 235 PolicyLevel level = forced ? POLICY_LEVEL_MANDATORY : |
243 POLICY_LEVEL_RECOMMENDED; | 236 POLICY_LEVEL_RECOMMENDED; |
244 scoped_ptr<base::Value> policy_value(CreateValueFromProperty(value)); | 237 scoped_ptr<base::Value> policy_value(CreateValueFromProperty(value)); |
245 if (policy_value) | 238 if (policy_value) { |
246 policy->Set(it->first, level, POLICY_SCOPE_USER, | 239 policy->Set(it.key(), level, POLICY_SCOPE_USER, |
247 policy_value.release(), NULL); | 240 policy_value.release(), NULL); |
| 241 } |
248 } | 242 } |
249 } | 243 } |
250 | 244 |
251 void PolicyLoaderMac::OnFileUpdated(const base::FilePath& path, bool error) { | 245 void PolicyLoaderMac::OnFileUpdated(const base::FilePath& path, bool error) { |
252 if (!error) | 246 if (!error) |
253 Reload(false); | 247 Reload(false); |
254 } | 248 } |
255 | 249 |
256 } // namespace policy | 250 } // namespace policy |
OLD | NEW |