Bug 1706374 - Part 6: Add Mozilla extensions to the Name type, r=handyman

Differential Revision: https://phabricator.services.mozilla.com/D112771
This commit is contained in:
Nika Layzell 2021-06-22 18:17:20 +00:00
Родитель 3dbeb59016
Коммит da31167de5
2 изменённых файлов: 84 добавлений и 15 удалений

Просмотреть файл

@ -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<mojo::core::ports::PortName>::Write(
Message* aMsg, const paramType& aParam) {
WriteParam(aMsg, aParam.v1);
WriteParam(aMsg, aParam.v2);
}
bool IPC::ParamTraits<mojo::core::ports::PortName>::Read(const Message* aMsg,
PickleIterator* aIter,
paramType* aResult) {
return ReadParam(aMsg, aIter, &aResult->v1) &&
ReadParam(aMsg, aIter, &aResult->v2);
}
void IPC::ParamTraits<mojo::core::ports::NodeName>::Write(
Message* aMsg, const paramType& aParam) {
WriteParam(aMsg, aParam.v1);
WriteParam(aMsg, aParam.v2);
}
bool IPC::ParamTraits<mojo::core::ports::NodeName>::Read(const Message* aMsg,
PickleIterator* aIter,
paramType* aResult) {
return ReadParam(aMsg, aIter, &aResult->v1) &&
ReadParam(aMsg, aIter, &aResult->v2);
}

Просмотреть файл

@ -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<mojo::core::ports::PortName>(
const mojo::core::ports::PortName& aValue) {
return mozilla::HashGeneric(aValue.v1, aValue.v2);
}
template <>
inline PLDHashNumber Hash<mojo::core::ports::NodeName>(
const mojo::core::ports::NodeName& aValue) {
return mozilla::HashGeneric(aValue.v1, aValue.v2);
}
using PortNameHashKey = nsGenericHashKey<mojo::core::ports::PortName>;
using NodeNameHashKey = nsGenericHashKey<mojo::core::ports::NodeName>;
} // namespace mozilla
namespace std {
template <>
struct hash<mojo::core::ports::PortName> {
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<mojo::core::ports::NodeName> {
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 <typename T>
struct ParamTraits;
class Message;
template <>
struct ParamTraits<mojo::core::ports::PortName> {
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<mojo::core::ports::NodeName> {
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_