| Index: third_party/WebKit/Source/modules/fetch/CompositeDataConsumerHandle.cpp
|
| diff --git a/third_party/WebKit/Source/modules/fetch/CompositeDataConsumerHandle.cpp b/third_party/WebKit/Source/modules/fetch/CompositeDataConsumerHandle.cpp
|
| index 035c0b13ca463655fae6352f677e278d501f7ba0..abf0990c593a46a5e3933a209a54c30c6382be79 100644
|
| --- a/third_party/WebKit/Source/modules/fetch/CompositeDataConsumerHandle.cpp
|
| +++ b/third_party/WebKit/Source/modules/fetch/CompositeDataConsumerHandle.cpp
|
| @@ -37,40 +37,42 @@ public:
|
| static PassRefPtr<Context> create(std::unique_ptr<WebDataConsumerHandle> handle) { return adoptRef(new Context(std::move(handle))); }
|
| ~Context()
|
| {
|
| - DCHECK(!m_readerThread);
|
| DCHECK(!m_reader);
|
| DCHECK(!m_client);
|
| }
|
| std::unique_ptr<ReaderImpl> obtainReader(Client* client)
|
| {
|
| MutexLocker locker(m_mutex);
|
| - DCHECK(!m_readerThread);
|
| + DCHECK(!m_readerTaskRunner);
|
| DCHECK(!m_reader);
|
| DCHECK(!m_client);
|
| ++m_token;
|
| m_client = client;
|
| - m_readerThread = Platform::current()->currentThread();
|
| + if (client)
|
| + m_readerTaskRunner = client->getTaskRunner()->clone();
|
| + else
|
| + m_readerTaskRunner = Platform::current()->currentThread()->getWebTaskRunner()->clone();
|
| m_reader = m_handle->obtainReader(m_client);
|
| return wrapUnique(new ReaderImpl(this));
|
| }
|
| void detachReader()
|
| {
|
| MutexLocker locker(m_mutex);
|
| - DCHECK(m_readerThread);
|
| - DCHECK(m_readerThread->isCurrentThread());
|
| + DCHECK(m_readerTaskRunner);
|
| + DCHECK(m_readerTaskRunner->runsTasksOnCurrentThread());
|
| DCHECK(m_reader);
|
| DCHECK(!m_isInTwoPhaseRead);
|
| DCHECK(!m_isUpdateWaitingForEndRead);
|
| ++m_token;
|
| m_reader = nullptr;
|
| - m_readerThread = nullptr;
|
| + m_readerTaskRunner = nullptr;
|
| m_client = nullptr;
|
| }
|
| void update(std::unique_ptr<WebDataConsumerHandle> handle)
|
| {
|
| MutexLocker locker(m_mutex);
|
| m_handle = std::move(handle);
|
| - if (!m_readerThread) {
|
| + if (!m_readerTaskRunner) {
|
| // There is no reader.
|
| return;
|
| }
|
| @@ -80,12 +82,14 @@ public:
|
|
|
| Result read(void* data, size_t size, Flags flags, size_t* readSize)
|
| {
|
| - DCHECK(m_readerThread && m_readerThread->isCurrentThread());
|
| + DCHECK(m_readerTaskRunner);
|
| + DCHECK(m_readerTaskRunner->runsTasksOnCurrentThread());
|
| return m_reader->read(data, size, flags, readSize);
|
| }
|
| Result beginRead(const void** buffer, Flags flags, size_t* available)
|
| {
|
| - DCHECK(m_readerThread && m_readerThread->isCurrentThread());
|
| + DCHECK(m_readerTaskRunner);
|
| + DCHECK(m_readerTaskRunner->runsTasksOnCurrentThread());
|
| DCHECK(!m_isInTwoPhaseRead);
|
| Result r = m_reader->beginRead(buffer, flags, available);
|
| m_isInTwoPhaseRead = (r == Ok);
|
| @@ -93,7 +97,8 @@ public:
|
| }
|
| Result endRead(size_t readSize)
|
| {
|
| - DCHECK(m_readerThread && m_readerThread->isCurrentThread());
|
| + DCHECK(m_readerTaskRunner);
|
| + DCHECK(m_readerTaskRunner->runsTasksOnCurrentThread());
|
| DCHECK(m_isInTwoPhaseRead);
|
| Result r = m_reader->endRead(readSize);
|
| m_isInTwoPhaseRead = false;
|
| @@ -108,9 +113,9 @@ public:
|
| }
|
|
|
| private:
|
| - explicit Context(std::unique_ptr<WebDataConsumerHandle> handle)
|
| + Context(std::unique_ptr<WebDataConsumerHandle> handle)
|
| : m_handle(std::move(handle))
|
| - , m_readerThread(nullptr)
|
| + , m_readerTaskRunner(nullptr)
|
| , m_client(nullptr)
|
| , m_token(0)
|
| , m_isUpdateWaitingForEndRead(false)
|
| @@ -128,9 +133,9 @@ private:
|
| // This request is not fresh. Ignore it.
|
| return;
|
| }
|
| - DCHECK(m_readerThread);
|
| + DCHECK(m_readerTaskRunner);
|
| DCHECK(m_reader);
|
| - if (m_readerThread->isCurrentThread()) {
|
| + if (m_readerTaskRunner->runsTasksOnCurrentThread()) {
|
| if (m_isInTwoPhaseRead) {
|
| // We are waiting for the two-phase read completion.
|
| m_isUpdateWaitingForEndRead = true;
|
| @@ -142,18 +147,12 @@ private:
|
| return;
|
| }
|
| ++m_token;
|
| - m_readerThread->getWebTaskRunner()->postTask(BLINK_FROM_HERE, crossThreadBind(&Context::updateReader, wrapPassRefPtr(this), m_token));
|
| + m_readerTaskRunner->postTask(BLINK_FROM_HERE, crossThreadBind(&Context::updateReader, wrapPassRefPtr(this), m_token));
|
| }
|
|
|
| std::unique_ptr<Reader> m_reader;
|
| std::unique_ptr<WebDataConsumerHandle> m_handle;
|
| - // 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;
|
| Client* m_client;
|
| Token m_token;
|
| // These boolean values are bound to the reader thread.
|
|
|