| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/fetch/DataConsumerTee.h" | 5 #include "modules/fetch/DataConsumerTee.h" |
| 6 | 6 |
| 7 #include "core/dom/ActiveDOMObject.h" | 7 #include "core/dom/ActiveDOMObject.h" |
| 8 #include "core/dom/ExecutionContext.h" | 8 #include "core/dom/ExecutionContext.h" |
| 9 #include "modules/fetch/DataConsumerHandleUtil.h" | 9 #include "modules/fetch/DataConsumerHandleUtil.h" |
| 10 #include "modules/fetch/FetchBlobDataConsumerHandle.h" | 10 #include "modules/fetch/FetchBlobDataConsumerHandle.h" |
| 11 #include "platform/Task.h" | |
| 12 #include "platform/ThreadSafeFunctional.h" | 11 #include "platform/ThreadSafeFunctional.h" |
| 13 #include "platform/heap/Handle.h" | 12 #include "platform/heap/Handle.h" |
| 14 #include "public/platform/Platform.h" | 13 #include "public/platform/Platform.h" |
| 14 #include "public/platform/WebTaskRunner.h" |
| 15 #include "public/platform/WebThread.h" | 15 #include "public/platform/WebThread.h" |
| 16 #include "public/platform/WebTraceLocation.h" | 16 #include "public/platform/WebTraceLocation.h" |
| 17 #include "wtf/Deque.h" | 17 #include "wtf/Deque.h" |
| 18 #include "wtf/Functional.h" | 18 #include "wtf/Functional.h" |
| 19 #include "wtf/ThreadSafeRefCounted.h" | 19 #include "wtf/ThreadSafeRefCounted.h" |
| 20 #include "wtf/ThreadingPrimitives.h" | 20 #include "wtf/ThreadingPrimitives.h" |
| 21 #include "wtf/Vector.h" | 21 #include "wtf/Vector.h" |
| 22 | 22 |
| 23 namespace blink { | 23 namespace blink { |
| 24 | 24 |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 void notify() | 176 void notify() |
| 177 { | 177 { |
| 178 { | 178 { |
| 179 MutexLocker locker(m_mutex); | 179 MutexLocker locker(m_mutex); |
| 180 if (!m_client) { | 180 if (!m_client) { |
| 181 // No client is registered. | 181 // No client is registered. |
| 182 return; | 182 return; |
| 183 } | 183 } |
| 184 ASSERT(m_readerThread); | 184 ASSERT(m_readerThread); |
| 185 if (!m_readerThread->isCurrentThread()) { | 185 if (!m_readerThread->isCurrentThread()) { |
| 186 m_readerThread->taskRunner()->postTask(BLINK_FROM_HERE, new Task
(threadSafeBind(&DestinationContext::notify, this))); | 186 m_readerThread->taskRunner()->postTask(BLINK_FROM_HERE, threadSa
feBind(&DestinationContext::notify, this)); |
| 187 return; | 187 return; |
| 188 } | 188 } |
| 189 } | 189 } |
| 190 // The reading thread is the current thread. | 190 // The reading thread is the current thread. |
| 191 if (m_client) | 191 if (m_client) |
| 192 m_client->didGetReadable(); | 192 m_client->didGetReadable(); |
| 193 } | 193 } |
| 194 | 194 |
| 195 Mutex& mutex() { return m_mutex; } | 195 Mutex& mutex() { return m_mutex; } |
| 196 | 196 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 public: | 263 public: |
| 264 DestinationReader(PassRefPtr<DestinationContext::Proxy> contextProxy, WebDat
aConsumerHandle::Client* client) | 264 DestinationReader(PassRefPtr<DestinationContext::Proxy> contextProxy, WebDat
aConsumerHandle::Client* client) |
| 265 : m_contextProxy(contextProxy) | 265 : m_contextProxy(contextProxy) |
| 266 { | 266 { |
| 267 MutexLocker locker(context()->mutex()); | 267 MutexLocker locker(context()->mutex()); |
| 268 context()->attachReader(client); | 268 context()->attachReader(client); |
| 269 if (client) { | 269 if (client) { |
| 270 // We need to use threadSafeBind here to retain the context. Note | 270 // We need to use threadSafeBind here to retain the context. Note |
| 271 // |context()| return value is of type DestinationContext*, not | 271 // |context()| return value is of type DestinationContext*, not |
| 272 // PassRefPtr<DestinationContext>. | 272 // PassRefPtr<DestinationContext>. |
| 273 Platform::current()->currentThread()->taskRunner()->postTask(BLINK_F
ROM_HERE, new Task(threadSafeBind(&DestinationContext::notify, context()))); | 273 Platform::current()->currentThread()->taskRunner()->postTask(BLINK_F
ROM_HERE, threadSafeBind(&DestinationContext::notify, context())); |
| 274 } | 274 } |
| 275 } | 275 } |
| 276 ~DestinationReader() override | 276 ~DestinationReader() override |
| 277 { | 277 { |
| 278 MutexLocker locker(context()->mutex()); | 278 MutexLocker locker(context()->mutex()); |
| 279 context()->detachReader(); | 279 context()->detachReader(); |
| 280 } | 280 } |
| 281 | 281 |
| 282 Result beginRead(const void** buffer, Flags, size_t* available) override | 282 Result beginRead(const void** buffer, Flags, size_t* available) override |
| 283 { | 283 { |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 } | 424 } |
| 425 | 425 |
| 426 OwnPtr<WebDataConsumerHandle> webDest1, webDest2; | 426 OwnPtr<WebDataConsumerHandle> webDest1, webDest2; |
| 427 DataConsumerTee::create(executionContext, static_cast<PassOwnPtr<WebDataCons
umerHandle>>(src), &webDest1, &webDest2); | 427 DataConsumerTee::create(executionContext, static_cast<PassOwnPtr<WebDataCons
umerHandle>>(src), &webDest1, &webDest2); |
| 428 *dest1 = createFetchDataConsumerHandleFromWebHandle(webDest1.release()); | 428 *dest1 = createFetchDataConsumerHandleFromWebHandle(webDest1.release()); |
| 429 *dest2 = createFetchDataConsumerHandleFromWebHandle(webDest2.release()); | 429 *dest2 = createFetchDataConsumerHandleFromWebHandle(webDest2.release()); |
| 430 return; | 430 return; |
| 431 } | 431 } |
| 432 | 432 |
| 433 } // namespace blink | 433 } // namespace blink |
| OLD | NEW |