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. | |
pastarmovj
2013/05/21 08:37:56
nitty nit: s/chrome/Chrome's/
Joao da Silva
2013/05/27 12:15:00
Done.
| |
102 // TODO(joaodasilva): use a schema for Chrome once it's generated and | |
103 // available from a PolicyDomainDescriptor. | |
100 PolicyMap& chrome_policy = | 104 PolicyMap& chrome_policy = |
101 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); | 105 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); |
102 | 106 |
103 PolicyLoadStatusSample status; | 107 PolicyLoadStatusSample status; |
104 bool policy_present = false; | 108 bool policy_present = false; |
105 const PolicyDefinitionList::Entry* current; | 109 const PolicyDefinitionList::Entry* current; |
106 for (current = policy_list_->begin; current != policy_list_->end; ++current) { | 110 for (current = policy_list_->begin; current != policy_list_->end; ++current) { |
107 base::mac::ScopedCFTypeRef<CFStringRef> name( | 111 base::mac::ScopedCFTypeRef<CFStringRef> name( |
108 base::SysUTF8ToCFStringRef(current->name)); | 112 base::SysUTF8ToCFStringRef(current->name)); |
109 base::mac::ScopedCFTypeRef<CFPropertyListRef> value( | 113 base::mac::ScopedCFTypeRef<CFPropertyListRef> value( |
110 preferences_->CopyAppValue(name, kCFPreferencesCurrentApplication)); | 114 preferences_->CopyAppValue(name, kCFPreferencesCurrentApplication)); |
111 if (!value.get()) | 115 if (!value.get()) |
112 continue; | 116 continue; |
113 policy_present = true; | 117 policy_present = true; |
114 bool forced = | 118 bool forced = |
115 preferences_->AppValueIsForced(name, kCFPreferencesCurrentApplication); | 119 preferences_->AppValueIsForced(name, kCFPreferencesCurrentApplication); |
116 PolicyLevel level = forced ? POLICY_LEVEL_MANDATORY : | 120 PolicyLevel level = forced ? POLICY_LEVEL_MANDATORY : |
117 POLICY_LEVEL_RECOMMENDED; | 121 POLICY_LEVEL_RECOMMENDED; |
118 // TODO(joaodasilva): figure the policy scope. | 122 // TODO(joaodasilva): figure the policy scope. |
119 base::Value* policy = CreateValueFromProperty(value); | 123 base::Value* policy = CreateValueFromProperty(value); |
120 if (policy) | 124 if (policy) |
121 chrome_policy.Set(current->name, level, POLICY_SCOPE_USER, policy); | 125 chrome_policy.Set(current->name, level, POLICY_SCOPE_USER, policy); |
122 else | 126 else |
123 status.Add(POLICY_LOAD_STATUS_PARSE_ERROR); | 127 status.Add(POLICY_LOAD_STATUS_PARSE_ERROR); |
124 } | 128 } |
125 | 129 |
126 if (!policy_present) | 130 if (!policy_present) |
127 status.Add(POLICY_LOAD_STATUS_NO_POLICY); | 131 status.Add(POLICY_LOAD_STATUS_NO_POLICY); |
128 | 132 |
133 // Load policy for the registered components. | |
134 static const struct { | |
135 PolicyDomain domain; | |
136 const char* domain_name; | |
137 } kSupportedDomains[] = { | |
138 { POLICY_DOMAIN_EXTENSIONS, "extensions" }, | |
139 }; | |
140 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kSupportedDomains); ++i) { | |
141 DescriptorMap::const_iterator it = | |
142 descriptor_map().find(kSupportedDomains[i].domain); | |
143 if (it != descriptor_map().end()) { | |
144 LoadPolicyForDomain( | |
145 it->second, kSupportedDomains[i].domain_name, bundle.get()); | |
146 } | |
147 } | |
148 | |
129 return bundle.Pass(); | 149 return bundle.Pass(); |
130 } | 150 } |
131 | 151 |
132 base::Time PolicyLoaderMac::LastModificationTime() { | 152 base::Time PolicyLoaderMac::LastModificationTime() { |
133 base::PlatformFileInfo file_info; | 153 base::PlatformFileInfo file_info; |
134 if (!file_util::GetFileInfo(managed_policy_path_, &file_info) || | 154 if (!file_util::GetFileInfo(managed_policy_path_, &file_info) || |
135 file_info.is_directory) { | 155 file_info.is_directory) { |
136 return base::Time(); | 156 return base::Time(); |
137 } | 157 } |
138 | 158 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
176 CFArrayApplyFunction(array, | 196 CFArrayApplyFunction(array, |
177 CFRangeMake(0, CFArrayGetCount(array)), | 197 CFRangeMake(0, CFArrayGetCount(array)), |
178 ArrayEntryToValue, | 198 ArrayEntryToValue, |
179 list_value); | 199 list_value); |
180 return list_value; | 200 return list_value; |
181 } | 201 } |
182 | 202 |
183 return NULL; | 203 return NULL; |
184 } | 204 } |
185 | 205 |
206 void PolicyLoaderMac::LoadPolicyForDomain( | |
207 scoped_refptr<const PolicyDomainDescriptor> descriptor, | |
208 const std::string& domain_name, | |
209 PolicyBundle* bundle) { | |
210 std::string id_prefix(base::mac::BaseBundleID()); | |
211 id_prefix.append(".").append(domain_name).append("."); | |
212 | |
213 for (PolicyDomainDescriptor::SchemaMap::const_iterator it_schema = | |
214 descriptor->components().begin(); | |
215 it_schema != descriptor->components().end(); ++it_schema) { | |
216 PolicyMap policy; | |
217 LoadPolicyForComponent( | |
218 id_prefix + it_schema->first, it_schema->second, &policy); | |
219 if (!policy.empty()) { | |
220 bundle->Get(PolicyNamespace(descriptor->domain(), it_schema->first)) | |
221 .Swap(&policy); | |
222 } | |
223 } | |
224 } | |
225 | |
226 void PolicyLoaderMac::LoadPolicyForComponent( | |
227 const std::string& bundle_id_string, | |
228 const PolicySchema* schema, | |
229 PolicyMap* policy) { | |
230 base::mac::ScopedCFTypeRef<CFStringRef> bundle_id( | |
231 base::SysUTF8ToCFStringRef(bundle_id_string)); | |
232 preferences_->AppSynchronize(bundle_id); | |
233 | |
234 const PolicySchemaMap* map = schema->GetProperties(); | |
235 if (!map) { | |
236 NOTREACHED(); | |
237 return; | |
238 } | |
239 | |
240 for (PolicySchemaMap::const_iterator it = map->begin(); | |
241 it != map->end(); ++it) { | |
242 base::mac::ScopedCFTypeRef<CFStringRef> pref_name( | |
243 base::SysUTF8ToCFStringRef(it->first)); | |
244 base::mac::ScopedCFTypeRef<CFPropertyListRef> value( | |
245 preferences_->CopyAppValue(pref_name, bundle_id)); | |
246 if (!value.get()) | |
247 continue; | |
248 bool forced = | |
249 preferences_->AppValueIsForced(pref_name, bundle_id); | |
250 PolicyLevel level = forced ? POLICY_LEVEL_MANDATORY : | |
251 POLICY_LEVEL_RECOMMENDED; | |
252 scoped_ptr<base::Value> policy_value(CreateValueFromProperty(value)); | |
253 if (policy_value) | |
254 policy->Set(it->first, level, POLICY_SCOPE_USER, policy_value.release()); | |
255 } | |
256 } | |
257 | |
186 void PolicyLoaderMac::OnFileUpdated(const base::FilePath& path, bool error) { | 258 void PolicyLoaderMac::OnFileUpdated(const base::FilePath& path, bool error) { |
187 if (!error) | 259 if (!error) |
188 Reload(false); | 260 Reload(false); |
189 } | 261 } |
190 | 262 |
191 } // namespace policy | 263 } // namespace policy |
OLD | NEW |