[webkit-dev] Propose some changes to WebKit implementation of HTML5 workers in order to run them in Chrome's worker process

Jian Li jianli at chromium.org
Thu Feb 5 19:05:20 PST 2009


Based on the initial refactoring of WorkerMessagingProxy class, I've updated
the abstractions as the following:

// A proxy to talk to the worker context.
// All calls to any methods should come from worker object thread.class
WorkerContextProxyBase {
public:
    // Creator.
    static WorkerContextProxy* create(const String& scriptUrl, Worker*
worker);

    // Terminates the worker context.
    virtual void terminateWorkerContext() = 0;

    // Posts the message to the worker context.
    virtual void postMessageToWorkerContext(const String& message) = 0;

    // Has any pending activity?
    virtual bool hasPendingActivity() const = 0;
};

// A proxy to talk to the worker object.
// All calls to any methods should come from worker context thread.
class WorkerObjectProxyBase {
public:
    // Posts the message to the worker object.
    virtual void postMessageToWorkerObject(const String& message) = 0;

    // Posts the exception to the worker object.
    virtual void postExceptionToWorkerObject(const String& errorMessage, int
lineNumber, const String& sourceURL) = 0;

    // Reports if there is pending activity in the worker context.
    virtual void reportPendingActivity(bool hasPendingActivity) = 0;

    // Called when the worker context is destroyed.
    virtual void workerContextDestroyed() = 0;
};




On Mon, Feb 2, 2009 at 6:10 PM, Jian Li <jianli at chromium.org> wrote:

> The current WebKit implementation of HTML5 workers is based on cross-thread
> communication in single process. To make it work for Chrome, we need to run
> the workers in Chrome's worker process. Hence, we propose the following
> changes:
>
> MessagingWorkerProxy acts as the gateway between Worker and WorkerContext in
> order to exchange messages. This does not work well across process. To
> support both cross-thread and cross-process models, we propose splitting
> MessagingWorkerProxy into two pieces: WorkerContextProxy and
> WorkerObjectProxy.
>
> For WebKit, MessagingWorkerProxy can implement both WorkerContextProxy
>  and WorkerObjectProxy, that communicate with each other via cross-thread
> task posting. Some changes need also to be made in DOM objects in order to
> put them in the right scope. For example, MessageWorkerTask.performTask can
> be moved to Worker object and MessageWorkerContextTask.performTask can be
> moved to WorkerContext object.
>
> For Chrome, the implementation of WorkerContextProxy uses IPC to
> communicate with the implementation of WorkerObjectProxy at the other end.
>
>         Worker <=> WorkerContextProxy <=> ... <=> WorkParentProxy <=>
> WorkerContext
>
>   WebKit: \--- in main thread  ---/       CTC     \------ in worker thread
>  -----/
>   (CTC: Cross-thread communication by posting task)
>
>   Chrome: \- in renderer process -/       IPC     \------ in worker process
> -----/
>   (IPC: Inter-process communication)
>
>
> The abstractions of WorkerContextProxy and WorkerObjectProxy are defined
> as the following:
>
> // A proxy to talk to the worker context.
> // All calls to any methods should come from main thread.
> class WorkerContextProxy {
> public:
>   // Creator.
>   static WorkerContextProxy* create();
>
>   // Starts the worker context. Returns 0 if successful, error code
> otherwise.
>   virtual int startContext(const String& scriptUrl, Worker* worker) = 0;
>
>   // Terminates the worker context.
>   virtual void terminateContext() = 0;
>
>   // Posts the message to the worker context.
>   virtual void postMessageToContext(const String& message) = 0;
>
>   // Has any pending activity?
>   virtual bool hasPendingActivity() = 0;
> };
>
> // A proxy to talk to the worker object.
> // All calls to any methods should come from worker thread.
> class WorkerObjectProxy {
> public:
>   // Runs the script with the specified url.
>   virtual bool run(const String& scriptURL) = 0;
>
>   // Posts the message to the worker object.
>   virtual void postMessageToObject(const String& message) = 0;
>
>   // Posts the exception to the worker object.
>   virtual void postExceptionToObject(const String& errorMessage, int
> lineNumber, const String& sourceURL) = 0;
> };
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20090205/2e24d15f/attachment.html>


More information about the webkit-dev mailing list