| 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/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/mac/foundation_util.h" | 10 #include "base/mac/foundation_util.h" |
| 11 #include "base/mac/scoped_cftyperef.h" | 11 #include "base/mac/scoped_cftyperef.h" |
| 12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "base/platform_file.h" | 13 #include "base/platform_file.h" |
| 14 #include "base/strings/sys_string_conversions.h" | 14 #include "base/strings/sys_string_conversions.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "chrome/browser/policy/policy_bundle.h" | 16 #include "chrome/browser/policy/policy_bundle.h" |
| 17 #include "chrome/browser/policy/policy_domain_descriptor.h" | 17 #include "chrome/browser/policy/policy_domain_descriptor.h" |
| 18 #include "chrome/browser/policy/policy_load_status.h" | 18 #include "chrome/browser/policy/policy_load_status.h" |
| 19 #include "chrome/browser/policy/policy_map.h" | 19 #include "chrome/browser/policy/policy_map.h" |
| 20 #include "chrome/browser/policy/policy_schema.h" | 20 #include "chrome/browser/policy/policy_schema.h" |
| 21 #include "chrome/browser/policy/preferences_mac.h" | 21 #include "chrome/browser/policy/preferences_mac.h" |
| 22 #include "chrome/common/chrome_paths.h" | 22 #include "chrome/common/chrome_paths.h" |
| 23 #include "policy/policy_constants.h" | 23 #include "policy/policy_constants.h" |
| 24 | 24 |
| 25 using base::mac::CFCast; | 25 using base::mac::CFCast; |
| 26 using base::mac::ScopedCFTypeRef; | 26 using base::ScopedCFTypeRef; |
| 27 | 27 |
| 28 namespace policy { | 28 namespace policy { |
| 29 | 29 |
| 30 namespace { | 30 namespace { |
| 31 | 31 |
| 32 base::FilePath GetManagedPolicyPath() { | 32 base::FilePath GetManagedPolicyPath() { |
| 33 // This constructs the path to the plist file in which Mac OS X stores the | 33 // This constructs the path to the plist file in which Mac OS X stores the |
| 34 // managed preference for the application. This is undocumented and therefore | 34 // managed preference for the application. This is undocumented and therefore |
| 35 // fragile, but if it doesn't work out, AsyncPolicyLoader has a task that | 35 // fragile, but if it doesn't work out, AsyncPolicyLoader has a task that |
| 36 // polls periodically in order to reload managed preferences later even if we | 36 // polls periodically in order to reload managed preferences later even if we |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 // Load Chrome's policy. | 101 // Load Chrome's policy. |
| 102 // TODO(joaodasilva): use a schema for Chrome once it's generated and | 102 // TODO(joaodasilva): use a schema for Chrome once it's generated and |
| 103 // available from a PolicyDomainDescriptor. | 103 // available from a PolicyDomainDescriptor. |
| 104 PolicyMap& chrome_policy = | 104 PolicyMap& chrome_policy = |
| 105 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); | 105 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); |
| 106 | 106 |
| 107 PolicyLoadStatusSample status; | 107 PolicyLoadStatusSample status; |
| 108 bool policy_present = false; | 108 bool policy_present = false; |
| 109 const PolicyDefinitionList::Entry* current; | 109 const PolicyDefinitionList::Entry* current; |
| 110 for (current = policy_list_->begin; current != policy_list_->end; ++current) { | 110 for (current = policy_list_->begin; current != policy_list_->end; ++current) { |
| 111 base::mac::ScopedCFTypeRef<CFStringRef> name( | 111 base::ScopedCFTypeRef<CFStringRef> name( |
| 112 base::SysUTF8ToCFStringRef(current->name)); | 112 base::SysUTF8ToCFStringRef(current->name)); |
| 113 base::mac::ScopedCFTypeRef<CFPropertyListRef> value( | 113 base::ScopedCFTypeRef<CFPropertyListRef> value( |
| 114 preferences_->CopyAppValue(name, kCFPreferencesCurrentApplication)); | 114 preferences_->CopyAppValue(name, kCFPreferencesCurrentApplication)); |
| 115 if (!value.get()) | 115 if (!value.get()) |
| 116 continue; | 116 continue; |
| 117 policy_present = true; | 117 policy_present = true; |
| 118 bool forced = | 118 bool forced = |
| 119 preferences_->AppValueIsForced(name, kCFPreferencesCurrentApplication); | 119 preferences_->AppValueIsForced(name, kCFPreferencesCurrentApplication); |
| 120 PolicyLevel level = forced ? POLICY_LEVEL_MANDATORY : | 120 PolicyLevel level = forced ? POLICY_LEVEL_MANDATORY : |
| 121 POLICY_LEVEL_RECOMMENDED; | 121 POLICY_LEVEL_RECOMMENDED; |
| 122 // TODO(joaodasilva): figure the policy scope. | 122 // TODO(joaodasilva): figure the policy scope. |
| 123 base::Value* policy = CreateValueFromProperty(value); | 123 base::Value* policy = CreateValueFromProperty(value); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 const std::string& bundle_id_string, | 227 const std::string& bundle_id_string, |
| 228 const PolicySchema* schema, | 228 const PolicySchema* schema, |
| 229 PolicyMap* policy) { | 229 PolicyMap* policy) { |
| 230 // TODO(joaodasilva): extensions may be registered in a PolicyDomainDescriptor | 230 // TODO(joaodasilva): extensions may be registered in a PolicyDomainDescriptor |
| 231 // without a PolicySchema, to allow a graceful update of the Legacy Browser | 231 // without a PolicySchema, to allow a graceful update of the Legacy Browser |
| 232 // Support extension on Windows. Remove this temporary check once that support | 232 // Support extension on Windows. Remove this temporary check once that support |
| 233 // is removed. | 233 // is removed. |
| 234 if (!schema) | 234 if (!schema) |
| 235 return; | 235 return; |
| 236 | 236 |
| 237 base::mac::ScopedCFTypeRef<CFStringRef> bundle_id( | 237 base::ScopedCFTypeRef<CFStringRef> bundle_id( |
| 238 base::SysUTF8ToCFStringRef(bundle_id_string)); | 238 base::SysUTF8ToCFStringRef(bundle_id_string)); |
| 239 preferences_->AppSynchronize(bundle_id); | 239 preferences_->AppSynchronize(bundle_id); |
| 240 | 240 |
| 241 const PolicySchemaMap* map = schema->GetProperties(); | 241 const PolicySchemaMap* map = schema->GetProperties(); |
| 242 if (!map) { | 242 if (!map) { |
| 243 NOTREACHED(); | 243 NOTREACHED(); |
| 244 return; | 244 return; |
| 245 } | 245 } |
| 246 | 246 |
| 247 for (PolicySchemaMap::const_iterator it = map->begin(); | 247 for (PolicySchemaMap::const_iterator it = map->begin(); |
| 248 it != map->end(); ++it) { | 248 it != map->end(); ++it) { |
| 249 base::mac::ScopedCFTypeRef<CFStringRef> pref_name( | 249 base::ScopedCFTypeRef<CFStringRef> pref_name( |
| 250 base::SysUTF8ToCFStringRef(it->first)); | 250 base::SysUTF8ToCFStringRef(it->first)); |
| 251 base::mac::ScopedCFTypeRef<CFPropertyListRef> value( | 251 base::ScopedCFTypeRef<CFPropertyListRef> value( |
| 252 preferences_->CopyAppValue(pref_name, bundle_id)); | 252 preferences_->CopyAppValue(pref_name, bundle_id)); |
| 253 if (!value.get()) | 253 if (!value.get()) |
| 254 continue; | 254 continue; |
| 255 bool forced = | 255 bool forced = |
| 256 preferences_->AppValueIsForced(pref_name, bundle_id); | 256 preferences_->AppValueIsForced(pref_name, bundle_id); |
| 257 PolicyLevel level = forced ? POLICY_LEVEL_MANDATORY : | 257 PolicyLevel level = forced ? POLICY_LEVEL_MANDATORY : |
| 258 POLICY_LEVEL_RECOMMENDED; | 258 POLICY_LEVEL_RECOMMENDED; |
| 259 scoped_ptr<base::Value> policy_value(CreateValueFromProperty(value)); | 259 scoped_ptr<base::Value> policy_value(CreateValueFromProperty(value)); |
| 260 if (policy_value) | 260 if (policy_value) |
| 261 policy->Set(it->first, level, POLICY_SCOPE_USER, policy_value.release()); | 261 policy->Set(it->first, level, POLICY_SCOPE_USER, policy_value.release()); |
| 262 } | 262 } |
| 263 } | 263 } |
| 264 | 264 |
| 265 void PolicyLoaderMac::OnFileUpdated(const base::FilePath& path, bool error) { | 265 void PolicyLoaderMac::OnFileUpdated(const base::FilePath& path, bool error) { |
| 266 if (!error) | 266 if (!error) |
| 267 Reload(false); | 267 Reload(false); |
| 268 } | 268 } |
| 269 | 269 |
| 270 } // namespace policy | 270 } // namespace policy |
| OLD | NEW |