Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "core/loader/WorkerFetchContext.h" | |
| 6 | |
| 7 #include "core/workers/WorkerClients.h" | |
| 8 #include "core/workers/WorkerGlobalScope.h" | |
| 9 #include "platform/Supplementable.h" | |
| 10 #include "platform/WebTaskRunner.h" | |
| 11 #include "platform/exported/WrappedResourceRequest.h" | |
| 12 #include "public/platform/Platform.h" | |
| 13 #include "public/platform/WebScheduler.h" | |
| 14 #include "public/platform/WebThread.h" | |
| 15 #include "public/platform/WebWorkerFetchContext.h" | |
| 16 | |
| 17 namespace blink { | |
| 18 | |
| 19 namespace { | |
| 20 | |
| 21 class WorkerFetchContextInfo final | |
|
nhiroki
2017/04/18 07:56:41
Can you add a class-level comment?
horo
2017/04/18 12:53:34
Done.
| |
| 22 : public GarbageCollectedFinalized<WorkerFetchContextInfo>, | |
| 23 public Supplement<WorkerClients> { | |
| 24 USING_GARBAGE_COLLECTED_MIXIN(WorkerFetchContextInfo); | |
| 25 | |
| 26 public: | |
| 27 static WorkerFetchContextInfo* From(WorkerClients& clients) { | |
| 28 return static_cast<WorkerFetchContextInfo*>( | |
| 29 Supplement<WorkerClients>::From(clients, SupplementName())); | |
| 30 } | |
| 31 static const char* SupplementName() { return "WorkerFetchContextInfo"; } | |
| 32 | |
| 33 explicit WorkerFetchContextInfo( | |
| 34 std::unique_ptr<WebWorkerFetchContext> web_context) | |
| 35 : web_context_(std::move(web_context)) {} | |
| 36 virtual ~WorkerFetchContextInfo() {} | |
| 37 | |
| 38 std::unique_ptr<WebWorkerFetchContext> TakeContext() { | |
| 39 return std::move(web_context_); | |
| 40 } | |
| 41 | |
| 42 DEFINE_INLINE_VIRTUAL_TRACE() { Supplement<WorkerClients>::Trace(visitor); } | |
| 43 | |
| 44 private: | |
| 45 std::unique_ptr<WebWorkerFetchContext> web_context_; | |
| 46 }; | |
| 47 | |
| 48 } // namespace | |
| 49 | |
| 50 WorkerFetchContext::~WorkerFetchContext() {} | |
| 51 | |
| 52 WorkerFetchContext* WorkerFetchContext::Create( | |
| 53 WorkerGlobalScope& worker_global_scope) { | |
| 54 WorkerClients* worker_clients = worker_global_scope.Clients(); | |
| 55 DCHECK(worker_clients); | |
| 56 WorkerFetchContextInfo* context_info = | |
| 57 static_cast<WorkerFetchContextInfo*>(Supplement<WorkerClients>::From( | |
| 58 *worker_clients, WorkerFetchContextInfo::SupplementName())); | |
| 59 if (!context_info) | |
| 60 return nullptr; | |
| 61 std::unique_ptr<WebWorkerFetchContext> web_context = | |
| 62 context_info->TakeContext(); | |
| 63 DCHECK(web_context); | |
| 64 return new WorkerFetchContext(std::move(web_context)); | |
| 65 } | |
| 66 | |
| 67 WorkerFetchContext::WorkerFetchContext( | |
| 68 std::unique_ptr<WebWorkerFetchContext> web_context) | |
| 69 : web_context_(std::move(web_context)) { | |
| 70 web_context_->InitializeOnWorkerThread(Platform::Current() | |
| 71 ->CurrentThread() | |
| 72 ->Scheduler() | |
| 73 ->LoadingTaskRunner() | |
| 74 ->ToSingleThreadTaskRunner()); | |
| 75 } | |
| 76 | |
| 77 WebURLLoader* WorkerFetchContext::CreateURLLoader() { | |
| 78 return web_context_->CreateURLLoader(); | |
| 79 } | |
| 80 | |
| 81 bool WorkerFetchContext::IsControlledByServiceWorker() const { | |
| 82 return web_context_->IsControlledByServiceWorker(); | |
| 83 } | |
| 84 | |
| 85 void WorkerFetchContext::PrepareRequest(ResourceRequest& request, | |
| 86 RedirectType) { | |
| 87 WrappedResourceRequest webreq(request); | |
| 88 web_context_->WillSendRequest(webreq); | |
| 89 } | |
| 90 | |
| 91 void ProvideWorkerFetchContextToWorker( | |
| 92 WorkerClients* clients, | |
| 93 std::unique_ptr<WebWorkerFetchContext> web_context) { | |
| 94 DCHECK(clients); | |
| 95 WorkerFetchContextInfo::ProvideTo( | |
| 96 *clients, WorkerFetchContextInfo::SupplementName(), | |
| 97 new WorkerFetchContextInfo(std::move(web_context))); | |
| 98 } | |
| 99 | |
| 100 } // namespace blink | |
| OLD | NEW |