Chromium Code Reviews| 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..e0c6f71590e0edd9ed279a04aa939c3d465a03e3 100644 |
| --- a/third_party/WebKit/Source/modules/fetch/CompositeDataConsumerHandle.cpp |
| +++ b/third_party/WebKit/Source/modules/fetch/CompositeDataConsumerHandle.cpp |
| @@ -37,40 +37,40 @@ public: |
| static PassRefPtr<Context> create(std::unique_ptr<WebDataConsumerHandle> handle) { return adoptRef(new Context(std::move(handle))); } |
| ~Context() |
| { |
| - DCHECK(!m_readerThread); |
| + DCHECK(!m_readerTaskRunner); |
| 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(); |
| + m_readerTaskRunner = client->getTaskRunner()->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 +80,12 @@ public: |
| Result read(void* data, size_t size, Flags flags, size_t* readSize) |
| { |
| - DCHECK(m_readerThread && m_readerThread->isCurrentThread()); |
| + DCHECK(m_readerTaskRunner && 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 && m_readerTaskRunner->runsTasksOnCurrentThread()); |
| DCHECK(!m_isInTwoPhaseRead); |
| Result r = m_reader->beginRead(buffer, flags, available); |
| m_isInTwoPhaseRead = (r == Ok); |
| @@ -93,7 +93,7 @@ public: |
| } |
| Result endRead(size_t readSize) |
| { |
| - DCHECK(m_readerThread && m_readerThread->isCurrentThread()); |
| + DCHECK(m_readerTaskRunner && m_readerTaskRunner->runsTasksOnCurrentThread()); |
| DCHECK(m_isInTwoPhaseRead); |
| Result r = m_reader->endRead(readSize); |
| m_isInTwoPhaseRead = false; |
| @@ -110,7 +110,7 @@ public: |
| private: |
| explicit 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 +128,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 +142,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; |
|
haraken
2016/07/28 09:19:30
Instead of holding a task runner, can we probably
tzik
2016/07/28 14:45:34
Since m_client is nullable and we need to use it e
|
| Client* m_client; |
| Token m_token; |
| // These boolean values are bound to the reader thread. |