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

Unified Diff: third_party/WebKit/Source/modules/fetch/DataConsumerTee.cpp

Issue 2177243002: Use per-frame TaskRunner instead of thread's default in DataConsumerHandle (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@data_consumer_handle_unique_ptr
Patch Set: update Created 4 years, 5 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/modules/fetch/DataConsumerTee.cpp
diff --git a/third_party/WebKit/Source/modules/fetch/DataConsumerTee.cpp b/third_party/WebKit/Source/modules/fetch/DataConsumerTee.cpp
index 8b335d42f85c5b98c7573833af61f6d1e61c465a..22e56fa795262820676fc499916122fa5d9c4f5e 100644
--- a/third_party/WebKit/Source/modules/fetch/DataConsumerTee.cpp
+++ b/third_party/WebKit/Source/modules/fetch/DataConsumerTee.cpp
@@ -6,6 +6,7 @@
#include "core/dom/ActiveDOMObject.h"
#include "core/dom/ExecutionContext.h"
+#include "core/dom/TaskRunnerHelper.h"
#include "modules/fetch/DataConsumerHandleUtil.h"
#include "modules/fetch/FetchBlobDataConsumerHandle.h"
#include "platform/CrossThreadFunctional.h"
@@ -183,9 +184,8 @@ public:
// No client is registered.
return;
}
- DCHECK(m_readerThread);
- if (!m_readerThread->isCurrentThread()) {
- m_readerThread->getWebTaskRunner()->postTask(BLINK_FROM_HERE, crossThreadBind(&DestinationContext::notify, wrapPassRefPtr(this)));
+ if (!m_client->getTaskRunner()->runsTasksOnCurrentThread()) {
+ m_client->getTaskRunner()->postTask(BLINK_FROM_HERE, crossThreadBind(&DestinationContext::notify, wrapPassRefPtr(this)));
return;
}
}
@@ -200,15 +200,12 @@ public:
// caller.
void attachReader(WebDataConsumerHandle::Client* client)
{
- DCHECK(!m_readerThread);
DCHECK(!m_client);
- m_readerThread = Platform::current()->currentThread();
m_client = client;
}
void detachReader()
{
- DCHECK(m_readerThread && m_readerThread->isCurrentThread());
- m_readerThread = nullptr;
+ DCHECK(!m_client || m_client->getTaskRunner()->runsTasksOnCurrentThread());
m_client = nullptr;
}
const std::unique_ptr<Vector<char>>& top() const { return m_queue.first(); }
@@ -231,7 +228,6 @@ public:
private:
DestinationContext()
: m_result(WebDataConsumerHandle::ShouldWait)
- , m_readerThread(nullptr)
, m_client(nullptr)
, m_offset(0)
, m_isTwoPhaseReadInProgress(false)
@@ -242,19 +238,11 @@ private:
{
MutexLocker locker(m_mutex);
DCHECK(!m_client);
- DCHECK(!m_readerThread);
m_queue.clear();
}
Result m_result;
Deque<std::unique_ptr<Vector<char>>> m_queue;
- // Note: Holding a WebThread raw pointer is not generally safe, but we can
- // do that in this case because:
- // 1. Destructing a ReaderImpl when the bound thread ends is a user's
- // responsibility.
- // 2. |m_readerThread| will never be used after the associated reader is
- // detached.
- WebThread* m_readerThread;
WebDataConsumerHandle::Client* m_client;
size_t m_offset;
bool m_isTwoPhaseReadInProgress;
@@ -269,10 +257,7 @@ public:
MutexLocker locker(context()->mutex());
context()->attachReader(client);
if (client) {
- // We need to use crossThreadBind here to retain the context. Note
- // |context()| return value is of type DestinationContext*, not
- // PassRefPtr<DestinationContext>.
- Platform::current()->currentThread()->getWebTaskRunner()->postTask(BLINK_FROM_HERE, crossThreadBind(&DestinationContext::notify, wrapPassRefPtr(context())));
+ client->getTaskRunner()->postTask(BLINK_FROM_HERE, bind(&DestinationContext::notify, wrapPassRefPtr(context())));
}
}
~DestinationReader() override
@@ -373,6 +358,11 @@ public:
stopInternal();
}
+ WebTaskRunner* getTaskRunner() override
+ {
+ return TaskRunnerHelper::getUnthrottledTaskRunner(getExecutionContext());
+ }
+
void stop() override
{
stopInternal();

Powered by Google App Engine
This is Rietveld 408576698