| 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" | |
| 21 #include "chrome/browser/policy/policy_load_status.h" | 20 #include "chrome/browser/policy/policy_load_status.h" |
| 22 #include "chrome/browser/policy/policy_map.h" | 21 #include "chrome/browser/policy/policy_map.h" |
| 23 #include "chrome/browser/policy/preferences_mac.h" | 22 #include "chrome/browser/policy/preferences_mac.h" |
| 23 #include "chrome/browser/policy/schema_map.h" |
| 24 #include "components/policy/core/common/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 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 managed_policy_path_, false, | 77 managed_policy_path_, false, |
| 78 base::Bind(&PolicyLoaderMac::OnFileUpdated, base::Unretained(this))); | 78 base::Bind(&PolicyLoaderMac::OnFileUpdated, base::Unretained(this))); |
| 79 } | 79 } |
| 80 } | 80 } |
| 81 | 81 |
| 82 scoped_ptr<PolicyBundle> PolicyLoaderMac::Load() { | 82 scoped_ptr<PolicyBundle> PolicyLoaderMac::Load() { |
| 83 preferences_->AppSynchronize(kCFPreferencesCurrentApplication); | 83 preferences_->AppSynchronize(kCFPreferencesCurrentApplication); |
| 84 scoped_ptr<PolicyBundle> bundle(new PolicyBundle()); | 84 scoped_ptr<PolicyBundle> bundle(new PolicyBundle()); |
| 85 | 85 |
| 86 // Load Chrome's policy. | 86 // Load Chrome's policy. |
| 87 // TODO(joaodasilva): use a schema for Chrome once it's generated and | 87 // TODO(joaodasilva): Use the Chrome schema instead of the |
| 88 // available from a PolicyDomainDescriptor. | 88 // PolicyDefinitionList. |
| 89 PolicyMap& chrome_policy = | 89 PolicyMap& chrome_policy = |
| 90 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); | 90 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); |
| 91 | 91 |
| 92 PolicyLoadStatusSample status; | 92 PolicyLoadStatusSample status; |
| 93 bool policy_present = false; | 93 bool policy_present = false; |
| 94 const PolicyDefinitionList::Entry* current; | 94 const PolicyDefinitionList::Entry* current; |
| 95 for (current = policy_list_->begin; current != policy_list_->end; ++current) { | 95 for (current = policy_list_->begin; current != policy_list_->end; ++current) { |
| 96 base::ScopedCFTypeRef<CFStringRef> name( | 96 base::ScopedCFTypeRef<CFStringRef> name( |
| 97 base::SysUTF8ToCFStringRef(current->name)); | 97 base::SysUTF8ToCFStringRef(current->name)); |
| 98 base::ScopedCFTypeRef<CFPropertyListRef> value( | 98 base::ScopedCFTypeRef<CFPropertyListRef> value( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 109 if (policy) | 109 if (policy) |
| 110 chrome_policy.Set(current->name, level, POLICY_SCOPE_USER, policy, NULL); | 110 chrome_policy.Set(current->name, level, POLICY_SCOPE_USER, policy, NULL); |
| 111 else | 111 else |
| 112 status.Add(POLICY_LOAD_STATUS_PARSE_ERROR); | 112 status.Add(POLICY_LOAD_STATUS_PARSE_ERROR); |
| 113 } | 113 } |
| 114 | 114 |
| 115 if (!policy_present) | 115 if (!policy_present) |
| 116 status.Add(POLICY_LOAD_STATUS_NO_POLICY); | 116 status.Add(POLICY_LOAD_STATUS_NO_POLICY); |
| 117 | 117 |
| 118 // Load policy for the registered components. | 118 // Load policy for the registered components. |
| 119 static const struct { | 119 LoadPolicyForDomain(POLICY_DOMAIN_EXTENSIONS, "extensions", bundle.get()); |
| 120 PolicyDomain domain; | |
| 121 const char* domain_name; | |
| 122 } kSupportedDomains[] = { | |
| 123 { POLICY_DOMAIN_EXTENSIONS, "extensions" }, | |
| 124 }; | |
| 125 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kSupportedDomains); ++i) { | |
| 126 DescriptorMap::const_iterator it = | |
| 127 descriptor_map().find(kSupportedDomains[i].domain); | |
| 128 if (it != descriptor_map().end()) { | |
| 129 LoadPolicyForDomain( | |
| 130 it->second, kSupportedDomains[i].domain_name, bundle.get()); | |
| 131 } | |
| 132 } | |
| 133 | 120 |
| 134 return bundle.Pass(); | 121 return bundle.Pass(); |
| 135 } | 122 } |
| 136 | 123 |
| 137 base::Time PolicyLoaderMac::LastModificationTime() { | 124 base::Time PolicyLoaderMac::LastModificationTime() { |
| 138 base::PlatformFileInfo file_info; | 125 base::PlatformFileInfo file_info; |
| 139 if (!file_util::GetFileInfo(managed_policy_path_, &file_info) || | 126 if (!file_util::GetFileInfo(managed_policy_path_, &file_info) || |
| 140 file_info.is_directory) { | 127 file_info.is_directory) { |
| 141 return base::Time(); | 128 return base::Time(); |
| 142 } | 129 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 CFRangeMake(0, CFArrayGetCount(array)), | 169 CFRangeMake(0, CFArrayGetCount(array)), |
| 183 ArrayEntryToValue, | 170 ArrayEntryToValue, |
| 184 list_value); | 171 list_value); |
| 185 return list_value; | 172 return list_value; |
| 186 } | 173 } |
| 187 | 174 |
| 188 return NULL; | 175 return NULL; |
| 189 } | 176 } |
| 190 | 177 |
| 191 void PolicyLoaderMac::LoadPolicyForDomain( | 178 void PolicyLoaderMac::LoadPolicyForDomain( |
| 192 scoped_refptr<const PolicyDomainDescriptor> descriptor, | 179 PolicyDomain domain, |
| 193 const std::string& domain_name, | 180 const std::string& domain_name, |
| 194 PolicyBundle* bundle) { | 181 PolicyBundle* bundle) { |
| 195 std::string id_prefix(base::mac::BaseBundleID()); | 182 std::string id_prefix(base::mac::BaseBundleID()); |
| 196 id_prefix.append(".").append(domain_name).append("."); | 183 id_prefix.append(".").append(domain_name).append("."); |
| 197 | 184 |
| 198 for (PolicyDomainDescriptor::SchemaMap::const_iterator it_schema = | 185 const ComponentMap* components = schema_map()->GetComponents(domain); |
| 199 descriptor->components().begin(); | 186 if (!components) |
| 200 it_schema != descriptor->components().end(); ++it_schema) { | 187 return; |
| 188 |
| 189 for (ComponentMap::const_iterator it = components->begin(); |
| 190 it != components->end(); ++it) { |
| 201 PolicyMap policy; | 191 PolicyMap policy; |
| 202 LoadPolicyForComponent( | 192 LoadPolicyForComponent(id_prefix + it->first, it->second, &policy); |
| 203 id_prefix + it_schema->first, it_schema->second, &policy); | 193 if (!policy.empty()) |
| 204 if (!policy.empty()) { | 194 bundle->Get(PolicyNamespace(domain, it->first)).Swap(&policy); |
| 205 bundle->Get(PolicyNamespace(descriptor->domain(), it_schema->first)) | |
| 206 .Swap(&policy); | |
| 207 } | |
| 208 } | 195 } |
| 209 } | 196 } |
| 210 | 197 |
| 211 void PolicyLoaderMac::LoadPolicyForComponent( | 198 void PolicyLoaderMac::LoadPolicyForComponent( |
| 212 const std::string& bundle_id_string, | 199 const std::string& bundle_id_string, |
| 213 Schema schema, | 200 const Schema& schema, |
| 214 PolicyMap* policy) { | 201 PolicyMap* policy) { |
| 215 // TODO(joaodasilva): extensions may be registered in a PolicyDomainDescriptor | 202 // TODO(joaodasilva): Extensions may be registered in a ComponentMap |
| 216 // without a schema, to allow a graceful update of the Legacy Browser Support | 203 // without a schema, to allow a graceful update of the Legacy Browser Support |
| 217 // extension on Windows. Remove this check once that support is removed. | 204 // extension on Windows. Remove this check once that support is removed. |
| 218 if (!schema.valid()) | 205 if (!schema.valid()) |
| 219 return; | 206 return; |
| 220 | 207 |
| 221 base::ScopedCFTypeRef<CFStringRef> bundle_id( | 208 base::ScopedCFTypeRef<CFStringRef> bundle_id( |
| 222 base::SysUTF8ToCFStringRef(bundle_id_string)); | 209 base::SysUTF8ToCFStringRef(bundle_id_string)); |
| 223 preferences_->AppSynchronize(bundle_id); | 210 preferences_->AppSynchronize(bundle_id); |
| 224 | 211 |
| 225 for (Schema::Iterator it = schema.GetPropertiesIterator(); | 212 for (Schema::Iterator it = schema.GetPropertiesIterator(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 241 } | 228 } |
| 242 } | 229 } |
| 243 } | 230 } |
| 244 | 231 |
| 245 void PolicyLoaderMac::OnFileUpdated(const base::FilePath& path, bool error) { | 232 void PolicyLoaderMac::OnFileUpdated(const base::FilePath& path, bool error) { |
| 246 if (!error) | 233 if (!error) |
| 247 Reload(false); | 234 Reload(false); |
| 248 } | 235 } |
| 249 | 236 |
| 250 } // namespace policy | 237 } // namespace policy |
| OLD | NEW |