Bug 1397456 - Always use static name for ipc messages r=billm

Never store names in Message. One can get string names from
Message::name() or use IPC::StringFromIPCMessageType() when only
message id is available.

MozReview-Commit-ID: 15ksx6SE90c

--HG--
extra : rebase_source : 1a041dc365b7f42edd540d8c7a4dfd8912e48921
This commit is contained in:
Kan-Ru Chen 2017-09-14 16:08:57 +08:00
Родитель 6961bb1222
Коммит 9016ef6cef
7 изменённых файлов: 13 добавлений и 39 удалений

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

@ -476,7 +476,7 @@ void Pickle::EndRead(PickleIterator& iter, uint32_t ipcMsgType) const {
uint32_t latencyMs = round((mozilla::TimeStamp::Now() - iter.start_).ToMilliseconds());
if (latencyMs >= kMinTelemetryIPCReadLatencyMs) {
mozilla::Telemetry::Accumulate(mozilla::Telemetry::IPC_READ_MAIN_THREAD_LATENCY_MS,
nsDependentCString(mozilla::ipc::StringFromIPCMessageType(ipcMsgType)),
nsDependentCString(IPC::StringFromIPCMessageType(ipcMsgType)),
latencyMs);
}
}

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

@ -51,14 +51,12 @@ Message::Message()
&_header->source_event_type);
}
#endif
InitLoggingVariables();
}
Message::Message(int32_t routing_id,
msgid_t type,
uint32_t segment_capacity,
HeaderFlags flags,
const char* const aName,
bool recordWriteLatency)
: Pickle(MSG_HEADER_SZ, segment_capacity) {
MOZ_COUNT_CTOR(IPC::Message);
@ -86,7 +84,6 @@ Message::Message(int32_t routing_id,
if (recordWriteLatency) {
create_time_ = mozilla::TimeStamp::Now();
}
InitLoggingVariables(aName);
}
#ifndef MOZ_TASK_TRACER
@ -101,12 +98,10 @@ Message::Message(const char* data, int data_len)
: Pickle(MSG_HEADER_SZ_DATA, data, data_len)
{
MOZ_COUNT_CTOR(IPC::Message);
InitLoggingVariables();
}
Message::Message(Message&& other) : Pickle(mozilla::Move(other)) {
MOZ_COUNT_CTOR(IPC::Message);
InitLoggingVariables(other.name_);
#if defined(OS_POSIX)
file_descriptor_set_ = other.file_descriptor_set_.forget();
#endif
@ -115,10 +110,9 @@ Message::Message(Message&& other) : Pickle(mozilla::Move(other)) {
/*static*/ Message*
Message::IPDLMessage(int32_t routing_id,
msgid_t type,
HeaderFlags flags,
const char* const name)
HeaderFlags flags)
{
return new Message(routing_id, type, 0, flags, name, true);
return new Message(routing_id, type, 0, flags, true);
}
/*static*/ Message*
@ -143,13 +137,8 @@ Message::ForInterruptDispatchError()
return m;
}
void Message::InitLoggingVariables(const char* const aName) {
name_ = aName;
}
Message& Message::operator=(Message&& other) {
*static_cast<Pickle*>(this) = mozilla::Move(other);
InitLoggingVariables(other.name_);
#if defined(OS_POSIX)
file_descriptor_set_.swap(other.file_descriptor_set_);
#endif

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

@ -31,6 +31,9 @@ namespace IPC {
//------------------------------------------------------------------------------
// Generated by IPDL compiler
const char* StringFromIPCMessageType(uint32_t aMessageType);
class Channel;
class Message;
struct LogData;
@ -194,7 +197,6 @@ class Message : public Pickle {
msgid_t type,
uint32_t segmentCapacity = 0, // 0 for the default capacity.
HeaderFlags flags = HeaderFlags(),
const char* const name="???",
bool recordWriteLatency=false);
Message(const char* data, int data_len);
@ -210,8 +212,7 @@ class Message : public Pickle {
// code.
static Message* IPDLMessage(int32_t routing_id,
msgid_t type,
HeaderFlags flags,
const char* const name);
HeaderFlags flags);
// One-off constructors for special error-handling messages.
static Message* ForSyncDispatchError(NestedLevel level);
@ -298,11 +299,7 @@ class Message : public Pickle {
}
const char* name() const {
return name_;
}
void set_name(const char* const aName) {
name_ = aName;
return StringFromIPCMessageType(type());
}
const mozilla::TimeStamp& create_time() const {
@ -462,8 +459,6 @@ class Message : public Pickle {
}
#endif
void InitLoggingVariables(const char* const name="???");
#if defined(OS_POSIX)
// The set of file descriptors associated with this message.
RefPtr<FileDescriptorSet> file_descriptor_set_;
@ -480,8 +475,6 @@ class Message : public Pickle {
}
#endif
const char* name_;
mozilla::TimeStamp create_time_;
};

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

@ -1898,7 +1898,7 @@ MessageChannel::RunMessage(MessageTask& aTask)
NS_IMPL_ISUPPORTS_INHERITED(MessageChannel::MessageTask, CancelableRunnable, nsIRunnablePriority)
MessageChannel::MessageTask::MessageTask(MessageChannel* aChannel, Message&& aMessage)
: CancelableRunnable(StringFromIPCMessageType(aMessage.type()))
: CancelableRunnable(aMessage.name())
, mChannel(aChannel)
, mMessage(Move(aMessage))
, mScheduled(false)
@ -2505,7 +2505,7 @@ MessageChannel::MaybeHandleError(Result code, const Message& aMsg, const char* c
}
char reason[512];
const char* msgname = StringFromIPCMessageType(aMsg.type());
const char* msgname = aMsg.name();
if (msgname[0] == '?') {
SprintfLiteral(reason,"(msgtype=0x%X) %s", aMsg.type(), errorMsg);
} else {

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

@ -732,8 +732,6 @@ void
TableToArray(const nsTHashtable<nsPtrHashKey<void>>& aTable,
nsTArray<void*>& aArray);
const char* StringFromIPCMessageType(uint32_t aMessageType);
} // namespace ipc
template<typename Protocol>

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

@ -245,8 +245,7 @@ print >>ipc_msgtype_name, """
} // anonymous namespace
namespace mozilla {
namespace ipc {
namespace IPC {
const char* StringFromIPCMessageType(uint32_t aMessageType)
{
@ -277,8 +276,7 @@ print >>ipc_msgtype_name, """
}
}
} // namespace ipc
} // namespace mozilla
} // namespace IPC
"""
ipdl.writeifmodified(ipcmsgstart.getvalue(), ipcmessagestartpath)

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

@ -1705,12 +1705,10 @@ def _generateMessageConstructor(md, segmentSize, protocol, forReply=False):
if forReply:
clsname = md.replyCtorFunc()
msgid = md.replyId()
prettyName = md.prettyReplyName(protocol.name+'::')
replyEnum = 'REPLY'
else:
clsname = md.msgCtorFunc()
msgid = md.msgId()
prettyName = md.prettyMsgName(protocol.name+'::')
replyEnum = 'NOT_REPLY'
nested = md.decl.type.nested
@ -1782,7 +1780,6 @@ def _generateMessageConstructor(md, segmentSize, protocol, forReply=False):
ExprVar(msgid),
ExprLiteral.Int(int(segmentSize)),
flags,
ExprLiteral.String(prettyName),
# Pass `true` to recordWriteLatency to collect telemetry
ExprLiteral.TRUE ])))
else:
@ -1790,8 +1787,7 @@ def _generateMessageConstructor(md, segmentSize, protocol, forReply=False):
StmtReturn(ExprCall(ExprVar('IPC::Message::IPDLMessage'),
args=[ routingId,
ExprVar(msgid),
flags,
ExprLiteral.String(prettyName) ])))
flags ])))
return func