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

Side by Side Diff: third_party/WebKit/Source/core/loader/ThreadableLoadingContext.cpp

Issue 2701753003: [WIP] off-main-thread loading
Patch Set: small fix 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 unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 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/loader/ThreadableLoadingContext.h" 5 #include "core/loader/ThreadableLoadingContext.h"
6 6
7 #include "core/dom/Document.h" 7 #include "core/dom/Document.h"
8 #include "core/dom/TaskRunnerHelper.h" 8 #include "core/dom/TaskRunnerHelper.h"
9 #include "core/loader/WorkerFetchContext.h"
10 #include "core/workers/WorkerGlobalScope.h"
9 #include "platform/loader/fetch/ResourceFetcher.h" 11 #include "platform/loader/fetch/ResourceFetcher.h"
10 12
11 namespace blink { 13 namespace blink {
12 14
13 class DocumentThreadableLoadingContext final : public ThreadableLoadingContext { 15 class DocumentThreadableLoadingContext final : public ThreadableLoadingContext {
14 public: 16 public:
15 explicit DocumentThreadableLoadingContext(Document& document) 17 explicit DocumentThreadableLoadingContext(Document& document)
16 : m_document(&document) {} 18 : m_document(&document) {}
17 19
18 ~DocumentThreadableLoadingContext() override = default; 20 ~DocumentThreadableLoadingContext() override = default;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 63
62 DEFINE_INLINE_VIRTUAL_TRACE() { 64 DEFINE_INLINE_VIRTUAL_TRACE() {
63 visitor->trace(m_document); 65 visitor->trace(m_document);
64 ThreadableLoadingContext::trace(visitor); 66 ThreadableLoadingContext::trace(visitor);
65 } 67 }
66 68
67 private: 69 private:
68 Member<Document> m_document; 70 Member<Document> m_document;
69 }; 71 };
70 72
73 class WorkerThreadableLoadingContext : public ThreadableLoadingContext {
74 public:
75 explicit WorkerThreadableLoadingContext(WorkerGlobalScope& workerGlobalScope)
76 : m_workerGlobalScope(&workerGlobalScope),
77 m_fetchContext(WorkerFetchContext::from(workerGlobalScope)) {}
78
79 ~WorkerThreadableLoadingContext() override = default;
80
81 bool isContextThread() const override {
82 DCHECK(m_fetchContext);
83 DCHECK(m_workerGlobalScope);
84 return m_workerGlobalScope->isContextThread();
85 }
86
87 ResourceFetcher* getResourceFetcher() override {
88 DCHECK(isContextThread());
89 return m_fetchContext->getResourceFetcher();
90 }
91
92 SecurityOrigin* getSecurityOrigin() override {
93 DCHECK(isContextThread());
94 return m_workerGlobalScope->getSecurityOrigin();
95 }
96
97 bool isSecureContext() const override {
98 DCHECK(isContextThread());
99 String errorMessage;
100 return m_workerGlobalScope->isSecureContext(errorMessage);
101 }
102
103 KURL firstPartyForCookies() const override {
104 DCHECK(isContextThread());
105 // TODO
106 return m_workerGlobalScope->url();
107 }
108
109 String userAgent() const override {
110 DCHECK(isContextThread());
111 return m_workerGlobalScope->userAgent();
112 }
113
114 Document* getLoadingDocument() override { return nullptr; }
115
116 RefPtr<WebTaskRunner> getTaskRunner(TaskType type) override {
117 switch (type) {
118 case TaskType::Timer:
119 return m_fetchContext->timerTaskRunner();
120 case TaskType::UnspecedLoading:
121 case TaskType::Networking:
122 return m_fetchContext->loadingTaskRunner();
123 default:
124 return TaskRunnerHelper::get(type, getLoadingDocument());
125 }
126 }
127
128 void recordUseCount(UseCounter::Feature feature) override {
129 UseCounter::count(m_workerGlobalScope, feature);
130 }
131
132 DEFINE_INLINE_VIRTUAL_TRACE() {
133 visitor->trace(m_fetchContext);
134 visitor->trace(m_workerGlobalScope);
135 ThreadableLoadingContext::trace(visitor);
136 }
137
138 private:
139 Member<WorkerGlobalScope> m_workerGlobalScope;
140 Member<WorkerFetchContext> m_fetchContext;
141 };
142
71 ThreadableLoadingContext* ThreadableLoadingContext::create(Document& document) { 143 ThreadableLoadingContext* ThreadableLoadingContext::create(Document& document) {
72 // For now this is the only default implementation. 144 // For now this is the only default implementation.
73 return new DocumentThreadableLoadingContext(document); 145 return new DocumentThreadableLoadingContext(document);
74 } 146 }
75 147
148 ThreadableLoadingContext* ThreadableLoadingContext::create(
149 WorkerGlobalScope& workerGlobalScope) {
150 return new WorkerThreadableLoadingContext(workerGlobalScope);
151 }
152
76 } // namespace blink 153 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698