OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_RENDERER_WEBWORKER_BASE_H_ |
| 6 #define CHROME_RENDERER_WEBWORKER_BASE_H_ |
| 7 |
| 8 #include <vector> |
| 9 |
| 10 #include "base/basictypes.h" |
| 11 #include "ipc/ipc_channel.h" |
| 12 |
| 13 class ChildThread; |
| 14 class GURL; |
| 15 |
| 16 // WebWorkerBase is the common base class used by both WebWorkerProxy and |
| 17 // WebSharedWorker. It contains logic to support starting up both dedicated |
| 18 // and shared workers, and handling message queueing while waiting for the |
| 19 // worker process to start. |
| 20 class WebWorkerBase : public IPC::Channel::Listener { |
| 21 public: |
| 22 WebWorkerBase(ChildThread* child_thread, |
| 23 int route_id, |
| 24 int render_view_route_id); |
| 25 |
| 26 virtual ~WebWorkerBase(); |
| 27 |
| 28 // Creates and initializes a new worker context. |
| 29 void CreateWorkerContext(IPC::Message* create_message, |
| 30 const GURL& script_url, |
| 31 const string16& user_agent, |
| 32 const string16& source_code); |
| 33 |
| 34 // Returns true if the worker is running (can send messages to it). |
| 35 bool IsStarted(); |
| 36 |
| 37 // Disconnects the worker (stops listening for incoming messages). |
| 38 virtual void Disconnect(); |
| 39 |
| 40 // Sends a message to the worker thread (forwarded via the RenderViewHost). |
| 41 // If WorkerStarted() has not yet been called, message is queued. |
| 42 bool Send(IPC::Message*); |
| 43 |
| 44 // Sends any messages currently in the queue. |
| 45 void SendQueuedMessages(); |
| 46 |
| 47 protected: |
| 48 // Routing id associated with this worker - used to receive messages from the |
| 49 // worker, and also to route messages to the worker (WorkerService contains |
| 50 // a map that maps between these renderer-side route IDs and worker-side |
| 51 // routing ids). |
| 52 int route_id_; |
| 53 |
| 54 // The routing id for the RenderView that created this worker. |
| 55 int render_view_route_id_; |
| 56 |
| 57 ChildThread* child_thread_; |
| 58 |
| 59 private: |
| 60 // Stores messages that were sent before the StartWorkerContext message. |
| 61 std::vector<IPC::Message*> queued_messages_; |
| 62 }; |
| 63 |
| 64 #endif // CHROME_RENDERER_WEBWORKER_BASE_H_ |
OLD | NEW |