#ifndef WorkerThread_h
#define WorkerThread_h
#if ENABLE(WORKERS)
#include "ContentSecurityPolicy.h"
#include "GroupSettings.h"
#include "WorkerRunLoop.h"
#include <wtf/Forward.h>
#include <wtf/OwnPtr.h>
#include <wtf/PassRefPtr.h>
#include <wtf/RefCounted.h>
namespace WebCore {
class KURL;
class NotificationClient;
class SecurityOrigin;
class WorkerContext;
class WorkerLoaderProxy;
class WorkerReportingProxy;
struct WorkerThreadStartupData;
enum WorkerThreadStartMode { DontPauseWorkerContextOnStart, PauseWorkerContextOnStart };
class WorkerThread : public RefCounted<WorkerThread> {
public:
virtual ~WorkerThread();
bool start();
void stop();
ThreadIdentifier threadID() const { return m_threadID; }
WorkerRunLoop& runLoop() { return m_runLoop; }
WorkerLoaderProxy& workerLoaderProxy() const { return m_workerLoaderProxy; }
WorkerReportingProxy& workerReportingProxy() const { return m_workerReportingProxy; }
static unsigned workerThreadCount();
static void releaseFastMallocFreeMemoryInAllThreads();
#if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
NotificationClient* getNotificationClient() { return m_notificationClient; }
void setNotificationClient(NotificationClient* client) { m_notificationClient = client; }
#endif
protected:
WorkerThread(const KURL&, const String& userAgent, const GroupSettings*, const String& sourceCode, WorkerLoaderProxy&, WorkerReportingProxy&, WorkerThreadStartMode, const String& contentSecurityPolicy, ContentSecurityPolicy::HeaderType, const SecurityOrigin* topOrigin);
virtual PassRefPtr<WorkerContext> createWorkerContext(const KURL&, const String& userAgent, PassOwnPtr<GroupSettings>, const String& contentSecurityPolicy, ContentSecurityPolicy::HeaderType, PassRefPtr<SecurityOrigin> topOrigin) = 0;
virtual void runEventLoop();
WorkerContext* workerContext() { return m_workerContext.get(); }
private:
static void workerThreadStart(void*);
void workerThread();
ThreadIdentifier m_threadID;
WorkerRunLoop m_runLoop;
WorkerLoaderProxy& m_workerLoaderProxy;
WorkerReportingProxy& m_workerReportingProxy;
RefPtr<WorkerContext> m_workerContext;
Mutex m_threadCreationMutex;
OwnPtr<WorkerThreadStartupData> m_startupData;
#if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
NotificationClient* m_notificationClient;
#endif
};
}
#endif // ENABLE(WORKERS)
#endif // WorkerThread_h