Chromium Code Reviews| 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..867030fcb3168e808059809031358409f4a4800c 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,9 @@ 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))); |
| + DCHECK(m_readerTaskRunner); |
| + if (!m_readerTaskRunner->runsTasksOnCurrentThread()) { |
| + m_readerTaskRunner->postTask(BLINK_FROM_HERE, crossThreadBind(&DestinationContext::notify, wrapPassRefPtr(this))); |
| return; |
| } |
| } |
| @@ -200,15 +201,15 @@ public: |
| // caller. |
| void attachReader(WebDataConsumerHandle::Client* client) |
| { |
| - DCHECK(!m_readerThread); |
| + DCHECK(!m_readerTaskRunner); |
| DCHECK(!m_client); |
| - m_readerThread = Platform::current()->currentThread(); |
| + m_readerTaskRunner = client->getTaskRunner()->clone(); |
| m_client = client; |
| } |
| void detachReader() |
| { |
| - DCHECK(m_readerThread && m_readerThread->isCurrentThread()); |
| - m_readerThread = nullptr; |
| + DCHECK(m_readerTaskRunner && m_readerTaskRunner->runsTasksOnCurrentThread()); |
| + m_readerTaskRunner = nullptr; |
| m_client = nullptr; |
| } |
| const std::unique_ptr<Vector<char>>& top() const { return m_queue.first(); } |
| @@ -231,7 +232,7 @@ public: |
| private: |
| DestinationContext() |
| : m_result(WebDataConsumerHandle::ShouldWait) |
| - , m_readerThread(nullptr) |
| + , m_readerTaskRunner(nullptr) |
| , m_client(nullptr) |
| , m_offset(0) |
| , m_isTwoPhaseReadInProgress(false) |
| @@ -242,19 +243,13 @@ private: |
| { |
| MutexLocker locker(m_mutex); |
| DCHECK(!m_client); |
| - DCHECK(!m_readerThread); |
| + DCHECK(!m_readerTaskRunner); |
| 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; |
| + std::unique_ptr<WebTaskRunner> m_readerTaskRunner; |
|
haraken
2016/07/28 09:19:30
Instead of holding a task runner, can we probably
tzik
2016/07/28 14:45:34
Done.
|
| WebDataConsumerHandle::Client* m_client; |
| size_t m_offset; |
| bool m_isTwoPhaseReadInProgress; |
| @@ -269,10 +264,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 +365,11 @@ public: |
| stopInternal(); |
| } |
| + WebTaskRunner* getTaskRunner() override |
| + { |
| + return TaskRunnerHelper::getUnthrottledTaskRunner(getExecutionContext()); |
| + } |
| + |
| void stop() override |
| { |
| stopInternal(); |