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 16 matching lines...) Expand all Loading... | |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
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 WorkerThreadableLoader_h | 31 #ifndef WorkerThreadableLoader_h |
32 #define WorkerThreadableLoader_h | 32 #define WorkerThreadableLoader_h |
33 | 33 |
34 #include "core/dom/ExecutionContextTask.h" | 34 #include "core/dom/ExecutionContextTask.h" |
35 #include "core/loader/ThreadableLoader.h" | 35 #include "core/loader/ThreadableLoader.h" |
36 #include "core/loader/ThreadableLoaderClient.h" | 36 #include "core/loader/ThreadableLoaderClient.h" |
37 #include "core/loader/ThreadableLoaderClientWrapper.h" | |
38 #include "core/workers/WorkerThread.h" | 37 #include "core/workers/WorkerThread.h" |
39 #include "core/workers/WorkerThreadLifecycleObserver.h" | 38 #include "core/workers/WorkerThreadLifecycleObserver.h" |
40 #include "platform/WaitableEvent.h" | 39 #include "platform/WaitableEvent.h" |
41 #include "platform/heap/Handle.h" | 40 #include "platform/heap/Handle.h" |
42 #include "public/platform/WebTraceLocation.h" | 41 #include "public/platform/WebTraceLocation.h" |
43 #include "wtf/PassRefPtr.h" | 42 #include "wtf/PassRefPtr.h" |
44 #include "wtf/PtrUtil.h" | |
45 #include "wtf/RefPtr.h" | 43 #include "wtf/RefPtr.h" |
46 #include "wtf/Threading.h" | 44 #include "wtf/Threading.h" |
47 #include "wtf/Vector.h" | 45 #include "wtf/Vector.h" |
48 #include "wtf/text/WTFString.h" | 46 #include "wtf/text/WTFString.h" |
49 #include <memory> | 47 #include <memory> |
50 | 48 |
51 namespace blink { | 49 namespace blink { |
52 | 50 |
53 class ResourceError; | 51 class ResourceError; |
54 class ResourceRequest; | 52 class ResourceRequest; |
55 class ResourceResponse; | 53 class ResourceResponse; |
56 class WorkerGlobalScope; | 54 class WorkerGlobalScope; |
57 class WorkerLoaderProxy; | 55 class WorkerLoaderProxy; |
58 struct CrossThreadResourceRequestData; | 56 struct CrossThreadResourceRequestData; |
57 struct CrossThreadResourceTimingInfoData; | |
59 | 58 |
60 // TODO(yhirano): Draw a diagram to illustrate the class relationship. | 59 // TODO(yhirano): Draw a diagram to illustrate the class relationship. |
61 // TODO(yhirano): Rename inner classes so that readers can see in which thread | 60 // TODO(yhirano): Rename inner classes so that readers can see in which thread |
62 // they are living easily. | 61 // they are living easily. |
63 class WorkerThreadableLoader final : public ThreadableLoader { | 62 class WorkerThreadableLoader final : public ThreadableLoader { |
64 USING_FAST_MALLOC(WorkerThreadableLoader); | |
65 public: | 63 public: |
66 static void loadResourceSynchronously(WorkerGlobalScope&, const ResourceRequ est&, ThreadableLoaderClient&, const ThreadableLoaderOptions&, const ResourceLoa derOptions&); | 64 static void loadResourceSynchronously(WorkerGlobalScope&, const ResourceRequ est&, ThreadableLoaderClient&, const ThreadableLoaderOptions&, const ResourceLoa derOptions&); |
67 static std::unique_ptr<WorkerThreadableLoader> create(WorkerGlobalScope& wor kerGlobalScope, ThreadableLoaderClient* client, const ThreadableLoaderOptions& o ptions, const ResourceLoaderOptions& resourceLoaderOptions) | 65 static WorkerThreadableLoader* create(WorkerGlobalScope& workerGlobalScope, ThreadableLoaderClient* client, const ThreadableLoaderOptions& options, const Re sourceLoaderOptions& resourceLoaderOptions) |
68 { | 66 { |
69 return wrapUnique(new WorkerThreadableLoader(workerGlobalScope, client, options, resourceLoaderOptions, LoadAsynchronously)); | 67 return new WorkerThreadableLoader(workerGlobalScope, client, options, re sourceLoaderOptions, LoadAsynchronously); |
70 } | 68 } |
71 | 69 |
72 ~WorkerThreadableLoader() override; | 70 ~WorkerThreadableLoader() override; |
73 | 71 |
72 // ThreableLoader functions | |
haraken
2016/08/01 07:34:20
ThreadableLoader
yhirano
2016/08/01 07:56:43
Thanks, done.
| |
74 void start(const ResourceRequest&) override; | 73 void start(const ResourceRequest&) override; |
75 void overrideTimeout(unsigned long timeout) override; | 74 void overrideTimeout(unsigned long timeout) override; |
76 void cancel() override; | 75 void cancel() override; |
77 | 76 |
77 DECLARE_TRACE(); | |
78 | |
78 private: | 79 private: |
79 enum BlockingBehavior { | 80 enum BlockingBehavior { |
80 LoadSynchronously, | 81 LoadSynchronously, |
81 LoadAsynchronously | 82 LoadAsynchronously |
82 }; | 83 }; |
83 | 84 |
84 // A TaskForwarder forwards an ExecutionContextTask to the worker thread. | 85 // A TaskForwarder forwards an ExecutionContextTask to the worker thread. |
85 class TaskForwarder : public GarbageCollectedFinalized<TaskForwarder> { | 86 class TaskForwarder : public GarbageCollectedFinalized<TaskForwarder> { |
86 public: | 87 public: |
87 virtual ~TaskForwarder() {} | 88 virtual ~TaskForwarder() {} |
88 virtual void forwardTask(const WebTraceLocation&, std::unique_ptr<Execut ionContextTask>) = 0; | 89 virtual void forwardTask(const WebTraceLocation&, std::unique_ptr<Execut ionContextTask>) = 0; |
89 virtual void forwardTaskWithDoneSignal(const WebTraceLocation&, std::uni que_ptr<ExecutionContextTask>) = 0; | 90 virtual void forwardTaskWithDoneSignal(const WebTraceLocation&, std::uni que_ptr<ExecutionContextTask>) = 0; |
90 virtual void abort() = 0; | 91 virtual void abort() = 0; |
91 | 92 |
92 DEFINE_INLINE_VIRTUAL_TRACE() {} | 93 DEFINE_INLINE_VIRTUAL_TRACE() {} |
93 }; | 94 }; |
94 class AsyncTaskForwarder; | 95 class AsyncTaskForwarder; |
95 struct TaskWithLocation; | 96 struct TaskWithLocation; |
96 class WaitableEventWithTasks; | 97 class WaitableEventWithTasks; |
97 class SyncTaskForwarder; | 98 class SyncTaskForwarder; |
98 | 99 |
99 class Peer; | 100 // An instance of this class lives in the main thread. It is a |
100 // A Bridge instance lives in the worker thread and requests the associated | 101 // ThreadableLoaderClient for a DocumentThreadableLoader and forward |
101 // Peer (which lives in the main thread) to process loading tasks. | 102 // notifications to the associated WorkerThreadableLoader living in the |
102 class Bridge final : public GarbageCollectedFinalized<Bridge> { | 103 // worker thread. |
103 public: | |
104 Bridge(ThreadableLoaderClientWrapper*, PassRefPtr<WorkerLoaderProxy>, co nst ThreadableLoaderOptions&, const ResourceLoaderOptions&, BlockingBehavior); | |
105 ~Bridge(); | |
106 | |
107 void start(const ResourceRequest&, const WorkerGlobalScope&); | |
108 void overrideTimeout(unsigned long timeoutMilliseconds); | |
109 void cancel(); | |
110 void destroy(); | |
111 | |
112 void didStart(Peer*); | |
113 | |
114 // This getter function is thread safe. | |
115 ThreadableLoaderClientWrapper* clientWrapper() { return m_clientWrapper. get(); } | |
116 | |
117 DECLARE_VIRTUAL_TRACE(); | |
118 | |
119 private: | |
120 void cancelPeer(); | |
121 | |
122 const Member<ThreadableLoaderClientWrapper> m_clientWrapper; | |
123 const RefPtr<WorkerLoaderProxy> m_loaderProxy; | |
124 const ThreadableLoaderOptions m_threadableLoaderOptions; | |
125 const ResourceLoaderOptions m_resourceLoaderOptions; | |
126 const BlockingBehavior m_blockingBehavior; | |
127 | |
128 // |*m_peer| lives in the main thread. | |
129 CrossThreadPersistent<Peer> m_peer; | |
130 }; | |
131 | |
132 // A Peer instance lives in the main thread. It is a ThreadableLoaderClient | |
133 // for a DocumentThreadableLoader and forward notifications to the | |
134 // ThreadableLoaderClientWrapper which lives in the worker thread. | |
135 class Peer final : public GarbageCollectedFinalized<Peer>, public Threadable LoaderClient, public WorkerThreadLifecycleObserver { | 104 class Peer final : public GarbageCollectedFinalized<Peer>, public Threadable LoaderClient, public WorkerThreadLifecycleObserver { |
136 USING_GARBAGE_COLLECTED_MIXIN(Peer); | 105 USING_GARBAGE_COLLECTED_MIXIN(Peer); |
137 public: | 106 public: |
138 static void createAndStart( | 107 static void createAndStart( |
139 Bridge*, | 108 WorkerThreadableLoader*, |
140 PassRefPtr<WorkerLoaderProxy>, | 109 PassRefPtr<WorkerLoaderProxy>, |
141 WorkerThreadLifecycleContext*, | 110 WorkerThreadLifecycleContext*, |
142 std::unique_ptr<CrossThreadResourceRequestData>, | 111 std::unique_ptr<CrossThreadResourceRequestData>, |
143 const ThreadableLoaderOptions&, | 112 const ThreadableLoaderOptions&, |
144 const ResourceLoaderOptions&, | 113 const ResourceLoaderOptions&, |
145 PassRefPtr<WaitableEventWithTasks>, | 114 PassRefPtr<WaitableEventWithTasks>, |
146 ExecutionContext*); | 115 ExecutionContext*); |
147 ~Peer() override; | 116 ~Peer() override; |
148 | 117 |
149 void overrideTimeout(unsigned long timeoutMillisecond); | 118 void overrideTimeout(unsigned long timeoutMillisecond); |
(...skipping 12 matching lines...) Expand all Loading... | |
162 | 131 |
163 void contextDestroyed() override; | 132 void contextDestroyed() override; |
164 | 133 |
165 DECLARE_TRACE(); | 134 DECLARE_TRACE(); |
166 | 135 |
167 private: | 136 private: |
168 Peer(TaskForwarder*, WorkerThreadLifecycleContext*); | 137 Peer(TaskForwarder*, WorkerThreadLifecycleContext*); |
169 void start(Document&, std::unique_ptr<CrossThreadResourceRequestData>, c onst ThreadableLoaderOptions&, const ResourceLoaderOptions&); | 138 void start(Document&, std::unique_ptr<CrossThreadResourceRequestData>, c onst ThreadableLoaderOptions&, const ResourceLoaderOptions&); |
170 | 139 |
171 Member<TaskForwarder> m_forwarder; | 140 Member<TaskForwarder> m_forwarder; |
172 std::unique_ptr<ThreadableLoader> m_mainThreadLoader; | 141 Member<ThreadableLoader> m_mainThreadLoader; |
173 | 142 |
174 // |*m_clientWrapper| lives in the worker thread. | 143 // |*m_workerLoader| lives in the worker thread. |
175 CrossThreadWeakPersistent<ThreadableLoaderClientWrapper> m_clientWrapper ; | 144 CrossThreadWeakPersistent<WorkerThreadableLoader> m_workerLoader; |
176 }; | 145 }; |
177 | 146 |
178 WorkerThreadableLoader(WorkerGlobalScope&, ThreadableLoaderClient*, const Th readableLoaderOptions&, const ResourceLoaderOptions&, BlockingBehavior); | 147 WorkerThreadableLoader(WorkerGlobalScope&, ThreadableLoaderClient*, const Th readableLoaderOptions&, const ResourceLoaderOptions&, BlockingBehavior); |
148 void didStart(Peer*); | |
179 | 149 |
180 Persistent<WorkerGlobalScope> m_workerGlobalScope; | 150 void didSendData(unsigned long long bytesSent, unsigned long long totalBytes ToBeSent); |
181 const Persistent<ThreadableLoaderClientWrapper> m_workerClientWrapper; | 151 void didReceiveResponse(unsigned long identifier, std::unique_ptr<CrossThrea dResourceResponseData>, std::unique_ptr<WebDataConsumerHandle>); |
182 const Persistent<Bridge> m_bridge; | 152 void didReceiveData(std::unique_ptr<Vector<char>> data); |
153 void didReceiveCachedMetadata(std::unique_ptr<Vector<char>> data); | |
154 void didFinishLoading(unsigned long identifier, double finishTime); | |
155 void didFail(const ResourceError&); | |
156 void didFailAccessControlCheck(const ResourceError&); | |
157 void didFailRedirectCheck(); | |
158 void didDownloadData(int dataLength); | |
159 void didReceiveResourceTiming(std::unique_ptr<CrossThreadResourceTimingInfoD ata>); | |
160 | |
161 Member<WorkerGlobalScope> m_workerGlobalScope; | |
162 RefPtr<WorkerLoaderProxy> m_workerLoaderProxy; | |
163 ThreadableLoaderClient* m_client; | |
164 | |
165 ThreadableLoaderOptions m_threadableLoaderOptions; | |
166 ResourceLoaderOptions m_resourceLoaderOptions; | |
167 BlockingBehavior m_blockingBehavior; | |
168 | |
169 // |*m_peer| lives in the main thread. | |
170 CrossThreadPersistent<Peer> m_peer; | |
183 }; | 171 }; |
184 | 172 |
185 } // namespace blink | 173 } // namespace blink |
186 | 174 |
187 #endif // WorkerThreadableLoader_h | 175 #endif // WorkerThreadableLoader_h |
OLD | NEW |