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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 | 50 |
51 class ExecutionContextTask; | 51 class ExecutionContextTask; |
52 class ResourceError; | 52 class ResourceError; |
53 class ResourceRequest; | 53 class ResourceRequest; |
54 class ResourceResponse; | 54 class ResourceResponse; |
55 class WaitableEvent; | 55 class WaitableEvent; |
56 class WorkerGlobalScope; | 56 class WorkerGlobalScope; |
57 class WorkerLoaderProxy; | 57 class WorkerLoaderProxy; |
58 struct CrossThreadResourceRequestData; | 58 struct CrossThreadResourceRequestData; |
59 | 59 |
60 class WorkerThreadableLoader final : public ThreadableLoader, private Threadable
LoaderClientWrapper::ResourceTimingClient { | 60 class WorkerThreadableLoader final : public ThreadableLoader { |
61 USING_FAST_MALLOC(WorkerThreadableLoader); | 61 USING_FAST_MALLOC(WorkerThreadableLoader); |
62 public: | 62 public: |
63 static void loadResourceSynchronously(WorkerGlobalScope&, const ResourceRequ
est&, ThreadableLoaderClient&, const ThreadableLoaderOptions&, const ResourceLoa
derOptions&); | 63 static void loadResourceSynchronously(WorkerGlobalScope&, const ResourceRequ
est&, ThreadableLoaderClient&, const ThreadableLoaderOptions&, const ResourceLoa
derOptions&); |
64 static std::unique_ptr<WorkerThreadableLoader> create(WorkerGlobalScope& wor
kerGlobalScope, ThreadableLoaderClient* client, const ThreadableLoaderOptions& o
ptions, const ResourceLoaderOptions& resourceLoaderOptions) | 64 static std::unique_ptr<WorkerThreadableLoader> create(WorkerGlobalScope& wor
kerGlobalScope, ThreadableLoaderClient* client, const ThreadableLoaderOptions& o
ptions, const ResourceLoaderOptions& resourceLoaderOptions) |
65 { | 65 { |
66 return wrapUnique(new WorkerThreadableLoader(workerGlobalScope, client,
options, resourceLoaderOptions, LoadAsynchronously)); | 66 return wrapUnique(new WorkerThreadableLoader(workerGlobalScope, client,
options, resourceLoaderOptions, LoadAsynchronously)); |
67 } | 67 } |
68 | 68 |
69 ~WorkerThreadableLoader() override; | 69 ~WorkerThreadableLoader() override; |
70 | 70 |
(...skipping 24 matching lines...) Expand all Loading... |
95 // | 95 // |
96 // case 2. xhr gets aborted and the worker context continues running. | 96 // case 2. xhr gets aborted and the worker context continues running. |
97 // The ThreadableLoaderClientWrapper has the underlying client cleared, s
o no more calls | 97 // The ThreadableLoaderClientWrapper has the underlying client cleared, s
o no more calls |
98 // go through it. All tasks posted from the worker object's thread to th
e worker context's | 98 // go through it. All tasks posted from the worker object's thread to th
e worker context's |
99 // thread do "ThreadableLoaderClientWrapper::ref" (automatically inside o
f the cross thread copy | 99 // thread do "ThreadableLoaderClientWrapper::ref" (automatically inside o
f the cross thread copy |
100 // done in createCrossThreadTask), so the ThreadableLoaderClientWrapper i
nstance is there until all | 100 // done in createCrossThreadTask), so the ThreadableLoaderClientWrapper i
nstance is there until all |
101 // tasks are executed. | 101 // tasks are executed. |
102 class MainThreadBridgeBase : public ThreadableLoaderClient { | 102 class MainThreadBridgeBase : public ThreadableLoaderClient { |
103 public: | 103 public: |
104 // All executed on the worker context's thread. | 104 // All executed on the worker context's thread. |
105 MainThreadBridgeBase(PassRefPtr<ThreadableLoaderClientWrapper>, PassRefP
tr<WorkerLoaderProxy>); | 105 MainThreadBridgeBase(ThreadableLoaderClientWrapper*, PassRefPtr<WorkerLo
aderProxy>); |
106 virtual void start(const ResourceRequest&, const WorkerGlobalScope&) = 0
; | 106 virtual void start(const ResourceRequest&, const WorkerGlobalScope&) = 0
; |
107 void overrideTimeout(unsigned long timeoutMilliseconds); | 107 void overrideTimeout(unsigned long timeoutMilliseconds); |
108 void cancel(); | 108 void cancel(); |
109 void destroy(); | 109 void destroy(); |
110 | 110 |
111 // All executed on the main thread. | 111 // All executed on the main thread. |
112 void didSendData(unsigned long long bytesSent, unsigned long long totalB
ytesToBeSent) final; | 112 void didSendData(unsigned long long bytesSent, unsigned long long totalB
ytesToBeSent) final; |
113 void didReceiveResponse(unsigned long identifier, const ResourceResponse
&, std::unique_ptr<WebDataConsumerHandle>) final; | 113 void didReceiveResponse(unsigned long identifier, const ResourceResponse
&, std::unique_ptr<WebDataConsumerHandle>) final; |
114 void didReceiveData(const char*, unsigned dataLength) final; | 114 void didReceiveData(const char*, unsigned dataLength) final; |
115 void didDownloadData(int dataLength) final; | 115 void didDownloadData(int dataLength) final; |
(...skipping 27 matching lines...) Expand all Loading... |
143 // All executed on the main thread. | 143 // All executed on the main thread. |
144 void mainThreadCreateLoader(ThreadableLoaderOptions, ResourceLoaderOptio
ns, ExecutionContext*); | 144 void mainThreadCreateLoader(ThreadableLoaderOptions, ResourceLoaderOptio
ns, ExecutionContext*); |
145 void mainThreadStart(std::unique_ptr<CrossThreadResourceRequestData>); | 145 void mainThreadStart(std::unique_ptr<CrossThreadResourceRequestData>); |
146 void mainThreadDestroy(ExecutionContext*); | 146 void mainThreadDestroy(ExecutionContext*); |
147 void mainThreadOverrideTimeout(unsigned long timeoutMilliseconds, Execut
ionContext*); | 147 void mainThreadOverrideTimeout(unsigned long timeoutMilliseconds, Execut
ionContext*); |
148 void mainThreadCancel(ExecutionContext*); | 148 void mainThreadCancel(ExecutionContext*); |
149 | 149 |
150 // Only to be used on the main thread. | 150 // Only to be used on the main thread. |
151 std::unique_ptr<ThreadableLoader> m_mainThreadLoader; | 151 std::unique_ptr<ThreadableLoader> m_mainThreadLoader; |
152 | 152 |
153 // ThreadableLoaderClientWrapper is to be used on the worker context thr
ead. | 153 // |m_workerClientWrapper| holds an pointer created on the worker |
154 // The ref counting is done on either thread: | 154 // thread, and |this| instance is created on the main thread. |
155 // - worker context's thread: held by the tasks | 155 CrossThreadPersistent<ThreadableLoaderClientWrapper> m_workerClientWrapp
er; |
156 // - main thread: held by MainThreadBridgeBase | |
157 // Therefore, this must be a ThreadSafeRefCounted. | |
158 RefPtr<ThreadableLoaderClientWrapper> m_workerClientWrapper; | |
159 | 156 |
160 // Used on the worker context thread. | 157 // Used on the worker context thread. |
161 RefPtr<WorkerLoaderProxy> m_loaderProxy; | 158 RefPtr<WorkerLoaderProxy> m_loaderProxy; |
162 }; | 159 }; |
163 | 160 |
164 class MainThreadAsyncBridge final : public MainThreadBridgeBase { | 161 class MainThreadAsyncBridge final : public MainThreadBridgeBase { |
165 public: | 162 public: |
166 MainThreadAsyncBridge(WorkerGlobalScope&, PassRefPtr<ThreadableLoaderCli
entWrapper>, const ThreadableLoaderOptions&, const ResourceLoaderOptions&); | 163 MainThreadAsyncBridge(WorkerGlobalScope&, ThreadableLoaderClientWrapper*
, const ThreadableLoaderOptions&, const ResourceLoaderOptions&); |
167 void start(const ResourceRequest&, const WorkerGlobalScope&) override; | 164 void start(const ResourceRequest&, const WorkerGlobalScope&) override; |
168 | 165 |
169 private: | 166 private: |
170 ~MainThreadAsyncBridge() override; | 167 ~MainThreadAsyncBridge() override; |
171 | 168 |
172 void forwardTaskToWorker(std::unique_ptr<ExecutionContextTask>) override
; | 169 void forwardTaskToWorker(std::unique_ptr<ExecutionContextTask>) override
; |
173 void forwardTaskToWorkerOnLoaderDone(std::unique_ptr<ExecutionContextTas
k>) override; | 170 void forwardTaskToWorkerOnLoaderDone(std::unique_ptr<ExecutionContextTas
k>) override; |
174 }; | 171 }; |
175 | 172 |
176 class MainThreadSyncBridge final : public MainThreadBridgeBase { | 173 class MainThreadSyncBridge final : public MainThreadBridgeBase { |
177 public: | 174 public: |
178 MainThreadSyncBridge(WorkerGlobalScope&, PassRefPtr<ThreadableLoaderClie
ntWrapper>, const ThreadableLoaderOptions&, const ResourceLoaderOptions&); | 175 MainThreadSyncBridge(WorkerGlobalScope&, ThreadableLoaderClientWrapper*,
const ThreadableLoaderOptions&, const ResourceLoaderOptions&); |
179 void start(const ResourceRequest&, const WorkerGlobalScope&) override; | 176 void start(const ResourceRequest&, const WorkerGlobalScope&) override; |
180 | 177 |
181 private: | 178 private: |
182 ~MainThreadSyncBridge() override; | 179 ~MainThreadSyncBridge() override; |
183 | 180 |
184 void forwardTaskToWorker(std::unique_ptr<ExecutionContextTask>) override
; | 181 void forwardTaskToWorker(std::unique_ptr<ExecutionContextTask>) override
; |
185 void forwardTaskToWorkerOnLoaderDone(std::unique_ptr<ExecutionContextTas
k>) override; | 182 void forwardTaskToWorkerOnLoaderDone(std::unique_ptr<ExecutionContextTas
k>) override; |
186 | 183 |
187 bool m_done; | 184 bool m_done; |
188 std::unique_ptr<WaitableEvent> m_loaderDoneEvent; | 185 std::unique_ptr<WaitableEvent> m_loaderDoneEvent; |
189 // Thread-safety: |m_clientTasks| can be written (i.e. Closures are adde
d) | 186 // Thread-safety: |m_clientTasks| can be written (i.e. Closures are adde
d) |
190 // on the main thread only before |m_loaderDoneEvent| is signaled and ca
n be read | 187 // on the main thread only before |m_loaderDoneEvent| is signaled and ca
n be read |
191 // on the worker context thread only after |m_loaderDoneEvent| is signal
ed. | 188 // on the worker context thread only after |m_loaderDoneEvent| is signal
ed. |
192 Vector<std::unique_ptr<ExecutionContextTask>> m_clientTasks; | 189 Vector<std::unique_ptr<ExecutionContextTask>> m_clientTasks; |
193 Mutex m_lock; | 190 Mutex m_lock; |
194 }; | 191 }; |
195 | 192 |
196 WorkerThreadableLoader(WorkerGlobalScope&, ThreadableLoaderClient*, const Th
readableLoaderOptions&, const ResourceLoaderOptions&, BlockingBehavior); | 193 WorkerThreadableLoader(WorkerGlobalScope&, ThreadableLoaderClient*, const Th
readableLoaderOptions&, const ResourceLoaderOptions&, BlockingBehavior); |
197 | 194 |
198 void didReceiveResourceTiming(const ResourceTimingInfo&) override; | |
199 | |
200 Persistent<WorkerGlobalScope> m_workerGlobalScope; | 195 Persistent<WorkerGlobalScope> m_workerGlobalScope; |
201 RefPtr<ThreadableLoaderClientWrapper> m_workerClientWrapper; | 196 const Persistent<ThreadableLoaderClientWrapper> m_workerClientWrapper; |
202 | 197 |
203 MainThreadBridgeBase* m_bridge; | 198 MainThreadBridgeBase* m_bridge; |
204 }; | 199 }; |
205 | 200 |
206 } // namespace blink | 201 } // namespace blink |
207 | 202 |
208 #endif // WorkerThreadableLoader_h | 203 #endif // WorkerThreadableLoader_h |
OLD | NEW |