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.
5 #ifndef COMPONENTS_POLICY_CORE_COMMON_POLICY_NAMESPACE_H_
6 #define COMPONENTS_POLICY_CORE_COMMON_POLICY_NAMESPACE_H_
13 #include "base/containers/hash_tables.h"
14 #include "components/policy/policy_export.h"
18 // Policies are namespaced by a (PolicyDomain, ID) pair. The meaning of the ID
19 // string depends on the domain; for example, if the PolicyDomain is
20 // "extensions" then the ID identifies the extension that the policies control.
22 // The component ID for chrome policies is always the empty string.
25 // The extensions policy domain is a work in progress. Included here for
27 POLICY_DOMAIN_EXTENSIONS
,
29 // Must be the last entry.
33 // Groups a policy domain and a component ID in a single object representing
34 // a policy namespace. Objects of this class can be used as keys in std::maps.
35 struct POLICY_EXPORT PolicyNamespace
{
38 PolicyNamespace(PolicyDomain domain
, const std::string
& component_id
);
39 PolicyNamespace(const PolicyNamespace
& other
);
42 PolicyNamespace
& operator=(const PolicyNamespace
& other
);
43 bool operator<(const PolicyNamespace
& other
) const;
44 bool operator==(const PolicyNamespace
& other
) const;
45 bool operator!=(const PolicyNamespace
& other
) const;
48 std::string component_id
;
51 typedef std::vector
<PolicyNamespace
> PolicyNamespaceList
;
55 // Define a custom std::hash for PolicyNamespace so that it can be used as
56 // a key in hash_maps, and in particular in ScopedPtrHashMaps (which uses the
57 // default std::hash).
58 namespace BASE_HASH_NAMESPACE
{
61 struct hash
<policy::PolicyNamespace
> {
62 std::size_t operator()(const policy::PolicyNamespace
& ns
) const {
63 return hash
<std::string
>()(ns
.component_id
) ^ (UINT64_C(1) << ns
.domain
);
67 } // namespace BASE_HASH_NAMESPACE
69 #endif // COMPONENTS_POLICY_CORE_COMMON_POLICY_NAMESPACE_H_