Changeset 249835 in webkit


Ignore:
Timestamp:
Sep 13, 2019 9:03:17 AM (5 years ago)
Author:
achristensen@apple.com
Message:

AuxiliaryProcessProxy::sendWithAsyncReply should queue up messages if sent while the process is starting like it does messages without replies
https://bugs.webkit.org/show_bug.cgi?id=201746

Reviewed by Youenn Fablet.

  • UIProcess/AuxiliaryProcessProxy.cpp:

(WebKit::AuxiliaryProcessProxy::sendMessage):
(WebKit::AuxiliaryProcessProxy::didFinishLaunching):

  • UIProcess/AuxiliaryProcessProxy.h:

(WebKit::AuxiliaryProcessProxy::sendWithAsyncReply):

Location:
trunk/Source/WebKit
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r249832 r249835  
     12019-09-13  Alex Christensen  <achristensen@webkit.org>
     2
     3        AuxiliaryProcessProxy::sendWithAsyncReply should queue up messages if sent while the process is starting like it does messages without replies
     4        https://bugs.webkit.org/show_bug.cgi?id=201746
     5
     6        Reviewed by Youenn Fablet.
     7
     8        * UIProcess/AuxiliaryProcessProxy.cpp:
     9        (WebKit::AuxiliaryProcessProxy::sendMessage):
     10        (WebKit::AuxiliaryProcessProxy::didFinishLaunching):
     11        * UIProcess/AuxiliaryProcessProxy.h:
     12        (WebKit::AuxiliaryProcessProxy::sendWithAsyncReply):
     13
    1142019-09-13  Youenn Fablet  <youenn@apple.com>
    215
  • trunk/Source/WebKit/UIProcess/AuxiliaryProcessProxy.cpp

    r249703 r249835  
    141141}
    142142
    143 bool AuxiliaryProcessProxy::sendMessage(std::unique_ptr<IPC::Encoder> encoder, OptionSet<IPC::SendOption> sendOptions)
     143bool AuxiliaryProcessProxy::sendMessage(std::unique_ptr<IPC::Encoder> encoder, OptionSet<IPC::SendOption> sendOptions, Optional<std::pair<CompletionHandler<void(IPC::Decoder*)>, uint64_t>>&& asyncReplyInfo)
    144144{
    145145    switch (state()) {
    146146    case State::Launching:
    147147        // If we're waiting for the child process to launch, we need to stash away the messages so we can send them once we have a connection.
    148         m_pendingMessages.append(std::make_pair(WTFMove(encoder), sendOptions));
     148        m_pendingMessages.append({ WTFMove(encoder), sendOptions, WTFMove(asyncReplyInfo) });
    149149        return true;
    150150
    151151    case State::Running:
    152         return connection()->sendMessage(WTFMove(encoder), sendOptions);
     152        if (connection()->sendMessage(WTFMove(encoder), sendOptions)) {
     153            if (asyncReplyInfo)
     154                IPC::addAsyncReplyHandler(*connection(), asyncReplyInfo->second, WTFMove(asyncReplyInfo->first));
     155            return true;
     156        }
     157        break;
    153158
    154159    case State::Terminated:
    155         return false;
    156     }
    157 
     160        break;
     161    }
     162
     163    if (asyncReplyInfo)
     164        asyncReplyInfo->first(nullptr);
     165   
    158166    return false;
    159167}
     
    201209    m_connection->open();
    202210
    203     for (size_t i = 0; i < m_pendingMessages.size(); ++i) {
    204         std::unique_ptr<IPC::Encoder> message = WTFMove(m_pendingMessages[i].first);
    205         OptionSet<IPC::SendOption> sendOptions = m_pendingMessages[i].second;
     211    for (auto&& pendingMessage : std::exchange(m_pendingMessages, { })) {
     212        auto encoder = WTFMove(pendingMessage.encoder);
     213        auto sendOptions = pendingMessage.sendOptions;
    206214#if HAVE(SANDBOX_ISSUE_MACH_EXTENSION_TO_PROCESS_BY_PID)
    207         if (message->messageName() == "LoadRequestWaitingForPID") {
    208             auto buffer = message->buffer();
    209             auto bufferSize = message->bufferSize();
     215        if (encoder->messageName() == "LoadRequestWaitingForPID") {
     216            auto buffer = encoder->buffer();
     217            auto bufferSize = encoder->bufferSize();
    210218            std::unique_ptr<IPC::Decoder> decoder = makeUnique<IPC::Decoder>(buffer, bufferSize, nullptr, Vector<IPC::Attachment> { });
    211219            LoadParameters loadParameters;
     
    218226        }
    219227#endif
    220         m_connection->sendMessage(WTFMove(message), sendOptions);
    221     }
    222 
    223     m_pendingMessages.clear();
     228        if (pendingMessage.asyncReplyInfo)
     229            IPC::addAsyncReplyHandler(*connection(), pendingMessage.asyncReplyInfo->second, WTFMove(pendingMessage.asyncReplyInfo->first));
     230        m_connection->sendMessage(WTFMove(encoder), sendOptions);
     231    }
    224232}
    225233
  • trunk/Source/WebKit/UIProcess/AuxiliaryProcessProxy.h

    r249703 r249835  
    5151    template<typename T> bool send(T&& message, uint64_t destinationID, OptionSet<IPC::SendOption> sendOptions = { });
    5252    template<typename T> bool sendSync(T&& message, typename T::Reply&&, uint64_t destinationID, Seconds timeout = 1_s, OptionSet<IPC::SendSyncOption> sendSyncOptions = { });
    53     template<typename T, typename... Args> void sendWithAsyncReply(T&&, CompletionHandler<void(Args...)>&&);
     53    template<typename T, typename... Args> void sendWithAsyncReply(T&&, CompletionHandler<void(Args...)>&&, uint64_t destinationID = 0, OptionSet<IPC::SendOption> = { });
    5454   
    5555    template<typename T, typename U>
     
    103103
    104104    bool canSendMessage() const { return state() != State::Terminated;}
    105     bool sendMessage(std::unique_ptr<IPC::Encoder>, OptionSet<IPC::SendOption>);
     105    bool sendMessage(std::unique_ptr<IPC::Encoder>, OptionSet<IPC::SendOption>, Optional<std::pair<CompletionHandler<void(IPC::Decoder*)>, uint64_t>>&& asyncReplyInfo = WTF::nullopt);
    106106
    107107    void shutDownProcess();
     
    126126    static bool isRunningProcessPID(ProcessID);
    127127
    128     Vector<std::pair<std::unique_ptr<IPC::Encoder>, OptionSet<IPC::SendOption>>> m_pendingMessages;
     128    struct PendingMessage {
     129        std::unique_ptr<IPC::Encoder> encoder;
     130        OptionSet<IPC::SendOption> sendOptions;
     131        Optional<std::pair<CompletionHandler<void(IPC::Decoder*)>, uint64_t>> asyncReplyInfo;
     132    };
     133   
     134    Vector<PendingMessage> m_pendingMessages;
    129135    RefPtr<ProcessLauncher> m_processLauncher;
    130136    RefPtr<IPC::Connection> m_connection;
     
    159165
    160166template<typename T, typename... Args>
    161 void AuxiliaryProcessProxy::sendWithAsyncReply(T&& message, CompletionHandler<void(Args...)>&& completionHandler)
     167void AuxiliaryProcessProxy::sendWithAsyncReply(T&& message, CompletionHandler<void(Args...)>&& completionHandler, uint64_t destinationID, OptionSet<IPC::SendOption> sendOptions)
    162168{
    163     if (!m_connection) {
    164         T::cancelReply(WTFMove(completionHandler));
    165         return;
    166     }
     169    COMPILE_ASSERT(!T::isSync, AsyncMessageExpected);
    167170
    168     connection()->sendWithAsyncReply(std::forward<T>(message), WTFMove(completionHandler));
     171    auto encoder = makeUnique<IPC::Encoder>(T::receiverName(), T::name(), destinationID);
     172    uint64_t listenerID = IPC::nextAsyncReplyHandlerID();
     173    encoder->encode(listenerID);
     174    encoder->encode(message.arguments());
     175    sendMessage(WTFMove(encoder), sendOptions, {{ [completionHandler = WTFMove(completionHandler)] (IPC::Decoder* decoder) mutable {
     176        if (decoder && !decoder->isInvalid())
     177            T::callReply(*decoder, WTFMove(completionHandler));
     178        else
     179            T::cancelReply(WTFMove(completionHandler));
     180    }, listenerID }});
    169181}
    170182   
Note: See TracChangeset for help on using the changeset viewer.