OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009, 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2009, 2010 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 #include "core/loader/WorkerThreadableLoader.h" | 31 #include "core/loader/WorkerThreadableLoader.h" |
32 | 32 |
33 #include <memory> | 33 #include <memory> |
34 #include "core/loader/DocumentThreadableLoader.h" | 34 #include "core/loader/DocumentThreadableLoader.h" |
35 #include "core/loader/ThreadableLoadingContext.h" | 35 #include "core/loader/ThreadableLoadingContext.h" |
36 #include "core/timing/WorkerGlobalScopePerformance.h" | 36 #include "core/timing/WorkerGlobalScopePerformance.h" |
37 #include "core/workers/WorkerGlobalScope.h" | 37 #include "core/workers/WorkerGlobalScope.h" |
38 #include "core/workers/WorkerLoaderProxy.h" | |
39 #include "platform/CrossThreadFunctional.h" | 38 #include "platform/CrossThreadFunctional.h" |
40 #include "platform/heap/SafePoint.h" | 39 #include "platform/heap/SafePoint.h" |
41 #include "platform/loader/fetch/ResourceError.h" | 40 #include "platform/loader/fetch/ResourceError.h" |
42 #include "platform/loader/fetch/ResourceRequest.h" | 41 #include "platform/loader/fetch/ResourceRequest.h" |
43 #include "platform/loader/fetch/ResourceResponse.h" | 42 #include "platform/loader/fetch/ResourceResponse.h" |
44 #include "platform/loader/fetch/ResourceTimingInfo.h" | 43 #include "platform/loader/fetch/ResourceTimingInfo.h" |
45 #include "platform/weborigin/KURL.h" | 44 #include "platform/weborigin/KURL.h" |
46 #include "platform/weborigin/SecurityPolicy.h" | 45 #include "platform/weborigin/SecurityPolicy.h" |
47 #include "platform/wtf/Functional.h" | 46 #include "platform/wtf/Functional.h" |
48 #include "platform/wtf/debug/Alias.h" | 47 #include "platform/wtf/debug/Alias.h" |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 RefPtr<WaitableEventWithTasks> event_with_tasks_; | 189 RefPtr<WaitableEventWithTasks> event_with_tasks_; |
191 }; | 190 }; |
192 | 191 |
193 WorkerThreadableLoader::WorkerThreadableLoader( | 192 WorkerThreadableLoader::WorkerThreadableLoader( |
194 WorkerGlobalScope& worker_global_scope, | 193 WorkerGlobalScope& worker_global_scope, |
195 ThreadableLoaderClient* client, | 194 ThreadableLoaderClient* client, |
196 const ThreadableLoaderOptions& options, | 195 const ThreadableLoaderOptions& options, |
197 const ResourceLoaderOptions& resource_loader_options, | 196 const ResourceLoaderOptions& resource_loader_options, |
198 BlockingBehavior blocking_behavior) | 197 BlockingBehavior blocking_behavior) |
199 : worker_global_scope_(&worker_global_scope), | 198 : worker_global_scope_(&worker_global_scope), |
200 worker_loader_proxy_( | |
201 worker_global_scope.GetThread()->GetWorkerLoaderProxy()), | |
202 parent_frame_task_runners_( | 199 parent_frame_task_runners_( |
203 worker_global_scope.GetThread()->GetParentFrameTaskRunners()), | 200 worker_global_scope.GetThread()->GetParentFrameTaskRunners()), |
204 client_(client), | 201 client_(client), |
205 threadable_loader_options_(options), | 202 threadable_loader_options_(options), |
206 resource_loader_options_(resource_loader_options), | 203 resource_loader_options_(resource_loader_options), |
207 blocking_behavior_(blocking_behavior) { | 204 blocking_behavior_(blocking_behavior) { |
208 DCHECK(client); | 205 DCHECK(client); |
209 } | 206 } |
210 | 207 |
211 void WorkerThreadableLoader::LoadResourceSynchronously( | 208 void WorkerThreadableLoader::LoadResourceSynchronously( |
212 WorkerGlobalScope& worker_global_scope, | 209 WorkerGlobalScope& worker_global_scope, |
213 const ResourceRequest& request, | 210 const ResourceRequest& request, |
214 ThreadableLoaderClient& client, | 211 ThreadableLoaderClient& client, |
215 const ThreadableLoaderOptions& options, | 212 const ThreadableLoaderOptions& options, |
216 const ResourceLoaderOptions& resource_loader_options) { | 213 const ResourceLoaderOptions& resource_loader_options) { |
217 (new WorkerThreadableLoader(worker_global_scope, &client, options, | 214 (new WorkerThreadableLoader(worker_global_scope, &client, options, |
218 resource_loader_options, kLoadSynchronously)) | 215 resource_loader_options, kLoadSynchronously)) |
219 ->Start(request); | 216 ->Start(request); |
220 } | 217 } |
221 | 218 |
222 WorkerThreadableLoader::~WorkerThreadableLoader() { | 219 WorkerThreadableLoader::~WorkerThreadableLoader() { |
223 DCHECK(!main_thread_loader_holder_); | 220 DCHECK(!main_thread_loader_holder_); |
224 DCHECK(!client_); | 221 DCHECK(!client_); |
225 } | 222 } |
226 | 223 |
227 void WorkerThreadableLoader::Start(const ResourceRequest& original_request) { | 224 void WorkerThreadableLoader::Start(const ResourceRequest& original_request) { |
| 225 DCHECK(worker_global_scope_->IsContextThread()); |
228 ResourceRequest request(original_request); | 226 ResourceRequest request(original_request); |
229 if (!request.DidSetHTTPReferrer()) { | 227 if (!request.DidSetHTTPReferrer()) { |
230 request.SetHTTPReferrer(SecurityPolicy::GenerateReferrer( | 228 request.SetHTTPReferrer(SecurityPolicy::GenerateReferrer( |
231 worker_global_scope_->GetReferrerPolicy(), request.Url(), | 229 worker_global_scope_->GetReferrerPolicy(), request.Url(), |
232 worker_global_scope_->OutgoingReferrer())); | 230 worker_global_scope_->OutgoingReferrer())); |
233 } | 231 } |
234 | 232 |
235 DCHECK(!IsMainThread()); | |
236 RefPtr<WaitableEventWithTasks> event_with_tasks; | 233 RefPtr<WaitableEventWithTasks> event_with_tasks; |
237 if (blocking_behavior_ == kLoadSynchronously) | 234 if (blocking_behavior_ == kLoadSynchronously) |
238 event_with_tasks = WaitableEventWithTasks::Create(); | 235 event_with_tasks = WaitableEventWithTasks::Create(); |
239 | 236 |
| 237 WorkerThread* worker_thread = worker_global_scope_->GetThread(); |
240 RefPtr<WebTaskRunner> worker_loading_task_runner = TaskRunnerHelper::Get( | 238 RefPtr<WebTaskRunner> worker_loading_task_runner = TaskRunnerHelper::Get( |
241 TaskType::kUnspecedLoading, worker_global_scope_.Get()); | 239 TaskType::kUnspecedLoading, worker_global_scope_.Get()); |
242 parent_frame_task_runners_->Get(TaskType::kUnspecedLoading) | 240 parent_frame_task_runners_->Get(TaskType::kUnspecedLoading) |
243 ->PostTask( | 241 ->PostTask( |
244 BLINK_FROM_HERE, | 242 BLINK_FROM_HERE, |
245 CrossThreadBind(&MainThreadLoaderHolder::CreateAndStart, | 243 CrossThreadBind( |
246 WrapCrossThreadPersistent(this), worker_loader_proxy_, | 244 &MainThreadLoaderHolder::CreateAndStart, |
247 std::move(worker_loading_task_runner), | 245 WrapCrossThreadPersistent(this), |
248 WrapCrossThreadPersistent( | 246 WrapCrossThreadPersistent(worker_thread->GetLoadingContext()), |
249 worker_global_scope_->GetThread() | 247 std::move(worker_loading_task_runner), |
250 ->GetWorkerThreadLifecycleContext()), | 248 WrapCrossThreadPersistent( |
251 request, threadable_loader_options_, | 249 worker_thread->GetWorkerThreadLifecycleContext()), |
252 resource_loader_options_, event_with_tasks)); | 250 request, threadable_loader_options_, resource_loader_options_, |
| 251 event_with_tasks)); |
253 | 252 |
254 if (blocking_behavior_ == kLoadAsynchronously) | 253 if (blocking_behavior_ == kLoadAsynchronously) |
255 return; | 254 return; |
256 | 255 |
257 event_with_tasks->Wait(); | 256 event_with_tasks->Wait(); |
258 | 257 |
259 if (event_with_tasks->IsAborted()) { | 258 if (event_with_tasks->IsAborted()) { |
260 // This thread is going to terminate. | 259 // This thread is going to terminate. |
261 Cancel(); | 260 Cancel(); |
262 return; | 261 return; |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 client_->DidReceiveResourceTiming(*info); | 429 client_->DidReceiveResourceTiming(*info); |
431 } | 430 } |
432 | 431 |
433 DEFINE_TRACE(WorkerThreadableLoader) { | 432 DEFINE_TRACE(WorkerThreadableLoader) { |
434 visitor->Trace(worker_global_scope_); | 433 visitor->Trace(worker_global_scope_); |
435 ThreadableLoader::Trace(visitor); | 434 ThreadableLoader::Trace(visitor); |
436 } | 435 } |
437 | 436 |
438 void WorkerThreadableLoader::MainThreadLoaderHolder::CreateAndStart( | 437 void WorkerThreadableLoader::MainThreadLoaderHolder::CreateAndStart( |
439 WorkerThreadableLoader* worker_loader, | 438 WorkerThreadableLoader* worker_loader, |
440 RefPtr<WorkerLoaderProxy> loader_proxy, | 439 ThreadableLoadingContext* loading_context, |
441 RefPtr<WebTaskRunner> worker_loading_task_runner, | 440 RefPtr<WebTaskRunner> worker_loading_task_runner, |
442 WorkerThreadLifecycleContext* worker_thread_lifecycle_context, | 441 WorkerThreadLifecycleContext* worker_thread_lifecycle_context, |
443 std::unique_ptr<CrossThreadResourceRequestData> request, | 442 std::unique_ptr<CrossThreadResourceRequestData> request, |
444 const ThreadableLoaderOptions& options, | 443 const ThreadableLoaderOptions& options, |
445 const ResourceLoaderOptions& resource_loader_options, | 444 const ResourceLoaderOptions& resource_loader_options, |
446 PassRefPtr<WaitableEventWithTasks> event_with_tasks) { | 445 PassRefPtr<WaitableEventWithTasks> event_with_tasks) { |
447 DCHECK(IsMainThread()); | 446 DCHECK(IsMainThread()); |
448 TaskForwarder* forwarder; | 447 TaskForwarder* forwarder; |
449 ThreadableLoadingContext* loading_context = | |
450 loader_proxy->GetThreadableLoadingContext(); | |
451 if (!loading_context) | |
452 return; | |
453 if (event_with_tasks) | 448 if (event_with_tasks) |
454 forwarder = new SyncTaskForwarder(std::move(event_with_tasks)); | 449 forwarder = new SyncTaskForwarder(std::move(event_with_tasks)); |
455 else | 450 else |
456 forwarder = new AsyncTaskForwarder(std::move(worker_loading_task_runner)); | 451 forwarder = new AsyncTaskForwarder(std::move(worker_loading_task_runner)); |
457 | 452 |
458 MainThreadLoaderHolder* main_thread_loader_holder = | 453 MainThreadLoaderHolder* main_thread_loader_holder = |
459 new MainThreadLoaderHolder(forwarder, worker_thread_lifecycle_context); | 454 new MainThreadLoaderHolder(forwarder, worker_thread_lifecycle_context); |
460 if (main_thread_loader_holder->WasContextDestroyedBeforeObserverCreation()) { | 455 if (main_thread_loader_holder->WasContextDestroyedBeforeObserverCreation()) { |
461 // The thread is already terminating. | 456 // The thread is already terminating. |
462 forwarder->Abort(); | 457 forwarder->Abort(); |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
679 DCHECK(IsMainThread()); | 674 DCHECK(IsMainThread()); |
680 ResourceLoaderOptions resource_loader_options = | 675 ResourceLoaderOptions resource_loader_options = |
681 original_resource_loader_options; | 676 original_resource_loader_options; |
682 resource_loader_options.request_initiator_context = kWorkerContext; | 677 resource_loader_options.request_initiator_context = kWorkerContext; |
683 main_thread_loader_ = DocumentThreadableLoader::Create( | 678 main_thread_loader_ = DocumentThreadableLoader::Create( |
684 loading_context, this, options, resource_loader_options); | 679 loading_context, this, options, resource_loader_options); |
685 main_thread_loader_->Start(ResourceRequest(request.get())); | 680 main_thread_loader_->Start(ResourceRequest(request.get())); |
686 } | 681 } |
687 | 682 |
688 } // namespace blink | 683 } // namespace blink |
OLD | NEW |