Chromium Code Reviews| 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 <string> | |
| 8 | |
| 9 #include "base/bind.h" | 7 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 11 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 12 #include "base/mac/foundation_util.h" | 10 #include "base/mac/foundation_util.h" |
| 13 #include "base/mac/scoped_cftyperef.h" | 11 #include "base/mac/scoped_cftyperef.h" |
| 14 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 15 #include "base/platform_file.h" | 13 #include "base/platform_file.h" |
| 16 #include "base/strings/sys_string_conversions.h" | 14 #include "base/strings/sys_string_conversions.h" |
| 17 #include "base/values.h" | 15 #include "base/values.h" |
| 18 #include "chrome/browser/policy/policy_bundle.h" | 16 #include "chrome/browser/policy/policy_bundle.h" |
| 17 #include "chrome/browser/policy/policy_domain_descriptor.h" | |
| 19 #include "chrome/browser/policy/policy_load_status.h" | 18 #include "chrome/browser/policy/policy_load_status.h" |
| 20 #include "chrome/browser/policy/policy_map.h" | 19 #include "chrome/browser/policy/policy_map.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::mac::ScopedCFTypeRef; |
| 27 | 27 |
| 28 namespace policy { | 28 namespace policy { |
| 29 | 29 |
| 30 namespace { | 30 namespace { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 90 if (!managed_policy_path_.empty()) { | 90 if (!managed_policy_path_.empty()) { |
| 91 watcher_.Watch( | 91 watcher_.Watch( |
| 92 managed_policy_path_, false, | 92 managed_policy_path_, false, |
| 93 base::Bind(&PolicyLoaderMac::OnFileUpdated, base::Unretained(this))); | 93 base::Bind(&PolicyLoaderMac::OnFileUpdated, base::Unretained(this))); |
| 94 } | 94 } |
| 95 } | 95 } |
| 96 | 96 |
| 97 scoped_ptr<PolicyBundle> PolicyLoaderMac::Load() { | 97 scoped_ptr<PolicyBundle> PolicyLoaderMac::Load() { |
| 98 preferences_->AppSynchronize(kCFPreferencesCurrentApplication); | 98 preferences_->AppSynchronize(kCFPreferencesCurrentApplication); |
| 99 scoped_ptr<PolicyBundle> bundle(new PolicyBundle()); | 99 scoped_ptr<PolicyBundle> bundle(new PolicyBundle()); |
| 100 | |
| 101 // Load chrome policy. | |
|
Mattias Nissler (ping if slow)
2013/05/15 10:42:14
I guess that this could use a TODO explaining that
Joao da Silva
2013/05/19 13:22:01
Done.
| |
| 100 PolicyMap& chrome_policy = | 102 PolicyMap& chrome_policy = |
| 101 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); | 103 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); |
| 102 | 104 |
| 103 PolicyLoadStatusSample status; | 105 PolicyLoadStatusSample status; |
| 104 bool policy_present = false; | 106 bool policy_present = false; |
| 105 const PolicyDefinitionList::Entry* current; | 107 const PolicyDefinitionList::Entry* current; |
| 106 for (current = policy_list_->begin; current != policy_list_->end; ++current) { | 108 for (current = policy_list_->begin; current != policy_list_->end; ++current) { |
| 107 base::mac::ScopedCFTypeRef<CFStringRef> name( | 109 base::mac::ScopedCFTypeRef<CFStringRef> name( |
| 108 base::SysUTF8ToCFStringRef(current->name)); | 110 base::SysUTF8ToCFStringRef(current->name)); |
| 109 base::mac::ScopedCFTypeRef<CFPropertyListRef> value( | 111 base::mac::ScopedCFTypeRef<CFPropertyListRef> value( |
| 110 preferences_->CopyAppValue(name, kCFPreferencesCurrentApplication)); | 112 preferences_->CopyAppValue(name, kCFPreferencesCurrentApplication)); |
| 111 if (!value.get()) | 113 if (!value.get()) |
| 112 continue; | 114 continue; |
| 113 policy_present = true; | 115 policy_present = true; |
| 114 bool forced = | 116 bool forced = |
| 115 preferences_->AppValueIsForced(name, kCFPreferencesCurrentApplication); | 117 preferences_->AppValueIsForced(name, kCFPreferencesCurrentApplication); |
| 116 PolicyLevel level = forced ? POLICY_LEVEL_MANDATORY : | 118 PolicyLevel level = forced ? POLICY_LEVEL_MANDATORY : |
| 117 POLICY_LEVEL_RECOMMENDED; | 119 POLICY_LEVEL_RECOMMENDED; |
| 118 // TODO(joaodasilva): figure the policy scope. | 120 // TODO(joaodasilva): figure the policy scope. |
| 119 base::Value* policy = CreateValueFromProperty(value); | 121 base::Value* policy = CreateValueFromProperty(value); |
| 120 if (policy) | 122 if (policy) |
| 121 chrome_policy.Set(current->name, level, POLICY_SCOPE_USER, policy); | 123 chrome_policy.Set(current->name, level, POLICY_SCOPE_USER, policy); |
| 122 else | 124 else |
| 123 status.Add(POLICY_LOAD_STATUS_PARSE_ERROR); | 125 status.Add(POLICY_LOAD_STATUS_PARSE_ERROR); |
| 124 } | 126 } |
| 125 | 127 |
| 126 if (!policy_present) | 128 if (!policy_present) |
| 127 status.Add(POLICY_LOAD_STATUS_NO_POLICY); | 129 status.Add(POLICY_LOAD_STATUS_NO_POLICY); |
| 128 | 130 |
| 131 // Load policy for the registered components. | |
| 132 std::map<PolicyDomain, std::string> supported_domains; | |
| 133 supported_domains[POLICY_DOMAIN_EXTENSIONS] = "extensions"; | |
|
Mattias Nissler (ping if slow)
2013/05/15 10:42:14
I guess this could be factored into a helper funct
Joao da Silva
2013/05/19 13:22:01
Done.
| |
| 134 for (DescriptorMap::const_iterator it_descriptors = descriptor_map().begin(); | |
| 135 it_descriptors != descriptor_map().end(); ++it_descriptors) { | |
| 136 scoped_refptr<const PolicyDomainDescriptor> descriptor = | |
| 137 it_descriptors->second; | |
| 138 const std::string& domain = supported_domains[descriptor->domain()]; | |
| 139 if (domain.empty()) | |
| 140 continue; | |
| 141 std::string id_prefix(base::mac::BaseBundleID()); | |
| 142 id_prefix.append(".").append(domain).append("."); | |
| 143 | |
| 144 for (PolicyDomainDescriptor::SchemaMap::const_iterator it_schema = | |
| 145 descriptor->components().begin(); | |
| 146 it_schema != descriptor->components().end(); ++it_schema) { | |
| 147 PolicyMap policy; | |
| 148 LoadComponentPolicy( | |
| 149 id_prefix + it_schema->first, it_schema->second, &policy); | |
| 150 if (!policy.empty()) { | |
| 151 bundle->Get(PolicyNamespace(descriptor->domain(), it_schema->first)) | |
| 152 .Swap(&policy); | |
| 153 } | |
| 154 } | |
| 155 } | |
| 156 | |
| 129 return bundle.Pass(); | 157 return bundle.Pass(); |
| 130 } | 158 } |
| 131 | 159 |
| 132 base::Time PolicyLoaderMac::LastModificationTime() { | 160 base::Time PolicyLoaderMac::LastModificationTime() { |
| 133 base::PlatformFileInfo file_info; | 161 base::PlatformFileInfo file_info; |
| 134 if (!file_util::GetFileInfo(managed_policy_path_, &file_info) || | 162 if (!file_util::GetFileInfo(managed_policy_path_, &file_info) || |
| 135 file_info.is_directory) { | 163 file_info.is_directory) { |
| 136 return base::Time(); | 164 return base::Time(); |
| 137 } | 165 } |
| 138 | 166 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 176 CFArrayApplyFunction(array, | 204 CFArrayApplyFunction(array, |
| 177 CFRangeMake(0, CFArrayGetCount(array)), | 205 CFRangeMake(0, CFArrayGetCount(array)), |
| 178 ArrayEntryToValue, | 206 ArrayEntryToValue, |
| 179 list_value); | 207 list_value); |
| 180 return list_value; | 208 return list_value; |
| 181 } | 209 } |
| 182 | 210 |
| 183 return NULL; | 211 return NULL; |
| 184 } | 212 } |
| 185 | 213 |
| 214 void PolicyLoaderMac::LoadComponentPolicy(const std::string& bundle_id_string, | |
| 215 const PolicySchema* schema, | |
| 216 PolicyMap* policy) { | |
| 217 base::mac::ScopedCFTypeRef<CFStringRef> bundle_id( | |
| 218 base::SysUTF8ToCFStringRef(bundle_id_string)); | |
| 219 preferences_->AppSynchronize(bundle_id); | |
| 220 | |
| 221 const PolicySchema::TypeMap& types = schema->type_map(); | |
| 222 for (PolicySchema::TypeMap::const_iterator it_type = types.begin(); | |
| 223 it_type != types.end(); ++it_type) { | |
| 224 base::mac::ScopedCFTypeRef<CFStringRef> pref_name( | |
| 225 base::SysUTF8ToCFStringRef(it_type->first)); | |
| 226 base::mac::ScopedCFTypeRef<CFPropertyListRef> value( | |
| 227 preferences_->CopyAppValue(pref_name, bundle_id)); | |
| 228 if (!value.get()) | |
| 229 continue; | |
| 230 bool forced = | |
| 231 preferences_->AppValueIsForced(pref_name, bundle_id); | |
| 232 if (!forced) | |
| 233 continue; | |
| 234 scoped_ptr<base::Value> policy_value(CreateValueFromProperty(value)); | |
| 235 if (policy_value && policy_value->IsType(it_type->second)) { | |
| 236 policy->Set(it_type->first, POLICY_LEVEL_MANDATORY, | |
|
Mattias Nissler (ping if slow)
2013/05/15 10:42:14
mandatory vs. recommended policy level?
Joao da Silva
2013/05/19 13:22:01
Done.
| |
| 237 POLICY_SCOPE_USER, policy_value.release()); | |
| 238 } | |
| 239 } | |
| 240 } | |
| 241 | |
| 186 void PolicyLoaderMac::OnFileUpdated(const base::FilePath& path, bool error) { | 242 void PolicyLoaderMac::OnFileUpdated(const base::FilePath& path, bool error) { |
| 187 if (!error) | 243 if (!error) |
| 188 Reload(false); | 244 Reload(false); |
| 189 } | 245 } |
| 190 | 246 |
| 191 } // namespace policy | 247 } // namespace policy |
| OLD | NEW |