Changeset 84173 in webkit


Ignore:
Timestamp:
Apr 18, 2011 1:04:57 PM (13 years ago)
Author:
andersca@apple.com
Message:

2011-04-18 Anders Carlsson <andersca@apple.com>

Reviewed by Adam Roben.

Finish implementing delayed sync replies in the CoreIPC message generator
https://bugs.webkit.org/show_bug.cgi?id=58814

Put the DelayedReply function definitions in the .cpp file and fix bugs found by
actually trying to compile the generated files.

  • Scripts/webkit2/messages.py:
  • Scripts/webkit2/messages_unittest.py:
Location:
trunk/Source/WebKit2
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r84153 r84173  
     12011-04-18  Anders Carlsson  <andersca@apple.com>
     2
     3        Reviewed by Adam Roben.
     4
     5        Finish implementing delayed sync replies in the CoreIPC message generator
     6        https://bugs.webkit.org/show_bug.cgi?id=58814
     7
     8        Put the DelayedReply function definitions in the .cpp file and fix bugs found by
     9        actually trying to compile the generated files.
     10
     11        * Scripts/webkit2/messages.py:
     12        * Scripts/webkit2/messages_unittest.py:
     13
    1142011-04-18  Anders Carlsson  <andersca@apple.com>
    215
  • trunk/Source/WebKit2/Scripts/webkit2/messages.py

    r83350 r84173  
    9595                if attributes_string:
    9696                    attributes = frozenset(attributes_string.split())
    97                     delayed = "Delayed" in attributes
     97                    is_delayed = "Delayed" in attributes
    9898                    dispatch_on_connection_queue = "DispatchOnConnectionQueue" in attributes
    9999                else:
    100                     delayed = False
     100                    is_delayed = False
    101101                    dispatch_on_connection_queue = False
    102102
     
    108108                    reply_parameters = None
    109109
    110                 messages.append(Message(name, parameters, reply_parameters, delayed, dispatch_on_connection_queue, condition))
     110                messages.append(Message(name, parameters, reply_parameters, is_delayed, dispatch_on_connection_queue, condition))
    111111        return MessageReceiver(destination, messages, master_condition)
    112112
    113113
    114114class Message(object):
    115     def __init__(self, name, parameters, reply_parameters, delayed, dispatch_on_connection_queue, condition):
     115    def __init__(self, name, parameters, reply_parameters, is_delayed, dispatch_on_connection_queue, condition):
    116116        self.name = name
    117117        self.parameters = parameters
    118118        self.reply_parameters = reply_parameters
    119119        if self.reply_parameters is not None:
    120             self.delayed = delayed
     120            self.is_delayed = is_delayed
    121121        self.dispatch_on_connection_queue = dispatch_on_connection_queue
    122122        self.condition = condition
     
    225225    result.append('    static const Kind messageID = %s;\n' % message.id())
    226226    if message.reply_parameters != None:
    227         if message.delayed:
     227        if message.is_delayed:
    228228            send_parameters = [(function_parameter_type(x.type), x.name) for x in message.reply_parameters]
    229             result.append('    struct DelayedReply {\n')
    230             result.append('        DelayedReply(PassRefPtr<CoreIPC::Connection> connection, PassOwnPtr<CoreIPC::ArgumentDecoder> arguments)\n')
    231             result.append('            : m_connection(connection)\n')
    232             result.append('            , m_arguments(arguments)\n')
    233             result.append('        {\n')
    234             result.append('        }\n')
     229            result.append('    struct DelayedReply : public ThreadSafeRefCounted<DelayedReply> {\n')
     230            result.append('        DelayedReply(PassRefPtr<CoreIPC::Connection>, PassOwnPtr<CoreIPC::ArgumentEncoder>);\n')
     231            result.append('        ~DelayedReply();\n')
    235232            result.append('\n')
    236             result.append('        bool send(%s)\n' % ', '.join([' '.join(x) for x in send_parameters]))
    237             result.append('        {\n')
    238             result.append('            ASSERT(m_arguments);\n')
    239             result += ['            m_arguments->encode(%s);\n' % x.name for x in message.reply_parameters]
    240             result.append('            bool result = m_connection->sendSyncReply(m_arguments.release());\n')
    241             result.append('            m_connection = nullptr;\n')
    242             result.append('            return result;\n')
    243             result.append('        }\n')
     233            result.append('        bool send(%s);\n' % ', '.join([' '.join(x) for x in send_parameters]))
    244234            result.append('\n')
    245235            result.append('    private:\n')
    246236            result.append('        RefPtr<CoreIPC::Connection> m_connection;\n')
    247             result.append('        OwnPtr<CoreIPC::ArgumentDecoder> m_arguments;\n')
     237            result.append('        OwnPtr<CoreIPC::ArgumentEncoder> m_arguments;\n')
    248238            result.append('    };\n\n')
    249         else:
    250             result.append('    typedef %s Reply;\n' % reply_type(message))
     239
     240        result.append('    typedef %s Reply;\n' % reply_type(message))
    251241
    252242    result.append('    typedef %s DecodeType;\n' % decode_type(message))
     
    310300    ])
    311301
     302    for message in receiver.messages:
     303        if message.reply_parameters != None and message.is_delayed:
     304            headers.add('<wtf/ThreadSafeRefCounted.h>')
     305            types_by_namespace['CoreIPC'].update(['ArgumentEncoder', 'Connection'])
     306
    312307    for parameter in receiver.iterparameters():
    313308        type = parameter.type
     
    396391def sync_case_statement(receiver, message):
    397392    dispatch_function = 'handleMessage'
     393    if message.is_delayed:
     394        dispatch_function += 'Delayed'
    398395    if message.is_variadic:
    399396        dispatch_function += 'Variadic'
     
    401398    result = []
    402399    result.append('    case Messages::%s::%s:\n' % (receiver.name, message.id()))
    403     result.append('        CoreIPC::%s<Messages::%s::%s>(arguments, reply, this, &%s);\n' % (dispatch_function, receiver.name, message.name, handler_function(receiver, message)))
    404     # FIXME: Handle delayed replies
    405     result.append('        return CoreIPC::AutomaticReply;\n')
     400    result.append('        CoreIPC::%s<Messages::%s::%s>(%sarguments, reply, this, &%s);\n' % (dispatch_function, receiver.name, message.name, 'connection, ' if message.is_delayed else '', handler_function(receiver, message)))
     401
     402    if message.is_delayed:
     403        result.append('        return CoreIPC::ManualReply;\n')
     404    else:
     405        result.append('        return CoreIPC::AutomaticReply;\n')
     406
    406407    return surround_in_condition(''.join(result), message.condition)
    407408
     
    530531    result.append('\n')
    531532
     533    sync_delayed_messages = []
     534    for message in receiver.messages:
     535        if message.reply_parameters != None and message.is_delayed:
     536            sync_delayed_messages.append(message)
     537
     538    if sync_delayed_messages:
     539        result.append('namespace Messages {\n\nnamespace %s {\n\n' % receiver.name)
     540
     541        for message in sync_delayed_messages:
     542            send_parameters = [(function_parameter_type(x.type), x.name) for x in message.reply_parameters]
     543
     544            result.append('%s::DelayedReply::DelayedReply(PassRefPtr<CoreIPC::Connection> connection, PassOwnPtr<CoreIPC::ArgumentEncoder> arguments)\n' % message.name)
     545            result.append('    : m_connection(connection)\n')
     546            result.append('    , m_arguments(arguments)\n')
     547            result.append('{\n')
     548            result.append('}\n')
     549            result.append('\n')
     550            result.append('%s::DelayedReply::~DelayedReply()\n' % message.name)
     551            result.append('{\n')
     552            result.append('    ASSERT(!m_connection);\n')
     553            result.append('}\n')
     554            result.append('\n')
     555            result.append('bool %s::DelayedReply::send(%s)\n' % (message.name, ', '.join([' '.join(x) for x in send_parameters])))
     556            result.append('{\n')
     557            result.append('    ASSERT(m_arguments);\n')
     558            result += ['    m_arguments->encode(%s);\n' % x.name for x in message.reply_parameters]
     559            result.append('    bool result = m_connection->sendSyncReply(m_arguments.release());\n')
     560            result.append('    m_connection = nullptr;\n')
     561            result.append('    return result;\n')
     562            result.append('}\n')
     563            result.append('\n')
     564
     565            result.append('} // namespace %s\n\n} // namespace Messages\n\n' % receiver.name)
     566
    532567    result.append('namespace WebKit {\n\n')
    533568
     
    553588    if sync_messages:
    554589        result.append('\n')
    555         result.append('CoreIPC::SyncReplyMode %s::didReceiveSync%sMessage(CoreIPC::Connection*, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments, CoreIPC::ArgumentEncoder* reply)\n' % (receiver.name, receiver.name))
     590        result.append('CoreIPC::SyncReplyMode %s::didReceiveSync%sMessage(CoreIPC::Connection*%s, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments, CoreIPC::ArgumentEncoder* reply)\n' % (receiver.name, receiver.name, ' connection' if sync_delayed_messages else ''))
    556591        result.append('{\n')
    557592        result.append('    switch (messageID.get<Messages::%s::Kind>()) {\n' % receiver.name)
  • trunk/Source/WebKit2/Scripts/webkit2/messages_unittest.py

    r83350 r84173  
    271271#include <WebCore/KeyboardEvent.h>
    272272#include <WebCore/PluginData.h>
     273#include <wtf/ThreadSafeRefCounted.h>
    273274#include <wtf/Vector.h>
    274275
    275276namespace CoreIPC {
     277    class ArgumentEncoder;
     278    class Connection;
    276279    class MachPort;
    277280}
     
    406409struct GetPluginProcessConnection : CoreIPC::Arguments1<const WTF::String&> {
    407410    static const Kind messageID = GetPluginProcessConnectionID;
    408     struct DelayedReply {
    409         DelayedReply(PassRefPtr<CoreIPC::Connection> connection, PassOwnPtr<CoreIPC::ArgumentDecoder> arguments)
    410             : m_connection(connection)
    411             , m_arguments(arguments)
    412         {
    413         }
    414 
    415         bool send(const CoreIPC::Connection::Handle& connectionHandle)
    416         {
    417             ASSERT(m_arguments);
    418             m_arguments->encode(connectionHandle);
    419             bool result = m_connection->sendSyncReply(m_arguments.release());
    420             m_connection = nullptr;
    421             return result;
    422         }
     411    struct DelayedReply : public ThreadSafeRefCounted<DelayedReply> {
     412        DelayedReply(PassRefPtr<CoreIPC::Connection>, PassOwnPtr<CoreIPC::ArgumentEncoder>);
     413        ~DelayedReply();
     414
     415        bool send(const CoreIPC::Connection::Handle& connectionHandle);
    423416
    424417    private:
    425418        RefPtr<CoreIPC::Connection> m_connection;
    426         OwnPtr<CoreIPC::ArgumentDecoder> m_arguments;
     419        OwnPtr<CoreIPC::ArgumentEncoder> m_arguments;
    427420    };
    428421
     422    typedef CoreIPC::Arguments1<CoreIPC::Connection::Handle&> Reply;
    429423    typedef CoreIPC::Arguments1<const WTF::String&> DecodeType;
    430424    explicit GetPluginProcessConnection(const WTF::String& pluginPath)
     
    436430struct TestMultipleAttributes : CoreIPC::Arguments0 {
    437431    static const Kind messageID = TestMultipleAttributesID;
    438     struct DelayedReply {
    439         DelayedReply(PassRefPtr<CoreIPC::Connection> connection, PassOwnPtr<CoreIPC::ArgumentDecoder> arguments)
    440             : m_connection(connection)
    441             , m_arguments(arguments)
    442         {
    443         }
    444 
    445         bool send()
    446         {
    447             ASSERT(m_arguments);
    448             bool result = m_connection->sendSyncReply(m_arguments.release());
    449             m_connection = nullptr;
    450             return result;
    451         }
     432    struct DelayedReply : public ThreadSafeRefCounted<DelayedReply> {
     433        DelayedReply(PassRefPtr<CoreIPC::Connection>, PassOwnPtr<CoreIPC::ArgumentEncoder>);
     434        ~DelayedReply();
     435
     436        bool send();
    452437
    453438    private:
    454439        RefPtr<CoreIPC::Connection> m_connection;
    455         OwnPtr<CoreIPC::ArgumentDecoder> m_arguments;
     440        OwnPtr<CoreIPC::ArgumentEncoder> m_arguments;
    456441    };
    457442
     443    typedef CoreIPC::Arguments0 Reply;
    458444    typedef CoreIPC::Arguments0 DecodeType;
    459445};
     
    548534#include "WebPreferencesStore.h"
    549535
     536namespace Messages {
     537
     538namespace WebPage {
     539
     540GetPluginProcessConnection::DelayedReply::DelayedReply(PassRefPtr<CoreIPC::Connection> connection, PassOwnPtr<CoreIPC::ArgumentEncoder> arguments)
     541    : m_connection(connection)
     542    , m_arguments(arguments)
     543{
     544}
     545
     546GetPluginProcessConnection::DelayedReply::~DelayedReply()
     547{
     548    ASSERT(!m_connection);
     549}
     550
     551bool GetPluginProcessConnection::DelayedReply::send(const CoreIPC::Connection::Handle& connectionHandle)
     552{
     553    ASSERT(m_arguments);
     554    m_arguments->encode(connectionHandle);
     555    bool result = m_connection->sendSyncReply(m_arguments.release());
     556    m_connection = nullptr;
     557    return result;
     558}
     559
     560TestMultipleAttributes::DelayedReply::DelayedReply(PassRefPtr<CoreIPC::Connection> connection, PassOwnPtr<CoreIPC::ArgumentEncoder> arguments)
     561    : m_connection(connection)
     562    , m_arguments(arguments)
     563{
     564}
     565
     566TestMultipleAttributes::DelayedReply::~DelayedReply()
     567{
     568    ASSERT(!m_connection);
     569}
     570
     571bool TestMultipleAttributes::DelayedReply::send()
     572{
     573    ASSERT(m_arguments);
     574    bool result = m_connection->sendSyncReply(m_arguments.release());
     575    m_connection = nullptr;
     576    return result;
     577}
     578
     579} // namespace WebPage
     580
     581} // namespace Messages
     582
    550583namespace WebKit {
    551584
     
    588621}
    589622
    590 CoreIPC::SyncReplyMode WebPage::didReceiveSyncWebPageMessage(CoreIPC::Connection*, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments, CoreIPC::ArgumentEncoder* reply)
     623CoreIPC::SyncReplyMode WebPage::didReceiveSyncWebPageMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments, CoreIPC::ArgumentEncoder* reply)
    591624{
    592625    switch (messageID.get<Messages::WebPage::Kind>()) {
     
    601634        return CoreIPC::AutomaticReply;
    602635    case Messages::WebPage::GetPluginProcessConnectionID:
    603         CoreIPC::handleMessage<Messages::WebPage::GetPluginProcessConnection>(arguments, reply, this, &WebPage::getPluginProcessConnection);
    604         return CoreIPC::AutomaticReply;
     636        CoreIPC::handleMessageDelayed<Messages::WebPage::GetPluginProcessConnection>(connection, arguments, reply, this, &WebPage::getPluginProcessConnection);
     637        return CoreIPC::ManualReply;
    605638    case Messages::WebPage::TestMultipleAttributesID:
    606         CoreIPC::handleMessage<Messages::WebPage::TestMultipleAttributes>(arguments, reply, this, &WebPage::testMultipleAttributes);
    607         return CoreIPC::AutomaticReply;
     639        CoreIPC::handleMessageDelayed<Messages::WebPage::TestMultipleAttributes>(connection, arguments, reply, this, &WebPage::testMultipleAttributes);
     640        return CoreIPC::ManualReply;
    608641#if PLATFORM(MAC)
    609642    case Messages::WebPage::InterpretKeyEventID:
Note: See TracChangeset for help on using the changeset viewer.