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" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
53 PolicyLoaderMac::CreateValueFromProperty( | 53 PolicyLoaderMac::CreateValueFromProperty( |
54 static_cast<CFPropertyListRef>(value)); | 54 static_cast<CFPropertyListRef>(value)); |
55 if (converted) | 55 if (converted) |
56 static_cast<base::ListValue *>(context)->Append(converted); | 56 static_cast<base::ListValue *>(context)->Append(converted); |
57 } | 57 } |
58 | 58 |
59 } // namespace | 59 } // namespace |
60 | 60 |
61 PolicyLoaderMac::PolicyLoaderMac( | 61 PolicyLoaderMac::PolicyLoaderMac( |
62 scoped_refptr<base::SequencedTaskRunner> task_runner, | 62 scoped_refptr<base::SequencedTaskRunner> task_runner, |
63 const PolicyDefinitionList* policy_list, | |
64 const base::FilePath& managed_policy_path, | 63 const base::FilePath& managed_policy_path, |
65 MacPreferences* preferences) | 64 MacPreferences* preferences) |
66 : AsyncPolicyLoader(task_runner), | 65 : AsyncPolicyLoader(task_runner), |
67 policy_list_(policy_list), | |
68 preferences_(preferences), | 66 preferences_(preferences), |
69 managed_policy_path_(managed_policy_path) {} | 67 managed_policy_path_(managed_policy_path) {} |
70 | 68 |
71 PolicyLoaderMac::~PolicyLoaderMac() {} | 69 PolicyLoaderMac::~PolicyLoaderMac() {} |
72 | 70 |
73 void PolicyLoaderMac::InitOnBackgroundThread() { | 71 void PolicyLoaderMac::InitOnBackgroundThread() { |
74 if (!managed_policy_path_.empty()) { | 72 if (!managed_policy_path_.empty()) { |
75 watcher_.Watch( | 73 watcher_.Watch( |
76 managed_policy_path_, false, | 74 managed_policy_path_, false, |
77 base::Bind(&PolicyLoaderMac::OnFileUpdated, base::Unretained(this))); | 75 base::Bind(&PolicyLoaderMac::OnFileUpdated, base::Unretained(this))); |
78 } | 76 } |
79 } | 77 } |
80 | 78 |
81 scoped_ptr<PolicyBundle> PolicyLoaderMac::Load() { | 79 scoped_ptr<PolicyBundle> PolicyLoaderMac::Load() { |
82 preferences_->AppSynchronize(kCFPreferencesCurrentApplication); | 80 preferences_->AppSynchronize(kCFPreferencesCurrentApplication); |
83 scoped_ptr<PolicyBundle> bundle(new PolicyBundle()); | 81 scoped_ptr<PolicyBundle> bundle(new PolicyBundle()); |
84 | 82 |
85 // Load Chrome's policy. | 83 // Load Chrome's policy. |
86 // TODO(joaodasilva): use the Chrome schema instead of the | |
87 // PolicyDefinitionList. | |
88 PolicyMap& chrome_policy = | 84 PolicyMap& chrome_policy = |
89 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); | 85 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); |
90 | 86 |
91 PolicyLoadStatusSample status; | 87 PolicyLoadStatusSample status; |
92 bool policy_present = false; | 88 bool policy_present = false; |
93 const PolicyDefinitionList::Entry* current; | 89 const Schema* schema = |
94 for (current = policy_list_->begin; current != policy_list_->end; ++current) { | 90 schema_map()->GetSchema(PolicyNamespace(POLICY_DOMAIN_CHROME, "")); |
bartfab (slow)
2013/11/05 18:18:33
Nit: #include "components/policy/core/common/polic
Joao da Silva
2013/11/07 20:27:27
Already in .h, for the PolicyDomain type
| |
91 for (Schema::Iterator it = schema->GetPropertiesIterator(); | |
92 !it.IsAtEnd(); it.Advance()) { | |
95 base::ScopedCFTypeRef<CFStringRef> name( | 93 base::ScopedCFTypeRef<CFStringRef> name( |
96 base::SysUTF8ToCFStringRef(current->name)); | 94 base::SysUTF8ToCFStringRef(it.key())); |
97 base::ScopedCFTypeRef<CFPropertyListRef> value( | 95 base::ScopedCFTypeRef<CFPropertyListRef> value( |
98 preferences_->CopyAppValue(name, kCFPreferencesCurrentApplication)); | 96 preferences_->CopyAppValue(name, kCFPreferencesCurrentApplication)); |
99 if (!value.get()) | 97 if (!value.get()) |
100 continue; | 98 continue; |
101 policy_present = true; | 99 policy_present = true; |
102 bool forced = | 100 bool forced = |
103 preferences_->AppValueIsForced(name, kCFPreferencesCurrentApplication); | 101 preferences_->AppValueIsForced(name, kCFPreferencesCurrentApplication); |
104 PolicyLevel level = forced ? POLICY_LEVEL_MANDATORY : | 102 PolicyLevel level = forced ? POLICY_LEVEL_MANDATORY : |
105 POLICY_LEVEL_RECOMMENDED; | 103 POLICY_LEVEL_RECOMMENDED; |
106 // TODO(joaodasilva): figure the policy scope. | 104 // TODO(joaodasilva): figure the policy scope. |
107 base::Value* policy = CreateValueFromProperty(value); | 105 base::Value* policy = CreateValueFromProperty(value); |
108 if (policy) | 106 if (policy) |
109 chrome_policy.Set(current->name, level, POLICY_SCOPE_USER, policy, NULL); | 107 chrome_policy.Set(it.key(), level, POLICY_SCOPE_USER, policy, NULL); |
110 else | 108 else |
111 status.Add(POLICY_LOAD_STATUS_PARSE_ERROR); | 109 status.Add(POLICY_LOAD_STATUS_PARSE_ERROR); |
112 } | 110 } |
113 | 111 |
114 if (!policy_present) | 112 if (!policy_present) |
115 status.Add(POLICY_LOAD_STATUS_NO_POLICY); | 113 status.Add(POLICY_LOAD_STATUS_NO_POLICY); |
116 | 114 |
117 // Load policy for the registered components. | 115 // Load policy for the registered components. |
118 LoadPolicyForDomain(POLICY_DOMAIN_EXTENSIONS, "extensions", bundle.get()); | 116 LoadPolicyForDomain(POLICY_DOMAIN_EXTENSIONS, "extensions", bundle.get()); |
119 | 117 |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
227 } | 225 } |
228 } | 226 } |
229 } | 227 } |
230 | 228 |
231 void PolicyLoaderMac::OnFileUpdated(const base::FilePath& path, bool error) { | 229 void PolicyLoaderMac::OnFileUpdated(const base::FilePath& path, bool error) { |
232 if (!error) | 230 if (!error) |
233 Reload(false); | 231 Reload(false); |
234 } | 232 } |
235 | 233 |
236 } // namespace policy | 234 } // namespace policy |
OLD | NEW |