• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 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.
4 
5 #ifndef COMPONENTS_POLICY_CORE_COMMON_POLICY_NAMESPACE_H_
6 #define COMPONENTS_POLICY_CORE_COMMON_POLICY_NAMESPACE_H_
7 
8 #include <stddef.h>
9 #include <stdint.h>
10 
11 #include <string>
12 #include <vector>
13 
14 #include "base/containers/hash_tables.h"
15 #include "components/policy/policy_export.h"
16 
17 namespace policy {
18 
19 // Policies are namespaced by a (PolicyDomain, ID) pair. The meaning of the ID
20 // string depends on the domain; for example, if the PolicyDomain is
21 // "extensions" then the ID identifies the extension that the policies control.
22 enum PolicyDomain {
23   // The component ID for chrome policies is always the empty string.
24   POLICY_DOMAIN_CHROME,
25 
26   // The component ID for the extension policies is equal to the extension ID.
27   POLICY_DOMAIN_EXTENSIONS,
28 
29   // The namespace that corresponds to the policies for extensions running
30   // under Chrome OS signin profile. The component ID is equal to the extension
31   // ID.
32   POLICY_DOMAIN_SIGNIN_EXTENSIONS,
33 
34   // Must be the last entry.
35   POLICY_DOMAIN_SIZE,
36 };
37 
38 // Groups a policy domain and a component ID in a single object representing
39 // a policy namespace. Objects of this class can be used as keys in std::maps.
40 struct POLICY_EXPORT PolicyNamespace {
41   PolicyNamespace();
42   PolicyNamespace(PolicyDomain domain, const std::string& component_id);
43   PolicyNamespace(const PolicyNamespace& other);
44   ~PolicyNamespace();
45 
46   PolicyNamespace& operator=(const PolicyNamespace& other);
47   bool operator<(const PolicyNamespace& other) const;
48   bool operator==(const PolicyNamespace& other) const;
49   bool operator!=(const PolicyNamespace& other) const;
50 
51   PolicyDomain domain;
52   std::string component_id;
53 };
54 
55 typedef std::vector<PolicyNamespace> PolicyNamespaceList;
56 
57 struct PolicyNamespaceHash {
operatorPolicyNamespaceHash58   size_t operator()(const policy::PolicyNamespace& ns) const {
59     return std::hash<std::string>()(ns.component_id) ^
60            (UINT64_C(1) << ns.domain);
61   }
62 };
63 
64 }  // namespace policy
65 
66 #endif  // COMPONENTS_POLICY_CORE_COMMON_POLICY_NAMESPACE_H_
67