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