Chromium Code Reviews| 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 11 matching lines...) Expand all Loading... | |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 * | 24 * |
| 25 */ | 25 */ |
| 26 | 26 |
| 27 #ifndef WorkerThread_h | 27 #ifndef WorkerThread_h |
| 28 #define WorkerThread_h | 28 #define WorkerThread_h |
| 29 | 29 |
| 30 #include "core/frame/ContentSecurityPolicy.h" | 30 #include "core/frame/ContentSecurityPolicy.h" |
| 31 #include "core/workers/WorkerRunLoop.h" | 31 #include "core/workers/WorkerRunLoop.h" |
| 32 #include "heap/Handle.h" | |
| 32 #include "platform/weborigin/SecurityOrigin.h" | 33 #include "platform/weborigin/SecurityOrigin.h" |
| 33 #include "wtf/Forward.h" | 34 #include "wtf/Forward.h" |
| 34 #include "wtf/OwnPtr.h" | 35 #include "wtf/OwnPtr.h" |
| 35 #include "wtf/PassRefPtr.h" | 36 #include "wtf/PassRefPtr.h" |
| 36 #include "wtf/RefCounted.h" | 37 #include "wtf/RefCounted.h" |
| 37 | 38 |
| 38 namespace blink { | 39 namespace blink { |
| 39 class WebWaitableEvent; | 40 class WebWaitableEvent; |
| 40 } | 41 } |
| 41 | 42 |
| 42 namespace WebCore { | 43 namespace WebCore { |
| 43 | 44 |
| 44 class KURL; | 45 class KURL; |
| 45 class NotificationClient; | 46 class NotificationClient; |
| 46 class WorkerGlobalScope; | 47 class WorkerGlobalScope; |
| 47 class WorkerLoaderProxy; | 48 class WorkerLoaderProxy; |
| 48 class WorkerReportingProxy; | 49 class WorkerReportingProxy; |
| 49 struct WorkerThreadStartupData; | 50 class WorkerThreadStartupData; |
| 50 | 51 |
| 51 enum WorkerThreadStartMode { DontPauseWorkerGlobalScopeOnStart, PauseWorkerG lobalScopeOnStart }; | 52 enum WorkerThreadStartMode { DontPauseWorkerGlobalScopeOnStart, PauseWorkerG lobalScopeOnStart }; |
| 52 | 53 |
| 53 class WorkerThread : public RefCounted<WorkerThread> { | 54 class WorkerThread : public RefCountedWillBeGarbageCollectedFinalized<Worker Thread> { |
| 55 DECLARE_GC_INFO; | |
| 54 public: | 56 public: |
| 55 virtual ~WorkerThread(); | 57 virtual ~WorkerThread(); |
| 56 | 58 |
| 57 bool start(); | 59 bool start(); |
| 58 void stop(); | 60 void stop(); |
| 59 | 61 |
| 60 // Can be used to wait for this worker thread to shut down. | 62 // Can be used to wait for this worker thread to shut down. |
| 61 // (This is signalled on the main thread, so it's assumed to be waited o n the worker context thread) | 63 // (This is signalled on the main thread, so it's assumed to be waited o n the worker context thread) |
| 62 blink::WebWaitableEvent* shutdownEvent() { return m_shutdownEvent.get(); } | 64 blink::WebWaitableEvent* shutdownEvent() { return m_shutdownEvent.get(); } |
| 63 | 65 |
| 64 bool isCurrentThread() const; | 66 bool isCurrentThread() const; |
| 65 WorkerRunLoop& runLoop() { return m_runLoop; } | 67 WorkerRunLoop& runLoop() { return m_runLoop; } |
| 66 WorkerLoaderProxy& workerLoaderProxy() const { return m_workerLoaderProx y; } | 68 WorkerLoaderProxy& workerLoaderProxy() const { return m_workerLoaderProx y; } |
| 67 WorkerReportingProxy& workerReportingProxy() const { return m_workerRepo rtingProxy; } | 69 WorkerReportingProxy& workerReportingProxy() const { return m_workerRepo rtingProxy; } |
| 68 | 70 |
| 69 // Number of active worker threads. | 71 // Number of active worker threads. |
| 70 static unsigned workerThreadCount(); | 72 static unsigned workerThreadCount(); |
| 71 static void releaseFastMallocFreeMemoryInAllThreads(); | 73 static void releaseFastMallocFreeMemoryInAllThreads(); |
| 72 | 74 |
| 73 NotificationClient* getNotificationClient() { return m_notificationClien t; } | 75 NotificationClient* getNotificationClient() { return m_notificationClien t; } |
| 74 void setNotificationClient(NotificationClient* client) { m_notificationC lient = client; } | 76 void setNotificationClient(NotificationClient* client) { m_notificationC lient = client; } |
| 75 | 77 |
| 78 void trace(Visitor*); | |
|
Mads Ager (chromium)
2014/02/24 13:27:53
Please make this virtual and make sure to implemen
| |
| 79 | |
| 76 protected: | 80 protected: |
| 77 WorkerThread(WorkerLoaderProxy&, WorkerReportingProxy&, PassOwnPtr<Worke rThreadStartupData>); | 81 WorkerThread(WorkerLoaderProxy&, WorkerReportingProxy&, PassOwnPtrWillBe RawPtr<WorkerThreadStartupData>); |
| 78 | 82 |
| 79 // Factory method for creating a new worker context for the thread. | 83 // Factory method for creating a new worker context for the thread. |
| 80 virtual PassRefPtr<WorkerGlobalScope> createWorkerGlobalScope(PassOwnPtr <WorkerThreadStartupData>) = 0; | 84 virtual PassRefPtrWillBeRawPtr<WorkerGlobalScope> createWorkerGlobalScop e(PassOwnPtrWillBeRawPtr<WorkerThreadStartupData>) = 0; |
| 81 | 85 |
| 82 // Executes the event loop for the worker thread. Derived classes can ov erride to perform actions before/after entering the event loop. | 86 // Executes the event loop for the worker thread. Derived classes can ov erride to perform actions before/after entering the event loop. |
| 83 virtual void runEventLoop(); | 87 virtual void runEventLoop(); |
| 84 | 88 |
| 85 WorkerGlobalScope* workerGlobalScope() { return m_workerGlobalScope.get( ); } | 89 WorkerGlobalScope* workerGlobalScope() { return m_workerGlobalScope.get( ); } |
| 86 | 90 |
| 87 private: | 91 private: |
| 88 // Static function executed as the core routine on the new thread. Passe d a pointer to a WorkerThread object. | 92 // Static function executed as the core routine on the new thread. Passe d a pointer to a WorkerThread object. |
| 89 static void workerThreadStart(void*); | 93 static void workerThreadStart(void*); |
| 90 | 94 |
| 91 void workerThread(); | 95 void workerThread(); |
| 92 | 96 |
| 93 ThreadIdentifier m_threadID; | 97 ThreadIdentifier m_threadID; |
| 94 WorkerRunLoop m_runLoop; | 98 WorkerRunLoop m_runLoop; |
| 95 WorkerLoaderProxy& m_workerLoaderProxy; | 99 WorkerLoaderProxy& m_workerLoaderProxy; |
| 96 WorkerReportingProxy& m_workerReportingProxy; | 100 WorkerReportingProxy& m_workerReportingProxy; |
| 97 | 101 |
| 98 RefPtr<WorkerGlobalScope> m_workerGlobalScope; | 102 RefPtrWillBeMember<WorkerGlobalScope> m_workerGlobalScope; |
| 99 Mutex m_threadCreationMutex; | 103 Mutex m_threadCreationMutex; |
| 100 | 104 |
| 101 OwnPtr<WorkerThreadStartupData> m_startupData; | 105 OwnPtrWillBeMember<WorkerThreadStartupData> m_startupData; |
| 102 | 106 |
| 103 NotificationClient* m_notificationClient; | 107 NotificationClient* m_notificationClient; |
| 104 | 108 |
| 105 // Used to signal thread shutdown. | 109 // Used to signal thread shutdown. |
| 106 OwnPtr<blink::WebWaitableEvent> m_shutdownEvent; | 110 OwnPtr<blink::WebWaitableEvent> m_shutdownEvent; |
| 107 }; | 111 }; |
| 108 | 112 |
| 109 } // namespace WebCore | 113 } // namespace WebCore |
| 110 | 114 |
| 111 #endif // WorkerThread_h | 115 #endif // WorkerThread_h |
| OLD | NEW |