| 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 "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_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 } | 53 } |
| 54 | 54 |
| 55 void PolicyLoaderMac::InitOnBackgroundThread() { | 55 void PolicyLoaderMac::InitOnBackgroundThread() { |
| 56 if (!managed_policy_path_.empty()) { | 56 if (!managed_policy_path_.empty()) { |
| 57 watcher_.Watch( | 57 watcher_.Watch( |
| 58 managed_policy_path_, false, | 58 managed_policy_path_, false, |
| 59 base::Bind(&PolicyLoaderMac::OnFileUpdated, base::Unretained(this))); | 59 base::Bind(&PolicyLoaderMac::OnFileUpdated, base::Unretained(this))); |
| 60 } | 60 } |
| 61 } | 61 } |
| 62 | 62 |
| 63 scoped_ptr<PolicyBundle> PolicyLoaderMac::Load() { | 63 std::unique_ptr<PolicyBundle> PolicyLoaderMac::Load() { |
| 64 preferences_->AppSynchronize(application_id_); | 64 preferences_->AppSynchronize(application_id_); |
| 65 scoped_ptr<PolicyBundle> bundle(new PolicyBundle()); | 65 std::unique_ptr<PolicyBundle> bundle(new PolicyBundle()); |
| 66 | 66 |
| 67 // Load Chrome's policy. | 67 // Load Chrome's policy. |
| 68 PolicyMap& chrome_policy = | 68 PolicyMap& chrome_policy = |
| 69 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); | 69 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); |
| 70 | 70 |
| 71 PolicyLoadStatusSample status; | 71 PolicyLoadStatusSample status; |
| 72 bool policy_present = false; | 72 bool policy_present = false; |
| 73 const Schema* schema = | 73 const Schema* schema = |
| 74 schema_map()->GetSchema(PolicyNamespace(POLICY_DOMAIN_CHROME, "")); | 74 schema_map()->GetSchema(PolicyNamespace(POLICY_DOMAIN_CHROME, "")); |
| 75 for (Schema::Iterator it = schema->GetPropertiesIterator(); !it.IsAtEnd(); | 75 for (Schema::Iterator it = schema->GetPropertiesIterator(); !it.IsAtEnd(); |
| 76 it.Advance()) { | 76 it.Advance()) { |
| 77 base::ScopedCFTypeRef<CFStringRef> name( | 77 base::ScopedCFTypeRef<CFStringRef> name( |
| 78 base::SysUTF8ToCFStringRef(it.key())); | 78 base::SysUTF8ToCFStringRef(it.key())); |
| 79 base::ScopedCFTypeRef<CFPropertyListRef> value( | 79 base::ScopedCFTypeRef<CFPropertyListRef> value( |
| 80 preferences_->CopyAppValue(name, application_id_)); | 80 preferences_->CopyAppValue(name, application_id_)); |
| 81 if (!value.get()) | 81 if (!value.get()) |
| 82 continue; | 82 continue; |
| 83 policy_present = true; | 83 policy_present = true; |
| 84 bool forced = preferences_->AppValueIsForced(name, application_id_); | 84 bool forced = preferences_->AppValueIsForced(name, application_id_); |
| 85 PolicyLevel level = | 85 PolicyLevel level = |
| 86 forced ? POLICY_LEVEL_MANDATORY : POLICY_LEVEL_RECOMMENDED; | 86 forced ? POLICY_LEVEL_MANDATORY : POLICY_LEVEL_RECOMMENDED; |
| 87 // TODO(joaodasilva): figure the policy scope. | 87 // TODO(joaodasilva): figure the policy scope. |
| 88 scoped_ptr<base::Value> policy = PropertyToValue(value); | 88 std::unique_ptr<base::Value> policy = PropertyToValue(value); |
| 89 if (policy) { | 89 if (policy) { |
| 90 chrome_policy.Set(it.key(), level, POLICY_SCOPE_USER, | 90 chrome_policy.Set(it.key(), level, POLICY_SCOPE_USER, |
| 91 POLICY_SOURCE_PLATFORM, policy.release(), nullptr); | 91 POLICY_SOURCE_PLATFORM, policy.release(), nullptr); |
| 92 } else { | 92 } else { |
| 93 status.Add(POLICY_LOAD_STATUS_PARSE_ERROR); | 93 status.Add(POLICY_LOAD_STATUS_PARSE_ERROR); |
| 94 } | 94 } |
| 95 } | 95 } |
| 96 | 96 |
| 97 if (!policy_present) | 97 if (!policy_present) |
| 98 status.Add(POLICY_LOAD_STATUS_NO_POLICY); | 98 status.Add(POLICY_LOAD_STATUS_NO_POLICY); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 it.Advance()) { | 172 it.Advance()) { |
| 173 base::ScopedCFTypeRef<CFStringRef> pref_name( | 173 base::ScopedCFTypeRef<CFStringRef> pref_name( |
| 174 base::SysUTF8ToCFStringRef(it.key())); | 174 base::SysUTF8ToCFStringRef(it.key())); |
| 175 base::ScopedCFTypeRef<CFPropertyListRef> value( | 175 base::ScopedCFTypeRef<CFPropertyListRef> value( |
| 176 preferences_->CopyAppValue(pref_name, bundle_id)); | 176 preferences_->CopyAppValue(pref_name, bundle_id)); |
| 177 if (!value.get()) | 177 if (!value.get()) |
| 178 continue; | 178 continue; |
| 179 bool forced = preferences_->AppValueIsForced(pref_name, bundle_id); | 179 bool forced = preferences_->AppValueIsForced(pref_name, bundle_id); |
| 180 PolicyLevel level = | 180 PolicyLevel level = |
| 181 forced ? POLICY_LEVEL_MANDATORY : POLICY_LEVEL_RECOMMENDED; | 181 forced ? POLICY_LEVEL_MANDATORY : POLICY_LEVEL_RECOMMENDED; |
| 182 scoped_ptr<base::Value> policy_value = PropertyToValue(value); | 182 std::unique_ptr<base::Value> policy_value = PropertyToValue(value); |
| 183 if (policy_value) { | 183 if (policy_value) { |
| 184 policy->Set(it.key(), level, POLICY_SCOPE_USER, POLICY_SOURCE_PLATFORM, | 184 policy->Set(it.key(), level, POLICY_SCOPE_USER, POLICY_SOURCE_PLATFORM, |
| 185 policy_value.release(), nullptr); | 185 policy_value.release(), nullptr); |
| 186 } | 186 } |
| 187 } | 187 } |
| 188 } | 188 } |
| 189 | 189 |
| 190 void PolicyLoaderMac::OnFileUpdated(const base::FilePath& path, bool error) { | 190 void PolicyLoaderMac::OnFileUpdated(const base::FilePath& path, bool error) { |
| 191 if (!error) | 191 if (!error) |
| 192 Reload(false); | 192 Reload(false); |
| 193 } | 193 } |
| 194 | 194 |
| 195 } // namespace policy | 195 } // namespace policy |
| OLD | NEW |