| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/workers/ThreadedMessagingProxyBase.h" | 5 #include "core/workers/ThreadedMessagingProxyBase.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/SourceLocation.h" | 7 #include "bindings/core/v8/SourceLocation.h" |
| 8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
| 9 #include "core/dom/TaskRunnerHelper.h" | 9 #include "core/dom/TaskRunnerHelper.h" |
| 10 #include "core/frame/Deprecation.h" | 10 #include "core/frame/Deprecation.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 document->Loader() | 60 document->Loader() |
| 61 ? document->Loader()->GetTiming().ReferenceMonotonicTime() | 61 ? document->Loader()->GetTiming().ReferenceMonotonicTime() |
| 62 : MonotonicallyIncreasingTime(); | 62 : MonotonicallyIncreasingTime(); |
| 63 | 63 |
| 64 loader_proxy_ = WorkerLoaderProxy::Create(this); | 64 loader_proxy_ = WorkerLoaderProxy::Create(this); |
| 65 worker_thread_ = CreateWorkerThread(origin_time); | 65 worker_thread_ = CreateWorkerThread(origin_time); |
| 66 worker_thread_->Start(std::move(startup_data), GetParentFrameTaskRunners()); | 66 worker_thread_->Start(std::move(startup_data), GetParentFrameTaskRunners()); |
| 67 WorkerThreadCreated(); | 67 WorkerThreadCreated(); |
| 68 } | 68 } |
| 69 | 69 |
| 70 void ThreadedMessagingProxyBase::PostTaskToWorkerGlobalScope( | |
| 71 const WebTraceLocation& location, | |
| 72 std::unique_ptr<WTF::CrossThreadClosure> task) { | |
| 73 if (asked_to_terminate_) | |
| 74 return; | |
| 75 | |
| 76 DCHECK(worker_thread_); | |
| 77 TaskRunnerHelper::Get(TaskType::kNetworking, worker_thread_.get()) | |
| 78 ->PostTask(location, std::move(task)); | |
| 79 } | |
| 80 | |
| 81 void ThreadedMessagingProxyBase::PostTaskToLoader( | |
| 82 const WebTraceLocation& location, | |
| 83 std::unique_ptr<WTF::CrossThreadClosure> task) { | |
| 84 parent_frame_task_runners_->Get(TaskType::kNetworking) | |
| 85 ->PostTask(BLINK_FROM_HERE, std::move(task)); | |
| 86 } | |
| 87 | |
| 88 ThreadableLoadingContext* | 70 ThreadableLoadingContext* |
| 89 ThreadedMessagingProxyBase::GetThreadableLoadingContext() { | 71 ThreadedMessagingProxyBase::GetThreadableLoadingContext() { |
| 90 DCHECK(IsParentContextThread()); | 72 DCHECK(IsParentContextThread()); |
| 91 if (!loading_context_) { | 73 if (!loading_context_) { |
| 92 loading_context_ = | 74 loading_context_ = |
| 93 ThreadableLoadingContext::Create(*ToDocument(execution_context_)); | 75 ThreadableLoadingContext::Create(*ToDocument(execution_context_)); |
| 94 } | 76 } |
| 95 return loading_context_; | 77 return loading_context_; |
| 96 } | 78 } |
| 97 | 79 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 } | 160 } |
| 179 | 161 |
| 180 bool ThreadedMessagingProxyBase::IsParentContextThread() const { | 162 bool ThreadedMessagingProxyBase::IsParentContextThread() const { |
| 181 // TODO(nhiroki): Nested worker is not supported yet, so the parent context | 163 // TODO(nhiroki): Nested worker is not supported yet, so the parent context |
| 182 // thread should be equal to the main thread (http://crbug.com/31666). | 164 // thread should be equal to the main thread (http://crbug.com/31666). |
| 183 DCHECK(execution_context_->IsDocument()); | 165 DCHECK(execution_context_->IsDocument()); |
| 184 return IsMainThread(); | 166 return IsMainThread(); |
| 185 } | 167 } |
| 186 | 168 |
| 187 } // namespace blink | 169 } // namespace blink |
| OLD | NEW |