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

Unified Diff: third_party/WebKit/Source/core/workers/ParentFrameTaskRunners.cpp

Issue 2236833002: Pass per-frame task runners to Workers (when possible) [2nd try] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase, lifecycle observer + TaskType Created 4 years, 4 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/workers/ParentFrameTaskRunners.cpp
diff --git a/third_party/WebKit/Source/core/workers/ParentFrameTaskRunners.cpp b/third_party/WebKit/Source/core/workers/ParentFrameTaskRunners.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..c18865f5930bfb38bf7c03cefa022005678b617d
--- /dev/null
+++ b/third_party/WebKit/Source/core/workers/ParentFrameTaskRunners.cpp
@@ -0,0 +1,76 @@
+// Copyright 2016 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/workers/ParentFrameTaskRunners.h"
+
+#include "core/dom/ContextLifecycleObserver.h"
+#include "core/dom/Document.h"
+#include "wtf/Assertions.h"
+
+namespace blink {
+
+class ParentFrameTaskRunners::Observer final : public GarbageCollected<Observer>, public ContextLifecycleObserver {
haraken 2016/08/11 14:57:43 I'd use LocalFrameLifecycleObserver instead, since
kinuko 2016/08/11 23:21:37 Wanted to make it an observer only in in-process c
+ USING_GARBAGE_COLLECTED_MIXIN(Observer);
+public:
+ Observer(ParentFrameTaskRunners* owner, Document* document)
+ : ContextLifecycleObserver(document)
+ , m_owner(owner)
+ {
+ }
+
+ void contextDestroyed() override
+ {
+ m_owner->contextDestroyed();
+ }
+
+ DEFINE_INLINE_VIRTUAL_TRACE()
+ {
+ ContextLifecycleObserver::trace(visitor);
+ }
+
+ ParentFrameTaskRunners* m_owner;
+};
+
+ParentFrameTaskRunners::~ParentFrameTaskRunners()
+{
+}
+
+WebTaskRunner* ParentFrameTaskRunners::get(TaskType type)
haraken 2016/08/11 14:57:43 Nit: I'd rename this to ParentFrameTaskRunnerHelpe
kinuko 2016/08/11 23:21:37 I slightly prefer the current name as this class a
+{
+ // For now we only support most basic three task types for workers.
+ // (Probably some unthrottled tasks should be moved to Internal type)
haraken 2016/08/11 14:57:42 Yeah, our plan is to limit the unthrottled task ru
kinuko 2016/08/11 23:21:37 I agree, but wanted to avoid mixing up additional
+ switch (type) {
+ case TaskType::Networking:
+ return m_loadingTaskRunner;
+ case TaskType::Unthrottled:
+ return m_unthrottledTaskRunner;
+ case TaskType::Timer:
+ return m_timerTaskRunner;
+ default:
+ NOTREACHED();
+ }
+ return nullptr;
+}
+
+ParentFrameTaskRunners::ParentFrameTaskRunners(Document* document)
haraken 2016/08/11 14:57:43 Would it make more sense to change the parameter f
kinuko 2016/08/11 23:21:37 For out-of-process workers taking LocalFrame feels
+ : m_unthrottledTaskRunner(TaskRunnerHelper::getUnthrottledTaskRunner(document))
+ , m_timerTaskRunner(TaskRunnerHelper::getTimerTaskRunner(document))
+ , m_loadingTaskRunner(TaskRunnerHelper::getLoadingTaskRunner(document))
+{
+ if (!document)
+ return;
+
+ m_observer = new Observer(this, document);
+ DCHECK(document->isContextThread());
+}
+
+void ParentFrameTaskRunners::contextDestroyed()
haraken 2016/08/11 14:57:43 Wouldn't contextDestroyed() (called by the main th
kinuko 2016/08/11 23:21:36 Done.
+{
+ Document* document = nullptr;
+ m_unthrottledTaskRunner = TaskRunnerHelper::getUnthrottledTaskRunner(document);
haraken 2016/08/11 14:57:43 Note that these APIs are deprecated. Use TaskRunne
kinuko 2016/08/11 23:21:37 Yep, I cut corners before I get initial feedback.
+ m_timerTaskRunner = TaskRunnerHelper::getTimerTaskRunner(document);
+ m_loadingTaskRunner = TaskRunnerHelper::getLoadingTaskRunner(document);
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698