| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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 <utility> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 9 #include "base/callback.h" | 11 #include "base/callback.h" |
| 10 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 11 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
| 12 #include "base/mac/foundation_util.h" | 14 #include "base/mac/foundation_util.h" |
| 13 #include "base/mac/scoped_cftyperef.h" | 15 #include "base/mac/scoped_cftyperef.h" |
| 14 #include "base/sequenced_task_runner.h" | 16 #include "base/sequenced_task_runner.h" |
| 15 #include "base/strings/sys_string_conversions.h" | 17 #include "base/strings/sys_string_conversions.h" |
| 16 #include "base/values.h" | 18 #include "base/values.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 PolicyLoadStatusSample status; | 73 PolicyLoadStatusSample status; |
| 72 bool policy_present = false; | 74 bool policy_present = false; |
| 73 const Schema* schema = | 75 const Schema* schema = |
| 74 schema_map()->GetSchema(PolicyNamespace(POLICY_DOMAIN_CHROME, "")); | 76 schema_map()->GetSchema(PolicyNamespace(POLICY_DOMAIN_CHROME, "")); |
| 75 for (Schema::Iterator it = schema->GetPropertiesIterator(); !it.IsAtEnd(); | 77 for (Schema::Iterator it = schema->GetPropertiesIterator(); !it.IsAtEnd(); |
| 76 it.Advance()) { | 78 it.Advance()) { |
| 77 base::ScopedCFTypeRef<CFStringRef> name( | 79 base::ScopedCFTypeRef<CFStringRef> name( |
| 78 base::SysUTF8ToCFStringRef(it.key())); | 80 base::SysUTF8ToCFStringRef(it.key())); |
| 79 base::ScopedCFTypeRef<CFPropertyListRef> value( | 81 base::ScopedCFTypeRef<CFPropertyListRef> value( |
| 80 preferences_->CopyAppValue(name, application_id_)); | 82 preferences_->CopyAppValue(name, application_id_)); |
| 81 if (!value.get()) | 83 if (!value) |
| 82 continue; | 84 continue; |
| 83 policy_present = true; | 85 policy_present = true; |
| 84 bool forced = preferences_->AppValueIsForced(name, application_id_); | 86 bool forced = preferences_->AppValueIsForced(name, application_id_); |
| 85 PolicyLevel level = | 87 PolicyLevel level = |
| 86 forced ? POLICY_LEVEL_MANDATORY : POLICY_LEVEL_RECOMMENDED; | 88 forced ? POLICY_LEVEL_MANDATORY : POLICY_LEVEL_RECOMMENDED; |
| 87 // TODO(joaodasilva): figure the policy scope. | 89 // TODO(joaodasilva): figure the policy scope. |
| 88 std::unique_ptr<base::Value> policy = PropertyToValue(value); | 90 std::unique_ptr<base::Value> policy = PropertyToValue(value); |
| 89 if (policy) { | 91 if (policy) { |
| 90 chrome_policy.Set(it.key(), level, POLICY_SCOPE_USER, | 92 chrome_policy.Set(it.key(), level, POLICY_SCOPE_USER, |
| 91 POLICY_SOURCE_PLATFORM, policy.release(), nullptr); | 93 POLICY_SOURCE_PLATFORM, std::move(policy), nullptr); |
| 92 } else { | 94 } else { |
| 93 status.Add(POLICY_LOAD_STATUS_PARSE_ERROR); | 95 status.Add(POLICY_LOAD_STATUS_PARSE_ERROR); |
| 94 } | 96 } |
| 95 } | 97 } |
| 96 | 98 |
| 97 if (!policy_present) | 99 if (!policy_present) |
| 98 status.Add(POLICY_LOAD_STATUS_NO_POLICY); | 100 status.Add(POLICY_LOAD_STATUS_NO_POLICY); |
| 99 | 101 |
| 100 // Load policy for the registered components. | 102 // Load policy for the registered components. |
| 101 LoadPolicyForDomain(POLICY_DOMAIN_EXTENSIONS, "extensions", bundle.get()); | 103 LoadPolicyForDomain(POLICY_DOMAIN_EXTENSIONS, "extensions", bundle.get()); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 base::ScopedCFTypeRef<CFStringRef> bundle_id( | 169 base::ScopedCFTypeRef<CFStringRef> bundle_id( |
| 168 base::SysUTF8ToCFStringRef(bundle_id_string)); | 170 base::SysUTF8ToCFStringRef(bundle_id_string)); |
| 169 preferences_->AppSynchronize(bundle_id); | 171 preferences_->AppSynchronize(bundle_id); |
| 170 | 172 |
| 171 for (Schema::Iterator it = schema.GetPropertiesIterator(); !it.IsAtEnd(); | 173 for (Schema::Iterator it = schema.GetPropertiesIterator(); !it.IsAtEnd(); |
| 172 it.Advance()) { | 174 it.Advance()) { |
| 173 base::ScopedCFTypeRef<CFStringRef> pref_name( | 175 base::ScopedCFTypeRef<CFStringRef> pref_name( |
| 174 base::SysUTF8ToCFStringRef(it.key())); | 176 base::SysUTF8ToCFStringRef(it.key())); |
| 175 base::ScopedCFTypeRef<CFPropertyListRef> value( | 177 base::ScopedCFTypeRef<CFPropertyListRef> value( |
| 176 preferences_->CopyAppValue(pref_name, bundle_id)); | 178 preferences_->CopyAppValue(pref_name, bundle_id)); |
| 177 if (!value.get()) | 179 if (!value) |
| 178 continue; | 180 continue; |
| 179 bool forced = preferences_->AppValueIsForced(pref_name, bundle_id); | 181 bool forced = preferences_->AppValueIsForced(pref_name, bundle_id); |
| 180 PolicyLevel level = | 182 PolicyLevel level = |
| 181 forced ? POLICY_LEVEL_MANDATORY : POLICY_LEVEL_RECOMMENDED; | 183 forced ? POLICY_LEVEL_MANDATORY : POLICY_LEVEL_RECOMMENDED; |
| 182 std::unique_ptr<base::Value> policy_value = PropertyToValue(value); | 184 std::unique_ptr<base::Value> policy_value = PropertyToValue(value); |
| 183 if (policy_value) { | 185 if (policy_value) { |
| 184 policy->Set(it.key(), level, POLICY_SCOPE_USER, POLICY_SOURCE_PLATFORM, | 186 policy->Set(it.key(), level, POLICY_SCOPE_USER, POLICY_SOURCE_PLATFORM, |
| 185 policy_value.release(), nullptr); | 187 std::move(policy_value), nullptr); |
| 186 } | 188 } |
| 187 } | 189 } |
| 188 } | 190 } |
| 189 | 191 |
| 190 void PolicyLoaderMac::OnFileUpdated(const base::FilePath& path, bool error) { | 192 void PolicyLoaderMac::OnFileUpdated(const base::FilePath& path, bool error) { |
| 191 if (!error) | 193 if (!error) |
| 192 Reload(false); | 194 Reload(false); |
| 193 } | 195 } |
| 194 | 196 |
| 195 } // namespace policy | 197 } // namespace policy |
| OLD | NEW |