Changeset 83767 in webkit


Ignore:
Timestamp:
Apr 13, 2011 2:29:36 PM (13 years ago)
Author:
andersca@apple.com
Message:

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

Reviewed by Adam Roben.

Add support for disabling/enabling termination to ChildProcess
https://bugs.webkit.org/show_bug.cgi?id=58476

Add ChildProcess::disableTermination and ChildProcess::enableTermination and convert
the PluginProcess class over to using them.

  • PluginProcess/PluginProcess.cpp: (WebKit::PluginProcess::PluginProcess): The child process now takes a terminationTimeout argument. Get rid of the shutdown timer.

(WebKit::PluginProcess::removeWebProcessConnection):
Call enableTermination().

(WebKit::PluginProcess::shouldTerminate):
Always return true.

(WebKit::PluginProcess::createWebProcessConnection):
Call disableTermination().

(WebKit::PluginProcess::getSitesWithData):
Call disableTermination()/enableTermination().

(WebKit::PluginProcess::clearSiteData):
Ditto.

  • Shared/ChildProcess.cpp: (WebKit::ChildProcess::disableTermination): Increment the counter and stop the timer.

(WebKit::ChildProcess::enableTermination):
Decrement the counter; if it's zero, start the timer.

(WebKit::ChildProcess::terminationTimerFired):
Call shouldTerminate(). If it returns true, call terminate().

(WebKit::ChildProcess::terminate):
Call RunLoop::quit().

  • WebProcess/WebProcess.cpp: (WebKit::WebProcess::WebProcess): Just initialize the termination timeout to 0 for now.

(WebKit::WebProcess::shouldTerminate):
Always return true; this isn't used yet.

  • WebProcess/WebProcess.h:
Location:
trunk/Source/WebKit2
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r83766 r83767  
     12011-04-13  Anders Carlsson  <andersca@apple.com>
     2
     3        Reviewed by Adam Roben.
     4
     5        Add support for disabling/enabling termination to ChildProcess
     6        https://bugs.webkit.org/show_bug.cgi?id=58476
     7
     8        Add ChildProcess::disableTermination and ChildProcess::enableTermination and convert
     9        the PluginProcess class over to using them.
     10
     11        * PluginProcess/PluginProcess.cpp:
     12        (WebKit::PluginProcess::PluginProcess):
     13        The child process now takes a terminationTimeout argument. Get rid of the shutdown timer.
     14
     15        (WebKit::PluginProcess::removeWebProcessConnection):
     16        Call enableTermination().
     17
     18        (WebKit::PluginProcess::shouldTerminate):
     19        Always return true.
     20
     21        (WebKit::PluginProcess::createWebProcessConnection):
     22        Call disableTermination().
     23
     24        (WebKit::PluginProcess::getSitesWithData):
     25        Call disableTermination()/enableTermination().
     26
     27        (WebKit::PluginProcess::clearSiteData):
     28        Ditto.
     29
     30        * Shared/ChildProcess.cpp:
     31        (WebKit::ChildProcess::disableTermination):
     32        Increment the counter and stop the timer.
     33
     34        (WebKit::ChildProcess::enableTermination):
     35        Decrement the counter; if it's zero, start the timer.
     36
     37        (WebKit::ChildProcess::terminationTimerFired):
     38        Call shouldTerminate(). If it returns true, call terminate().
     39
     40        (WebKit::ChildProcess::terminate):
     41        Call RunLoop::quit().
     42
     43        * WebProcess/WebProcess.cpp:
     44        (WebKit::WebProcess::WebProcess):
     45        Just initialize the termination timeout to 0 for now.
     46
     47        (WebKit::WebProcess::shouldTerminate):
     48        Always return true; this isn't used yet.
     49
     50        * WebProcess/WebProcess.h:
     51
    1522011-04-13  Enrica Casucci  <enrica@apple.com>
    253
  • trunk/Source/WebKit2/PluginProcess/PluginProcess.cpp

    r82460 r83767  
    4747
    4848PluginProcess::PluginProcess()
    49     : m_shutdownTimer(RunLoop::main(), this, &PluginProcess::shutdownTimerFired)
    50 #if USE(ACCELERATED_COMPOSITING) && PLATFORM(MAC)
     49    : ChildProcess(shutdownTimeout)
     50#if PLATFORM(MAC)
    5151    , m_compositingRenderServerPort(MACH_PORT_NULL)
    5252#endif
     
    7979    }       
    8080
    81     startShutdownTimerIfNecessary();
     81    enableTermination();
    8282}
    8383
     
    9999}
    100100
     101bool PluginProcess::shouldTerminate()
     102{
     103    ASSERT(m_webProcessConnections.isEmpty());
     104
     105    return true;
     106}
     107
    101108void PluginProcess::didReceiveMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments)
    102109{
     
    156163    }
    157164
    158     // Stop the shutdown timer.
    159     m_shutdownTimer.stop();
     165    disableTermination();
    160166}
    161167
    162168void PluginProcess::getSitesWithData(uint64_t callbackID)
    163169{
     170    disableTermination();
     171
    164172    Vector<String> sites;
    165173    if (NetscapePluginModule* module = netscapePluginModule())
     
    168176    m_connection->send(Messages::PluginProcessProxy::DidGetSitesWithData(sites, callbackID), 0);
    169177
    170     startShutdownTimerIfNecessary();
     178    enableTermination();
    171179}
    172180
    173181void PluginProcess::clearSiteData(const Vector<String>& sites, uint64_t flags, uint64_t maxAgeInSeconds, uint64_t callbackID)
    174182{
     183    disableTermination();
     184
    175185    if (NetscapePluginModule* module = netscapePluginModule()) {
    176186        if (sites.isEmpty()) {
     
    185195    m_connection->send(Messages::PluginProcessProxy::DidClearSiteData(callbackID), 0);
    186196
    187     startShutdownTimerIfNecessary();
    188 }
    189 
    190 void PluginProcess::startShutdownTimerIfNecessary()
    191 {
    192     if (!m_webProcessConnections.isEmpty())
    193         return;
    194 
    195     // Start the shutdown timer.
    196     m_shutdownTimer.startOneShot(shutdownTimeout);
    197 }
    198 
    199 void PluginProcess::shutdownTimerFired()
    200 {
    201     RunLoop::current()->stop();
     197    enableTermination();
    202198}
    203199
  • trunk/Source/WebKit2/PluginProcess/PluginProcess.h

    r81412 r83767  
    6565    ~PluginProcess();
    6666
     67    // ChildProcess
     68    virtual bool shouldTerminate();
     69
    6770    // CoreIPC::Connection::Client
    6871    virtual void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*);
     
    7780    void getSitesWithData(uint64_t callbackID);
    7881    void clearSiteData(const Vector<String>& sites, uint64_t flags, uint64_t maxAgeInSeconds, uint64_t callbackID);
    79 
    80     void startShutdownTimerIfNecessary();
    81     void shutdownTimerFired();
    8282
    8383    void platformInitialize(const PluginProcessCreationParameters&);
     
    9595    RefPtr<NetscapePluginModule> m_pluginModule;
    9696   
    97     // A timer used for the shutdown timeout.
    98     RunLoop::Timer<PluginProcess> m_shutdownTimer;
    99 
    10097#if USE(ACCELERATED_COMPOSITING) && PLATFORM(MAC)
    10198    // The Mach port used for accelerated compositing.
  • trunk/Source/WebKit2/Shared/ChildProcess.cpp

    r77874 r83767  
    3333namespace WebKit {
    3434
    35 ChildProcess::ChildProcess()
     35void ChildProcess::disableTermination()
    3636{
     37    m_terminationCounter++;
     38    m_terminationTimer.stop();
     39}
     40
     41void ChildProcess::enableTermination()
     42{
     43    ASSERT(m_terminationCounter > 0);
     44    m_terminationCounter--;
     45
     46    if (m_terminationCounter)
     47        return;
     48
     49    if (!m_terminationTimeout) {
     50        terminationTimerFired();
     51        return;
     52    }
     53
     54    m_terminationTimer.startOneShot(m_terminationTimeout);
     55}
     56
     57ChildProcess::ChildProcess(double terminationTimeout)
     58    : m_terminationTimeout(terminationTimeout)
     59    , m_terminationCounter(0)
     60    , m_terminationTimer(RunLoop::main(), this, &ChildProcess::terminationTimerFired)
     61{
     62    // FIXME: The termination timer should not be scheduled on the main run loop.
     63    // It won't work with the threaded mode, but it's not really useful anyway as is.
    3764}
    3865
    3966ChildProcess::~ChildProcess()
    4067{
     68}
     69
     70void ChildProcess::terminationTimerFired()
     71{
     72    if (!shouldTerminate())
     73        return;
     74
     75    terminate();
     76}
     77
     78void ChildProcess::terminate()
     79{
     80    RunLoop::main()->stop();
    4181}
    4282
  • trunk/Source/WebKit2/Shared/ChildProcess.h

    r77874 r83767  
    2828
    2929#include "Connection.h"
     30#include "RunLoop.h"
    3031
    3132namespace WebKit {
     
    3334class ChildProcess : protected CoreIPC::Connection::Client {
    3435    WTF_MAKE_NONCOPYABLE(ChildProcess);
     36
     37public:
     38    // disable and enable termination of the process. when disableTermination is called, the
     39    // process won't terminate unless a corresponding disableTermination call is made.
     40    void disableTermination();
     41    void enableTermination();
     42
    3543protected:
    36     ChildProcess();
     44    explicit ChildProcess(double terminationTimeout);
    3745    ~ChildProcess();
    3846
    3947    static void didCloseOnConnectionWorkQueue(WorkQueue&, CoreIPC::Connection*);
     48
     49private:
     50    void terminationTimerFired();
     51
     52    virtual bool shouldTerminate() = 0;
     53    virtual void terminate();
     54
     55    // The timeout, in seconds, before this process will be terminated if termination
     56    // has been enabled. If the timeout is 0 seconds, the process will be terminated immediately.
     57    double m_terminationTimeout;
     58
     59    // A termination counter; when the counter reaches zero, the process will be terminated
     60    // after a given period of time.
     61    unsigned m_terminationCounter;
     62
     63    RunLoop::Timer<ChildProcess> m_terminationTimer;
    4064};
    4165
  • trunk/Source/WebKit2/WebProcess/WebProcess.cpp

    r83627 r83767  
    119119
    120120WebProcess::WebProcess()
    121     : m_inDidClose(false)
     121    : ChildProcess(0)
     122    , m_inDidClose(false)
    122123    , m_hasSetCacheModel(false)
    123124    , m_cacheModel(CacheModelDocumentViewer)
     
    543544}
    544545
     546bool WebProcess::shouldTerminate()
     547{
     548    // FIXME: Implement.
     549    ASSERT_NOT_REACHED();
     550    return false;
     551}
     552
    545553CoreIPC::SyncReplyMode WebProcess::didReceiveSyncMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments, CoreIPC::ArgumentEncoder* reply)
    546554{   
  • trunk/Source/WebKit2/WebProcess/WebProcess.h

    r83498 r83767  
    167167    void setTextCheckerState(const TextCheckerState&);
    168168
     169    // ChildProcess
     170    virtual bool shouldTerminate();
     171
    169172    // CoreIPC::Connection::Client
    170173    void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*);
Note: See TracChangeset for help on using the changeset viewer.