diff --git a/ipc/chromium/src/mojo/core/ports/name.cc b/ipc/chromium/src/mojo/core/ports/name.cc index 95fa50fb97a7..2911b32a8e5a 100644 --- a/ipc/chromium/src/mojo/core/ports/name.cc +++ b/ipc/chromium/src/mojo/core/ports/name.cc @@ -3,15 +3,12 @@ // found in the LICENSE file. #include "mojo/core/ports/name.h" +#include "chrome/common/ipc_message_utils.h" namespace mojo { namespace core { namespace ports { -const PortName kInvalidPortName = {0, 0}; - -const NodeName kInvalidNodeName = {0, 0}; - std::ostream& operator<<(std::ostream& stream, const Name& name) { std::ios::fmtflags flags(stream.flags()); stream << std::hex << std::uppercase << name.v1; @@ -33,3 +30,29 @@ mozilla::Logger& operator<<(mozilla::Logger& log, const Name& name) { } // namespace ports } // namespace core } // namespace mojo + +void IPC::ParamTraits::Write( + Message* aMsg, const paramType& aParam) { + WriteParam(aMsg, aParam.v1); + WriteParam(aMsg, aParam.v2); +} + +bool IPC::ParamTraits::Read(const Message* aMsg, + PickleIterator* aIter, + paramType* aResult) { + return ReadParam(aMsg, aIter, &aResult->v1) && + ReadParam(aMsg, aIter, &aResult->v2); +} + +void IPC::ParamTraits::Write( + Message* aMsg, const paramType& aParam) { + WriteParam(aMsg, aParam.v1); + WriteParam(aMsg, aParam.v2); +} + +bool IPC::ParamTraits::Read(const Message* aMsg, + PickleIterator* aIter, + paramType* aResult) { + return ReadParam(aMsg, aIter, &aResult->v1) && + ReadParam(aMsg, aIter, &aResult->v2); +} diff --git a/ipc/chromium/src/mojo/core/ports/name.h b/ipc/chromium/src/mojo/core/ports/name.h index 1085ac53c583..e51338f46b17 100644 --- a/ipc/chromium/src/mojo/core/ports/name.h +++ b/ipc/chromium/src/mojo/core/ports/name.h @@ -12,13 +12,14 @@ #include "base/logging.h" #include "mozilla/HashFunctions.h" +#include "nsHashKeys.h" namespace mojo { namespace core { namespace ports { struct Name { - Name(uint64_t v1, uint64_t v2) : v1(v1), v2(v2) {} + constexpr Name(uint64_t v1, uint64_t v2) : v1(v1), v2(v2) {} uint64_t v1, v2; }; @@ -36,41 +37,86 @@ std::ostream& operator<<(std::ostream& stream, const Name& name); mozilla::Logger& operator<<(mozilla::Logger& log, const Name& name); struct PortName : Name { - PortName() : Name(0, 0) {} - PortName(uint64_t v1, uint64_t v2) : Name(v1, v2) {} + constexpr PortName() : Name(0, 0) {} + constexpr PortName(uint64_t v1, uint64_t v2) : Name(v1, v2) {} }; -extern const PortName kInvalidPortName; +constexpr PortName kInvalidPortName{0, 0}; struct NodeName : Name { - NodeName() : Name(0, 0) {} - NodeName(uint64_t v1, uint64_t v2) : Name(v1, v2) {} + constexpr NodeName() : Name(0, 0) {} + constexpr NodeName(uint64_t v1, uint64_t v2) : Name(v1, v2) {} }; -extern const NodeName kInvalidNodeName; +constexpr NodeName kInvalidNodeName{0, 0}; } // namespace ports } // namespace core } // namespace mojo +namespace mozilla { + +template <> +inline PLDHashNumber Hash( + const mojo::core::ports::PortName& aValue) { + return mozilla::HashGeneric(aValue.v1, aValue.v2); +} + +template <> +inline PLDHashNumber Hash( + const mojo::core::ports::NodeName& aValue) { + return mozilla::HashGeneric(aValue.v1, aValue.v2); +} + +using PortNameHashKey = nsGenericHashKey; +using NodeNameHashKey = nsGenericHashKey; + +} // namespace mozilla + namespace std { template <> struct hash { std::size_t operator()(const mojo::core::ports::PortName& name) const { - // FIXME: HashGeneric only generates a 32-bit hash - return mozilla::HashGeneric(name.v1, name.v2); + // FIXME: PLDHashNumber is only 32-bits + return mozilla::Hash(name); } }; template <> struct hash { std::size_t operator()(const mojo::core::ports::NodeName& name) const { - // FIXME: HashGeneric only generates a 32-bit hash - return mozilla::HashGeneric(name.v1, name.v2); + // FIXME: PLDHashNumber is only 32-bits + return mozilla::Hash(name); } }; } // namespace std +class PickleIterator; + +namespace IPC { + +template +struct ParamTraits; +class Message; + +template <> +struct ParamTraits { + using paramType = mojo::core::ports::PortName; + static void Write(Message* aMsg, const paramType& aParam); + static bool Read(const Message* aMsg, PickleIterator* aIter, + paramType* aResult); +}; + +template <> +struct ParamTraits { + using paramType = mojo::core::ports::NodeName; + static void Write(Message* aMsg, const paramType& aParam); + static bool Read(const Message* aMsg, PickleIterator* aIter, + paramType* aResult); +}; + +} // namespace IPC + #endif // MOJO_CORE_PORTS_NAME_H_