OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 21 matching lines...) Expand all Loading... |
32 #include "weborigin/SecurityOrigin.h" | 32 #include "weborigin/SecurityOrigin.h" |
33 #include "wtf/Forward.h" | 33 #include "wtf/Forward.h" |
34 #include "wtf/OwnPtr.h" | 34 #include "wtf/OwnPtr.h" |
35 #include "wtf/PassRefPtr.h" | 35 #include "wtf/PassRefPtr.h" |
36 #include "wtf/RefCounted.h" | 36 #include "wtf/RefCounted.h" |
37 | 37 |
38 namespace WebCore { | 38 namespace WebCore { |
39 | 39 |
40 class KURL; | 40 class KURL; |
41 class NotificationClient; | 41 class NotificationClient; |
42 class WorkerContext; | 42 class WorkerGlobalScope; |
43 class WorkerLoaderProxy; | 43 class WorkerLoaderProxy; |
44 class WorkerReportingProxy; | 44 class WorkerReportingProxy; |
45 struct WorkerThreadStartupData; | 45 struct WorkerThreadStartupData; |
46 | 46 |
47 enum WorkerThreadStartMode { DontPauseWorkerContextOnStart, PauseWorkerConte
xtOnStart }; | 47 enum WorkerThreadStartMode { DontPauseWorkerGlobalScopeOnStart, PauseWorkerG
lobalScopeOnStart }; |
48 | 48 |
49 class WorkerThread : public RefCounted<WorkerThread> { | 49 class WorkerThread : public RefCounted<WorkerThread> { |
50 public: | 50 public: |
51 virtual ~WorkerThread(); | 51 virtual ~WorkerThread(); |
52 | 52 |
53 bool start(); | 53 bool start(); |
54 void stop(); | 54 void stop(); |
55 | 55 |
56 bool isCurrentThread() const; | 56 bool isCurrentThread() const; |
57 WorkerRunLoop& runLoop() { return m_runLoop; } | 57 WorkerRunLoop& runLoop() { return m_runLoop; } |
58 WorkerLoaderProxy& workerLoaderProxy() const { return m_workerLoaderProx
y; } | 58 WorkerLoaderProxy& workerLoaderProxy() const { return m_workerLoaderProx
y; } |
59 WorkerReportingProxy& workerReportingProxy() const { return m_workerRepo
rtingProxy; } | 59 WorkerReportingProxy& workerReportingProxy() const { return m_workerRepo
rtingProxy; } |
60 | 60 |
61 // Number of active worker threads. | 61 // Number of active worker threads. |
62 static unsigned workerThreadCount(); | 62 static unsigned workerThreadCount(); |
63 static void releaseFastMallocFreeMemoryInAllThreads(); | 63 static void releaseFastMallocFreeMemoryInAllThreads(); |
64 | 64 |
65 #if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS) | 65 #if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS) |
66 NotificationClient* getNotificationClient() { return m_notificationClien
t; } | 66 NotificationClient* getNotificationClient() { return m_notificationClien
t; } |
67 void setNotificationClient(NotificationClient* client) { m_notificationC
lient = client; } | 67 void setNotificationClient(NotificationClient* client) { m_notificationC
lient = client; } |
68 #endif | 68 #endif |
69 | 69 |
70 protected: | 70 protected: |
71 WorkerThread(const KURL&, const String& userAgent, const String& sourceC
ode, WorkerLoaderProxy&, WorkerReportingProxy&, WorkerThreadStartMode, const Str
ing& contentSecurityPolicy, ContentSecurityPolicy::HeaderType, const SecurityOri
gin* topOrigin); | 71 WorkerThread(const KURL&, const String& userAgent, const String& sourceC
ode, WorkerLoaderProxy&, WorkerReportingProxy&, WorkerThreadStartMode, const Str
ing& contentSecurityPolicy, ContentSecurityPolicy::HeaderType, const SecurityOri
gin* topOrigin); |
72 | 72 |
73 // Factory method for creating a new worker context for the thread. | 73 // Factory method for creating a new worker context for the thread. |
74 virtual PassRefPtr<WorkerContext> createWorkerContext(const KURL&, const
String& userAgent, const String& contentSecurityPolicy, ContentSecurityPolicy::
HeaderType, PassRefPtr<SecurityOrigin> topOrigin) = 0; | 74 virtual PassRefPtr<WorkerGlobalScope> createWorkerGlobalScope(const KURL
&, const String& userAgent, const String& contentSecurityPolicy, ContentSecurity
Policy::HeaderType, PassRefPtr<SecurityOrigin> topOrigin) = 0; |
75 | 75 |
76 // Executes the event loop for the worker thread. Derived classes can ov
erride to perform actions before/after entering the event loop. | 76 // Executes the event loop for the worker thread. Derived classes can ov
erride to perform actions before/after entering the event loop. |
77 virtual void runEventLoop(); | 77 virtual void runEventLoop(); |
78 | 78 |
79 WorkerContext* workerContext() { return m_workerContext.get(); } | 79 WorkerGlobalScope* workerGlobalScope() { return m_workerGlobalScope.get(
); } |
80 | 80 |
81 private: | 81 private: |
82 // Static function executed as the core routine on the new thread. Passe
d a pointer to a WorkerThread object. | 82 // Static function executed as the core routine on the new thread. Passe
d a pointer to a WorkerThread object. |
83 static void workerThreadStart(void*); | 83 static void workerThreadStart(void*); |
84 | 84 |
85 void workerThread(); | 85 void workerThread(); |
86 | 86 |
87 ThreadIdentifier m_threadID; | 87 ThreadIdentifier m_threadID; |
88 WorkerRunLoop m_runLoop; | 88 WorkerRunLoop m_runLoop; |
89 WorkerLoaderProxy& m_workerLoaderProxy; | 89 WorkerLoaderProxy& m_workerLoaderProxy; |
90 WorkerReportingProxy& m_workerReportingProxy; | 90 WorkerReportingProxy& m_workerReportingProxy; |
91 | 91 |
92 RefPtr<WorkerContext> m_workerContext; | 92 RefPtr<WorkerGlobalScope> m_workerGlobalScope; |
93 Mutex m_threadCreationMutex; | 93 Mutex m_threadCreationMutex; |
94 | 94 |
95 OwnPtr<WorkerThreadStartupData> m_startupData; | 95 OwnPtr<WorkerThreadStartupData> m_startupData; |
96 | 96 |
97 #if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS) | 97 #if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS) |
98 NotificationClient* m_notificationClient; | 98 NotificationClient* m_notificationClient; |
99 #endif | 99 #endif |
100 }; | 100 }; |
101 | 101 |
102 } // namespace WebCore | 102 } // namespace WebCore |
103 | 103 |
104 #endif // WorkerThread_h | 104 #endif // WorkerThread_h |
105 | 105 |
OLD | NEW |