OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google 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 are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 17 matching lines...) Expand all Loading... |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #ifndef InProcessWorkerObjectProxy_h | 31 #ifndef InProcessWorkerObjectProxy_h |
32 #define InProcessWorkerObjectProxy_h | 32 #define InProcessWorkerObjectProxy_h |
33 | 33 |
34 #include "core/CoreExport.h" | 34 #include "core/CoreExport.h" |
35 #include "core/dom/MessagePort.h" | 35 #include "core/dom/MessagePort.h" |
36 #include "core/workers/WorkerReportingProxy.h" | 36 #include "core/workers/WorkerReportingProxy.h" |
37 #include "platform/heap/Handle.h" | 37 #include "platform/heap/Handle.h" |
| 38 #include "wtf/MakeCancellable.h" |
38 #include "wtf/PassRefPtr.h" | 39 #include "wtf/PassRefPtr.h" |
39 #include <memory> | 40 #include <memory> |
40 | 41 |
41 namespace blink { | 42 namespace blink { |
42 | 43 |
43 class ConsoleMessage; | 44 class ConsoleMessage; |
44 class ExecutionContext; | 45 class ExecutionContext; |
45 class ExecutionContextTask; | 46 class ExecutionContextTask; |
46 class InProcessWorkerMessagingProxy; | 47 class InProcessWorkerMessagingProxy; |
47 class WorkerOrWorkletGlobalScope; | 48 class WorkerOrWorkletGlobalScope; |
48 | 49 |
49 // A proxy to talk to the worker object. This object is created on the | 50 // A proxy to talk to the worker object. This object is created on the |
50 // parent context thread (i.e. usually the main thread), passed on to | 51 // parent context thread (i.e. usually the main thread), passed on to |
51 // the worker thread, and used just to proxy messages to the | 52 // the worker thread, and used just to proxy messages to the |
52 // InProcessWorkerMessagingProxy on the parent context thread. | 53 // InProcessWorkerMessagingProxy on the parent context thread. |
53 // | 54 // |
54 // Used only by in-process workers (DedicatedWorker and CompositorWorker.) | 55 // Used only by in-process workers (DedicatedWorker and CompositorWorker.) |
55 class CORE_EXPORT InProcessWorkerObjectProxy : public WorkerReportingProxy { | 56 class CORE_EXPORT InProcessWorkerObjectProxy : public WorkerReportingProxy { |
56 USING_FAST_MALLOC(InProcessWorkerObjectProxy); | 57 USING_FAST_MALLOC(InProcessWorkerObjectProxy); |
57 WTF_MAKE_NONCOPYABLE(InProcessWorkerObjectProxy); | 58 WTF_MAKE_NONCOPYABLE(InProcessWorkerObjectProxy); |
58 public: | 59 public: |
59 static std::unique_ptr<InProcessWorkerObjectProxy> create(InProcessWorkerMes
sagingProxy*); | 60 static std::unique_ptr<InProcessWorkerObjectProxy> create(InProcessWorkerMes
sagingProxy*); |
60 ~InProcessWorkerObjectProxy() override { } | 61 ~InProcessWorkerObjectProxy() override; |
61 | 62 |
62 void postMessageToWorkerObject(PassRefPtr<SerializedScriptValue>, std::uniqu
e_ptr<MessagePortChannelArray>); | 63 void postMessageToWorkerObject(PassRefPtr<SerializedScriptValue>, std::uniqu
e_ptr<MessagePortChannelArray>); |
63 void postTaskToMainExecutionContext(std::unique_ptr<ExecutionContextTask>); | 64 void postTaskToMainExecutionContext(std::unique_ptr<ExecutionContextTask>); |
64 void confirmMessageFromWorkerObject(bool hasPendingActivity); | 65 void confirmMessageFromWorkerObject(); |
65 void reportPendingActivity(bool hasPendingActivity); | 66 void reportPendingActivity(WorkerGlobalScope*); |
66 | 67 |
67 // WorkerReportingProxy overrides. | 68 // WorkerReportingProxy overrides. |
68 void reportException(const String& errorMessage, std::unique_ptr<SourceLocat
ion>, int exceptionId) override; | 69 void reportException(const String& errorMessage, std::unique_ptr<SourceLocat
ion>, int exceptionId) override; |
69 void reportConsoleMessage(MessageSource, MessageLevel, const String& message
, SourceLocation*) override; | 70 void reportConsoleMessage(MessageSource, MessageLevel, const String& message
, SourceLocation*) override; |
70 void postMessageToPageInspector(const String&) override; | 71 void postMessageToPageInspector(const String&) override; |
71 void didEvaluateWorkerScript(bool success) override { } | 72 void didEvaluateWorkerScript(bool success) override { } |
72 void workerGlobalScopeStarted(WorkerOrWorkletGlobalScope*) override { } | 73 void workerGlobalScopeStarted(WorkerOrWorkletGlobalScope*) override { } |
73 void workerGlobalScopeClosed() override; | 74 void workerGlobalScopeClosed() override; |
74 void workerThreadTerminated() override; | 75 void workerThreadTerminated() override; |
75 void willDestroyWorkerGlobalScope() override { } | 76 void willDestroyWorkerGlobalScope() override; |
76 | 77 |
77 protected: | 78 protected: |
78 InProcessWorkerObjectProxy(InProcessWorkerMessagingProxy*); | 79 InProcessWorkerObjectProxy(InProcessWorkerMessagingProxy*); |
79 virtual ExecutionContext* getExecutionContext(); | 80 virtual ExecutionContext* getExecutionContext(); |
80 | 81 |
81 private: | 82 private: |
| 83 friend class InProcessWorkerMessagingProxyForTest; |
| 84 |
82 // This object always outlives this proxy. | 85 // This object always outlives this proxy. |
83 InProcessWorkerMessagingProxy* m_messagingProxy; | 86 InProcessWorkerMessagingProxy* m_messagingProxy; |
| 87 |
| 88 // Used for scheduling a task to check pending activities on the worker |
| 89 // global scope. The task is scheduled as a delayed task with |
| 90 // |m_currentDelayToCheckPendingActivityInMs| delay. The delay is |
| 91 // exponetially increased up to |m_maxDelayToCheckPendingActivityInMs| |
| 92 // until all pending activities are done. The task is cancelled when the |
| 93 // worker global scoped is destroyed. |
| 94 WTF::ScopedFunctionCanceller m_taskCanceller; |
| 95 long long m_currentDelayToCheckPendingActivityInMs; |
| 96 long long m_maxDelayToCheckPendingActivityInMs; |
84 }; | 97 }; |
85 | 98 |
86 } // namespace blink | 99 } // namespace blink |
87 | 100 |
88 #endif // InProcessWorkerObjectProxy_h | 101 #endif // InProcessWorkerObjectProxy_h |
OLD | NEW |