Changeset 62790 in webkit


Ignore:
Timestamp:
Jul 8, 2010 9:01:42 AM (14 years ago)
Author:
kenneth@webkit.org
Message:

2010-07-08 Luiz Agostini <luiz@webkit.org>, Kenneth Rohde Christiansen <kenneth@webkit.org>

Reviewed by Antti Koivisto.

[Qt] Improve QtWebkit2 secondary process launching procedure
https://bugs.webkit.org/show_bug.cgi?id=41853

Changing secondary process launching procedure to make sure that the method
ProcessLauncher::didFinishLaunchingProcess will only be called after secondary
process has been launched and the connection has been stablished between the
UIProcess and WebProcess.

This solves the timing issues ocasionaly observed when launching MiniBrowser.

QLocalServer object and related code has been removed from the class Connection.
Server instances of the Connection class now get the QLocalSocket via ProcessLauncher.

  • Platform/CoreIPC/Connection.h:
  • Platform/CoreIPC/qt/ConnectionQt.cpp: (CoreIPC::Connection::platformInitialize): (CoreIPC::Connection::platformInvalidate): (CoreIPC::Connection::open):

Using QProcess* as PlatformProcessIdentifier.

  • Platform/PlatformProcessIdentifier.h:

A new singleton class named ProcessLauncherHelper was created to handle the QLocalServer
object used to receive connections. This class launches the process and waits for it to connect
before calling ProcessLauncher::didFinishLaunchingProcess.

  • UIProcess/Launcher/ProcessLauncher.h:
  • UIProcess/Launcher/qt/ProcessLauncherQt.cpp: (WebKit::ProcessLauncherHelper::launch): (WebKit::ProcessLauncherHelper::takePendingConnection): (WebKit::ProcessLauncherHelper::ProcessLauncherHelper): (WebKit::ProcessLauncherHelper::instance): (WebKit::ProcessLauncherHelper::newConnection): (WebKit::ProcessLauncher::launchProcess): (WebKit::ProcessLauncher::terminateProcess): (_qt_takePendingConnection):
Location:
trunk/WebKit2
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKit2/ChangeLog

    r62788 r62790  
     12010-07-08  Luiz Agostini  <luiz@webkit.org>, Kenneth Rohde Christiansen <kenneth@webkit.org>
     2
     3        Reviewed by Antti Koivisto.
     4
     5        [Qt] Improve QtWebkit2 secondary process launching procedure
     6        https://bugs.webkit.org/show_bug.cgi?id=41853
     7
     8        Changing secondary process launching procedure to make sure that the method
     9        ProcessLauncher::didFinishLaunchingProcess will only be called after secondary
     10        process has been launched and the connection has been stablished between the
     11        UIProcess and WebProcess.
     12
     13        This solves the timing issues ocasionaly observed when launching MiniBrowser.
     14
     15        QLocalServer object and related code has been removed from the class Connection.
     16        Server instances of the Connection class now get the QLocalSocket via ProcessLauncher.
     17
     18        * Platform/CoreIPC/Connection.h:
     19        * Platform/CoreIPC/qt/ConnectionQt.cpp:
     20        (CoreIPC::Connection::platformInitialize):
     21        (CoreIPC::Connection::platformInvalidate):
     22        (CoreIPC::Connection::open):
     23
     24        Using QProcess* as PlatformProcessIdentifier.
     25
     26        * Platform/PlatformProcessIdentifier.h:
     27
     28        A new singleton class named ProcessLauncherHelper was created to handle the QLocalServer
     29        object used to receive connections. This class launches the process and waits for it to connect
     30        before calling ProcessLauncher::didFinishLaunchingProcess.
     31
     32        * UIProcess/Launcher/ProcessLauncher.h:
     33        * UIProcess/Launcher/qt/ProcessLauncherQt.cpp:
     34        (WebKit::ProcessLauncherHelper::launch):
     35        (WebKit::ProcessLauncherHelper::takePendingConnection):
     36        (WebKit::ProcessLauncherHelper::ProcessLauncherHelper):
     37        (WebKit::ProcessLauncherHelper::instance):
     38        (WebKit::ProcessLauncherHelper::newConnection):
     39        (WebKit::ProcessLauncher::launchProcess):
     40        (WebKit::ProcessLauncher::terminateProcess):
     41        (_qt_takePendingConnection):
     42
    1432010-07-08  Antti Koivisto  <koivisto@iki.fi>
    244
  • trunk/WebKit2/Platform/CoreIPC/Connection.h

    r62430 r62790  
    174174#elif PLATFORM(QT)
    175175    // Called on the connection queue.
    176     void openConnectionHandler();
    177     void newConnectionHandler();
    178176    void readyReadHandler();
    179177
     
    181179    size_t m_currentMessageSize;
    182180    QLocalSocket* m_socket;
    183     QLocalServer* m_server;
    184181    QString m_serverName;
    185182#endif
  • trunk/WebKit2/Platform/CoreIPC/qt/ConnectionQt.cpp

    r62648 r62790  
    2828
    2929#include "ArgumentEncoder.h"
     30#include "ProcessLauncher.h"
    3031#include "WebPageProxyMessageKinds.h"
    3132#include "WorkItem.h"
     
    4344void Connection::platformInitialize(Identifier identifier)
    4445{
    45     m_serverName = "QtWebKit" + identifier;
    46     m_server = 0;
     46    m_serverName = identifier;
    4747    m_socket = 0;
    4848    m_readBuffer.resize(messageMaxSize);
     
    5252void Connection::platformInvalidate()
    5353{
    54     delete m_server;
    5554    delete m_socket;
    56 }
    57 
    58 void Connection::newConnectionHandler()
    59 {
    60     m_socket = m_server->nextPendingConnection();
    61     m_isConnected = m_socket;
    62     if (m_isConnected)
    63         m_connectionQueue.connectSignal(m_socket, SIGNAL(readyRead()), WorkItem::create(this, &Connection::readyReadHandler));
    6455}
    6556
     
    9485}
    9586
    96 void Connection::openConnectionHandler()
     87bool Connection::open()
    9788{
    98     ASSERT(!m_server);
    9989    ASSERT(!m_socket);
    10090
    10191    if (m_isServer) {
    102         m_server = new QLocalServer();
    103         if (!m_server->listen(m_serverName)) {
    104             qDebug() << "failed to create server " << m_serverName;
    105             return;
    106         }
    107         m_connectionQueue.connectSignal(m_server, SIGNAL(newConnection()), WorkItem::create(this, &Connection::newConnectionHandler));
     92        m_socket = WebKit::ProcessLauncher::takePendingConnection();
     93        m_isConnected = m_socket;
     94        if (m_isConnected)
     95            m_connectionQueue.connectSignal(m_socket, SIGNAL(readyRead()), WorkItem::create(this, &Connection::readyReadHandler));
    10896    } else {
    10997        m_socket = new QLocalSocket();
     
    112100        m_isConnected = m_socket->waitForConnected();
    113101    }
    114 }
    115 
    116 bool Connection::open()
    117 {
    118     m_connectionQueue.scheduleWork(WorkItem::create(this, &Connection::openConnectionHandler));
    119     return false;
     102    return m_isConnected;
    120103}
    121104
  • trunk/WebKit2/Platform/PlatformProcessIdentifier.h

    r62257 r62790  
    2828#define PlatformProcessIdentifier_h
    2929
     30#if PLATFORM(QT)
     31class QProcess;
     32#endif
     33
    3034namespace WebKit {
    3135
     
    3539typedef HANDLE PlatformProcessIdentifier;
    3640#elif PLATFORM(QT)
    37 typedef pid_t PlatformProcessIdentifier;
     41typedef QProcess* PlatformProcessIdentifier;
    3842#endif
    3943
  • trunk/WebKit2/UIProcess/Launcher/ProcessLauncher.h

    r62305 r62790  
    3232#include <wtf/Threading.h>
    3333
     34#if PLATFORM(QT)
     35    class QLocalSocket;
     36#endif
     37
    3438namespace WebKit {
    3539
     
    5660    static CoreIPC::Connection::Identifier createWebThread();
    5761
     62#if PLATFORM(QT)
     63    friend class ProcessLauncherHelper;
     64    static QLocalSocket* takePendingConnection();
     65#endif
     66
    5867private:
    5968    explicit ProcessLauncher(Client*);
  • trunk/WebKit2/UIProcess/Launcher/qt/ProcessLauncherQt.cpp

    r62485 r62790  
    4040#endif
    4141
    42 #ifdef Q_OS_UNIX
    43 #include <signal.h>
    44 #endif
    45 
    4642#include <QApplication>
    4743#include <QDebug>
     44#include <QLocalServer>
    4845#include <QProcess>
    4946
     
    6562namespace WebKit {
    6663
    67 void ProcessLauncher::launchProcess()
    68 {
    69     srandom(time(0));
    70     QString connectionIdentifier = QString::number(random());
    71 
    72     QString program("QtWebProcess " + connectionIdentifier);
    73 
    74     QProcess* webProcess = new QProcess;
     64class ProcessLauncherHelper : public QObject {
     65    Q_OBJECT
     66public:
     67    void launch(WebKit::ProcessLauncher*);
     68    QLocalSocket* takePendingConnection();
     69    static ProcessLauncherHelper* instance();
     70private:
     71    ProcessLauncherHelper();
     72    QLocalServer m_server;
     73    QList<WorkItem*> m_items;
     74
     75    Q_SLOT void newConnection();
     76};
     77
     78void ProcessLauncherHelper::launch(WebKit::ProcessLauncher* launcher)
     79{
     80    QString program("QtWebProcess " + m_server.serverName());
     81
     82    QProcess* webProcess = new QProcess();
    7583    webProcess->start(program);
    7684
     
    7886        qDebug() << "Failed to start" << program;
    7987        ASSERT_NOT_REACHED();
     88        delete webProcess;
     89        return;
    8090    }
    8191
    82     PlatformProcessIdentifier processIdentifier = webProcess->pid();
    83     setpriority(PRIO_PROCESS, processIdentifier, 10);
    84 
    85     qDebug() << program << "nice" << getpriority(PRIO_PROCESS, processIdentifier);
    86 
    87     // We've finished launching the process, message back to the run loop.
    88     RunLoop::main()->scheduleWork(WorkItem::create(this, &ProcessLauncher::didFinishLaunchingProcess, processIdentifier, connectionIdentifier));
     92    setpriority(PRIO_PROCESS, webProcess->pid(), 10);
     93
     94    m_items.append(WorkItem::create(launcher, &WebKit::ProcessLauncher::didFinishLaunchingProcess, webProcess, m_server.serverName()).release());
     95}
     96
     97QLocalSocket* ProcessLauncherHelper::takePendingConnection()
     98{
     99    return m_server.nextPendingConnection();
     100}
     101
     102ProcessLauncherHelper::ProcessLauncherHelper()
     103{
     104    srandom(time(0));
     105    if (!m_server.listen("QtWebKit" + QString::number(random()))) {
     106        qDebug() << "Failed to create server socket.";
     107        ASSERT_NOT_REACHED();
     108    }
     109    connect(&m_server, SIGNAL(newConnection()), this, SLOT(newConnection()));
     110}
     111
     112ProcessLauncherHelper* ProcessLauncherHelper::instance()
     113{
     114    static ProcessLauncherHelper* result = new ProcessLauncherHelper();
     115    return result;
     116}
     117
     118void ProcessLauncherHelper::newConnection()
     119{
     120    ASSERT(!m_items.isEmpty());
     121
     122    m_items[0]->execute();
     123    delete m_items[0];
     124    m_items.pop_front();
     125}
     126
     127void ProcessLauncher::launchProcess()
     128{
     129    ProcessLauncherHelper::instance()->launch(this);
    89130}
    90131
     
    94135        return;
    95136
    96 #ifdef Q_OS_UNIX
    97     kill(m_processIdentifier, SIGKILL);
    98 #endif
     137    QObject::connect(m_processIdentifier, SIGNAL(finished(int)), m_processIdentifier, SLOT(deleteLater()), Qt::QueuedConnection);
     138    m_processIdentifier->kill();
     139}
     140
     141QLocalSocket* ProcessLauncher::takePendingConnection()
     142{
     143    return ProcessLauncherHelper::instance()->takePendingConnection();
    99144}
    100145
     
    153198    return 0;
    154199}
     200
     201#include "WebProcessLauncherQt.moc"
Note: See TracChangeset for help on using the changeset viewer.