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 "components/policy/core/common/policy_loader_mac.h" | 5 #include "components/policy/core/common/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/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 using base::ScopedCFTypeRef; | 25 using base::ScopedCFTypeRef; |
26 | 26 |
27 namespace policy { | 27 namespace policy { |
28 | 28 |
29 PolicyLoaderMac::PolicyLoaderMac( | 29 PolicyLoaderMac::PolicyLoaderMac( |
30 scoped_refptr<base::SequencedTaskRunner> task_runner, | 30 scoped_refptr<base::SequencedTaskRunner> task_runner, |
31 const base::FilePath& managed_policy_path, | 31 const base::FilePath& managed_policy_path, |
32 MacPreferences* preferences) | 32 MacPreferences* preferences) |
33 : AsyncPolicyLoader(task_runner), | 33 : AsyncPolicyLoader(task_runner), |
34 preferences_(preferences), | 34 preferences_(preferences), |
35 managed_policy_path_(managed_policy_path) {} | 35 managed_policy_path_(managed_policy_path), |
| 36 application_id_(kCFPreferencesCurrentApplication) { |
| 37 } |
| 38 |
| 39 PolicyLoaderMac::PolicyLoaderMac( |
| 40 scoped_refptr<base::SequencedTaskRunner> task_runner, |
| 41 const base::FilePath& managed_policy_path, |
| 42 MacPreferences* preferences, |
| 43 CFStringRef application_id) |
| 44 : AsyncPolicyLoader(task_runner), |
| 45 preferences_(preferences), |
| 46 managed_policy_path_(managed_policy_path), |
| 47 application_id_(application_id) { |
| 48 } |
36 | 49 |
37 PolicyLoaderMac::~PolicyLoaderMac() {} | 50 PolicyLoaderMac::~PolicyLoaderMac() {} |
38 | 51 |
39 void PolicyLoaderMac::InitOnBackgroundThread() { | 52 void PolicyLoaderMac::InitOnBackgroundThread() { |
40 if (!managed_policy_path_.empty()) { | 53 if (!managed_policy_path_.empty()) { |
41 watcher_.Watch( | 54 watcher_.Watch( |
42 managed_policy_path_, false, | 55 managed_policy_path_, false, |
43 base::Bind(&PolicyLoaderMac::OnFileUpdated, base::Unretained(this))); | 56 base::Bind(&PolicyLoaderMac::OnFileUpdated, base::Unretained(this))); |
44 } | 57 } |
45 } | 58 } |
46 | 59 |
47 scoped_ptr<PolicyBundle> PolicyLoaderMac::Load() { | 60 scoped_ptr<PolicyBundle> PolicyLoaderMac::Load() { |
48 preferences_->AppSynchronize(kCFPreferencesCurrentApplication); | 61 preferences_->AppSynchronize(application_id_); |
49 scoped_ptr<PolicyBundle> bundle(new PolicyBundle()); | 62 scoped_ptr<PolicyBundle> bundle(new PolicyBundle()); |
50 | 63 |
51 // Load Chrome's policy. | 64 // Load Chrome's policy. |
52 PolicyMap& chrome_policy = | 65 PolicyMap& chrome_policy = |
53 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); | 66 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); |
54 | 67 |
55 PolicyLoadStatusSample status; | 68 PolicyLoadStatusSample status; |
56 bool policy_present = false; | 69 bool policy_present = false; |
57 const Schema* schema = | 70 const Schema* schema = |
58 schema_map()->GetSchema(PolicyNamespace(POLICY_DOMAIN_CHROME, "")); | 71 schema_map()->GetSchema(PolicyNamespace(POLICY_DOMAIN_CHROME, "")); |
59 for (Schema::Iterator it = schema->GetPropertiesIterator(); | 72 for (Schema::Iterator it = schema->GetPropertiesIterator(); |
60 !it.IsAtEnd(); it.Advance()) { | 73 !it.IsAtEnd(); it.Advance()) { |
61 base::ScopedCFTypeRef<CFStringRef> name( | 74 base::ScopedCFTypeRef<CFStringRef> name( |
62 base::SysUTF8ToCFStringRef(it.key())); | 75 base::SysUTF8ToCFStringRef(it.key())); |
63 base::ScopedCFTypeRef<CFPropertyListRef> value( | 76 base::ScopedCFTypeRef<CFPropertyListRef> value( |
64 preferences_->CopyAppValue(name, kCFPreferencesCurrentApplication)); | 77 preferences_->CopyAppValue(name, application_id_)); |
65 if (!value.get()) | 78 if (!value.get()) |
66 continue; | 79 continue; |
67 policy_present = true; | 80 policy_present = true; |
68 bool forced = | 81 bool forced = preferences_->AppValueIsForced(name, application_id_); |
69 preferences_->AppValueIsForced(name, kCFPreferencesCurrentApplication); | |
70 PolicyLevel level = forced ? POLICY_LEVEL_MANDATORY : | 82 PolicyLevel level = forced ? POLICY_LEVEL_MANDATORY : |
71 POLICY_LEVEL_RECOMMENDED; | 83 POLICY_LEVEL_RECOMMENDED; |
72 // TODO(joaodasilva): figure the policy scope. | 84 // TODO(joaodasilva): figure the policy scope. |
73 scoped_ptr<base::Value> policy = PropertyToValue(value); | 85 scoped_ptr<base::Value> policy = PropertyToValue(value); |
74 if (policy) { | 86 if (policy) { |
75 chrome_policy.Set( | 87 chrome_policy.Set( |
76 it.key(), level, POLICY_SCOPE_USER, policy.release(), NULL); | 88 it.key(), level, POLICY_SCOPE_USER, policy.release(), NULL); |
77 } else { | 89 } else { |
78 status.Add(POLICY_LOAD_STATUS_PARSE_ERROR); | 90 status.Add(POLICY_LOAD_STATUS_PARSE_ERROR); |
79 } | 91 } |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 } | 163 } |
152 } | 164 } |
153 } | 165 } |
154 | 166 |
155 void PolicyLoaderMac::OnFileUpdated(const base::FilePath& path, bool error) { | 167 void PolicyLoaderMac::OnFileUpdated(const base::FilePath& path, bool error) { |
156 if (!error) | 168 if (!error) |
157 Reload(false); | 169 Reload(false); |
158 } | 170 } |
159 | 171 |
160 } // namespace policy | 172 } // namespace policy |
OLD | NEW |