Add a Key class
[chromium-blink-merge.git] / sandbox / mac / policy.cc
blob5493c28e4f292543cbd9df8786d05bf86e1c13ee
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "sandbox/mac/policy.h"
7 namespace sandbox {
9 Rule::Rule()
10 : result(POLICY_DECISION_INVALID),
11 substitute_port(MACH_PORT_NULL) {
14 Rule::Rule(PolicyDecision result)
15 : result(result),
16 substitute_port(MACH_PORT_NULL) {
19 Rule::Rule(mach_port_t override_port)
20 : result(POLICY_SUBSTITUTE_PORT),
21 substitute_port(override_port) {
24 bool IsPolicyValid(const BootstrapSandboxPolicy& policy) {
25 for (BootstrapSandboxPolicy::const_iterator it = policy.begin();
26 it != policy.end();
27 ++it) {
28 const Rule& rule = it->second;
29 if (!(rule.result > POLICY_DECISION_INVALID &&
30 rule.result < POLICY_DECISION_LAST)) {
31 return false;
33 if (rule.result == POLICY_SUBSTITUTE_PORT) {
34 if (rule.substitute_port == MACH_PORT_NULL)
35 return false;
36 } else {
37 if (rule.substitute_port != MACH_PORT_NULL)
38 return false;
41 return true;
44 } // namespace sandbox