Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(643)

Unified Diff: third_party/WebKit/Source/core/loader/WorkerFetchContext.cpp

Issue 2804843005: Implement the infrastructure of creating WorkerFetchContext in worker global scope. (Closed)
Patch Set: rebase Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/loader/WorkerFetchContext.cpp
diff --git a/third_party/WebKit/Source/core/loader/WorkerFetchContext.cpp b/third_party/WebKit/Source/core/loader/WorkerFetchContext.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..5d61f544f797c2a2338e81729adb3d8bfa303987
--- /dev/null
+++ b/third_party/WebKit/Source/core/loader/WorkerFetchContext.cpp
@@ -0,0 +1,100 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/loader/WorkerFetchContext.h"
+
+#include "core/workers/WorkerClients.h"
+#include "core/workers/WorkerGlobalScope.h"
+#include "platform/Supplementable.h"
+#include "platform/WebTaskRunner.h"
+#include "platform/exported/WrappedResourceRequest.h"
+#include "public/platform/Platform.h"
+#include "public/platform/WebScheduler.h"
+#include "public/platform/WebThread.h"
+#include "public/platform/WebWorkerFetchContext.h"
+
+namespace blink {
+
+namespace {
+
+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.
+ : public GarbageCollectedFinalized<WorkerFetchContextInfo>,
+ public Supplement<WorkerClients> {
+ USING_GARBAGE_COLLECTED_MIXIN(WorkerFetchContextInfo);
+
+ public:
+ static WorkerFetchContextInfo* From(WorkerClients& clients) {
+ return static_cast<WorkerFetchContextInfo*>(
+ Supplement<WorkerClients>::From(clients, SupplementName()));
+ }
+ static const char* SupplementName() { return "WorkerFetchContextInfo"; }
+
+ explicit WorkerFetchContextInfo(
+ std::unique_ptr<WebWorkerFetchContext> web_context)
+ : web_context_(std::move(web_context)) {}
+ virtual ~WorkerFetchContextInfo() {}
+
+ std::unique_ptr<WebWorkerFetchContext> TakeContext() {
+ return std::move(web_context_);
+ }
+
+ DEFINE_INLINE_VIRTUAL_TRACE() { Supplement<WorkerClients>::Trace(visitor); }
+
+ private:
+ std::unique_ptr<WebWorkerFetchContext> web_context_;
+};
+
+} // namespace
+
+WorkerFetchContext::~WorkerFetchContext() {}
+
+WorkerFetchContext* WorkerFetchContext::Create(
+ WorkerGlobalScope& worker_global_scope) {
+ WorkerClients* worker_clients = worker_global_scope.Clients();
+ DCHECK(worker_clients);
+ WorkerFetchContextInfo* context_info =
+ static_cast<WorkerFetchContextInfo*>(Supplement<WorkerClients>::From(
+ *worker_clients, WorkerFetchContextInfo::SupplementName()));
+ if (!context_info)
+ return nullptr;
+ std::unique_ptr<WebWorkerFetchContext> web_context =
+ context_info->TakeContext();
+ DCHECK(web_context);
+ return new WorkerFetchContext(std::move(web_context));
+}
+
+WorkerFetchContext::WorkerFetchContext(
+ std::unique_ptr<WebWorkerFetchContext> web_context)
+ : web_context_(std::move(web_context)) {
+ web_context_->InitializeOnWorkerThread(Platform::Current()
+ ->CurrentThread()
+ ->Scheduler()
+ ->LoadingTaskRunner()
+ ->ToSingleThreadTaskRunner());
+}
+
+WebURLLoader* WorkerFetchContext::CreateURLLoader() {
+ return web_context_->CreateURLLoader();
+}
+
+bool WorkerFetchContext::IsControlledByServiceWorker() const {
+ return web_context_->IsControlledByServiceWorker();
+}
+
+void WorkerFetchContext::PrepareRequest(ResourceRequest& request,
+ RedirectType) {
+ WrappedResourceRequest webreq(request);
+ web_context_->WillSendRequest(webreq);
+}
+
+void ProvideWorkerFetchContextToWorker(
+ WorkerClients* clients,
+ std::unique_ptr<WebWorkerFetchContext> web_context) {
+ DCHECK(clients);
+ WorkerFetchContextInfo::ProvideTo(
+ *clients, WorkerFetchContextInfo::SupplementName(),
+ new WorkerFetchContextInfo(std::move(web_context)));
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698