From 967d4da9ae7ec0e481c24d00ca1ddb033d76639f Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Sat, 25 Aug 2012 01:25:08 -0700 Subject: [PATCH] Bug 636063, part 2: Backend support for |compress|d messages. r=bent --- ipc/chromium/src/chrome/common/ipc_message.cc | 4 +++- ipc/chromium/src/chrome/common/ipc_message.h | 14 +++++++++++++- ipc/ipdl/ipdl/lower.py | 13 ++++++++++--- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/ipc/chromium/src/chrome/common/ipc_message.cc b/ipc/chromium/src/chrome/common/ipc_message.cc index 65db523526e9..66e269cf0e06 100644 --- a/ipc/chromium/src/chrome/common/ipc_message.cc +++ b/ipc/chromium/src/chrome/common/ipc_message.cc @@ -28,11 +28,13 @@ Message::Message() } Message::Message(int32 routing_id, msgid_t type, PriorityValue priority, - const char* const name) + MessageCompression compression, const char* const name) : Pickle(sizeof(Header)) { header()->routing = routing_id; header()->type = type; header()->flags = priority; + if (compression == COMPRESSION_ENABLED) + header()->flags |= COMPRESS_BIT; #if defined(OS_POSIX) header()->num_fds = 0; #endif diff --git a/ipc/chromium/src/chrome/common/ipc_message.h b/ipc/chromium/src/chrome/common/ipc_message.h index d59ad4451b8c..8e7f1d81b2ef 100644 --- a/ipc/chromium/src/chrome/common/ipc_message.h +++ b/ipc/chromium/src/chrome/common/ipc_message.h @@ -54,6 +54,11 @@ class Message : public Pickle { PRIORITY_HIGH }; + enum MessageCompression { + COMPRESSION_NONE, + COMPRESSION_ENABLED + }; + virtual ~Message(); Message(); @@ -61,6 +66,7 @@ class Message : public Pickle { // Initialize a message with a user-defined type, priority value, and // destination WebView ID. Message(int32 routing_id, msgid_t type, PriorityValue priority, + MessageCompression compression = COMPRESSION_NONE, const char* const name="???"); // Initializes a message from a const block of data. The data is not copied; @@ -85,6 +91,11 @@ class Message : public Pickle { return (header()->flags & RPC_BIT) != 0; } + // True if compression is enabled for this message. + bool compress() const { + return (header()->flags & COMPRESS_BIT) != 0; + } + // Set this on a reply to a synchronous message. void set_reply() { header()->flags |= REPLY_BIT; @@ -263,7 +274,8 @@ class Message : public Pickle { UNBLOCK_BIT = 0x0020, PUMPING_MSGS_BIT= 0x0040, HAS_SENT_TIME_BIT = 0x0080, - RPC_BIT = 0x0100 + RPC_BIT = 0x0100, + COMPRESS_BIT = 0x0200 }; #pragma pack(push, 2) diff --git a/ipc/ipdl/ipdl/lower.py b/ipc/ipdl/ipdl/lower.py index 54683d59f06d..9e2a30e7c057 100644 --- a/ipc/ipdl/ipdl/lower.py +++ b/ipc/ipdl/ipdl/lower.py @@ -1550,13 +1550,15 @@ class _GenerateProtocolCode(ipdl.ast.Visitor): for md in p.messageDecls: ns.addstmts([ _generateMessageClass(md.msgClass(), md.msgId(), - typedefs, md.prettyMsgName(p.name+'::')), + typedefs, md.prettyMsgName(p.name+'::'), + md.decl.type.compress), Whitespace.NL ]) if md.hasReply(): ns.addstmts([ _generateMessageClass( md.replyClass(), md.replyId(), - typedefs, md.prettyReplyName(p.name+'::')), + typedefs, md.prettyReplyName(p.name+'::'), + md.decl.type.compress), Whitespace.NL ]) ns.addstmts([ Whitespace.NL, Whitespace.NL ]) @@ -1744,7 +1746,7 @@ class _GenerateProtocolCode(ipdl.ast.Visitor): ##-------------------------------------------------- -def _generateMessageClass(clsname, msgid, typedefs, prettyName): +def _generateMessageClass(clsname, msgid, typedefs, prettyName, compress): cls = Class(name=clsname, inherits=[ Inherit(Type('IPC::Message')) ]) cls.addstmt(Label.PRIVATE) cls.addstmts(typedefs) @@ -1757,12 +1759,17 @@ def _generateMessageClass(clsname, msgid, typedefs, prettyName): cls.addstmt(StmtDecl(Decl(idenum, ''))) # make the message constructor + if compress: + compression = ExprVar('COMPRESSION_ENABLED') + else: + compression = ExprVar('COMPRESSION_NONE') ctor = ConstructorDefn( ConstructorDecl(clsname), memberinits=[ ExprMemberInit(ExprVar('IPC::Message'), [ ExprVar('MSG_ROUTING_NONE'), ExprVar('ID'), ExprVar('PRIORITY_NORMAL'), + compression, ExprLiteral.String(prettyName) ]) ]) cls.addstmts([ ctor, Whitespace.NL ])