Index: components/policy/core/common/policy_namespace.h |
diff --git a/components/policy/core/common/policy_namespace.h b/components/policy/core/common/policy_namespace.h |
index 86dc5866afc5f7b207080626ebd3c636fc401175..e07ec0f14acb7af59f10713290648daec326fe5c 100644 |
--- a/components/policy/core/common/policy_namespace.h |
+++ b/components/policy/core/common/policy_namespace.h |
@@ -5,9 +5,12 @@ |
#ifndef COMPONENTS_POLICY_CORE_COMMON_POLICY_NAMESPACE_H_ |
#define COMPONENTS_POLICY_CORE_COMMON_POLICY_NAMESPACE_H_ |
+#include <stdint.h> |
+ |
#include <string> |
#include <vector> |
+#include "base/containers/hash_tables.h" |
#include "components/policy/policy_export.h" |
namespace policy { |
@@ -49,4 +52,18 @@ typedef std::vector<PolicyNamespace> PolicyNamespaceList; |
} // namespace policy |
+// Define a custom std::hash for PolicyNamespace so that it can be used as |
+// a key in hash_maps, and in particular in ScopedPtrHashMaps (which uses the |
+// default std::hash). |
+namespace BASE_HASH_NAMESPACE { |
+ |
+template <> |
+struct hash<policy::PolicyNamespace> { |
+ std::size_t operator()(const policy::PolicyNamespace& ns) const { |
+ return hash<std::string>()(ns.component_id) ^ (UINT64_C(1) << ns.domain); |
+ } |
+}; |
+ |
+} // namespace BASE_HASH_NAMESPACE |
+ |
#endif // COMPONENTS_POLICY_CORE_COMMON_POLICY_NAMESPACE_H_ |