#ifndef WorkerThread_h
#define WorkerThread_h
#include "core/frame/csp/ContentSecurityPolicy.h"
#include "core/workers/WorkerRunLoop.h"
#include "platform/weborigin/SecurityOrigin.h"
#include "wtf/Forward.h"
#include "wtf/OwnPtr.h"
#include "wtf/PassRefPtr.h"
#include "wtf/RefCounted.h"
namespace blink {
class WebWaitableEvent;
}
namespace WebCore {
class KURL;
class NotificationClient;
class WorkerGlobalScope;
class WorkerLoaderProxy;
class WorkerReportingProxy;
class WorkerThreadStartupData;
enum WorkerThreadStartMode { DontPauseWorkerGlobalScopeOnStart, PauseWorkerGlobalScopeOnStart };
class WorkerThread : public RefCounted<WorkerThread> {
public:
virtual ~WorkerThread();
bool start();
void stop();
blink::WebWaitableEvent* shutdownEvent() { return m_shutdownEvent.get(); }
bool isCurrentThread() const;
WorkerRunLoop& runLoop() { return m_runLoop; }
WorkerLoaderProxy& workerLoaderProxy() const { return m_workerLoaderProxy; }
WorkerReportingProxy& workerReportingProxy() const { return m_workerReportingProxy; }
static unsigned workerThreadCount();
static void releaseFastMallocFreeMemoryInAllThreads();
NotificationClient* getNotificationClient() { return m_notificationClient; }
void setNotificationClient(NotificationClient* client) { m_notificationClient = client; }
protected:
WorkerThread(WorkerLoaderProxy&, WorkerReportingProxy&, PassOwnPtrWillBeRawPtr<WorkerThreadStartupData>);
virtual PassRefPtrWillBeRawPtr<WorkerGlobalScope> createWorkerGlobalScope(PassOwnPtrWillBeRawPtr<WorkerThreadStartupData>) = 0;
virtual void runEventLoop();
WorkerGlobalScope* workerGlobalScope() { return m_workerGlobalScope.get(); }
private:
static void workerThreadStart(void*);
void workerThread();
ThreadIdentifier m_threadID;
WorkerRunLoop m_runLoop;
WorkerLoaderProxy& m_workerLoaderProxy;
WorkerReportingProxy& m_workerReportingProxy;
RefPtrWillBePersistent<WorkerGlobalScope> m_workerGlobalScope;
Mutex m_threadCreationMutex;
OwnPtrWillBePersistent<WorkerThreadStartupData> m_startupData;
NotificationClient* m_notificationClient;
OwnPtr<blink::WebWaitableEvent> m_shutdownEvent;
};
}
#endif