Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 | 25 |
| 26 #include "config.h" | 26 #include "config.h" |
| 27 | 27 |
| 28 #include "platform/graphics/ThreadSafeDataTransport.h" | 28 #include "platform/graphics/ThreadSafeDataTransport.h" |
| 29 | 29 |
| 30 #include "platform/SharedBuffer.h" | 30 #include "platform/SharedBuffer.h" |
| 31 | 31 |
| 32 namespace blink { | 32 namespace blink { |
| 33 | 33 |
| 34 ThreadSafeDataTransport::ThreadSafeDataTransport() | 34 ThreadSafeDataTransport::ThreadSafeDataTransport() |
| 35 : m_readBuffer(SharedBuffer::create()) | 35 : m_newAllDataReceived(false) |
| 36 , m_readBuffer(SharedBuffer::create()) | |
| 36 , m_allDataReceived(false) | 37 , m_allDataReceived(false) |
| 37 , m_readPosition(0) | 38 , m_readPosition(0) |
| 38 { | 39 { |
| 39 } | 40 } |
| 40 | 41 |
| 41 ThreadSafeDataTransport::~ThreadSafeDataTransport() | 42 ThreadSafeDataTransport::~ThreadSafeDataTransport() |
| 42 { | 43 { |
| 43 } | 44 } |
| 44 | 45 |
| 45 void ThreadSafeDataTransport::setData(SharedBuffer* buffer, bool allDataReceived ) | 46 void ThreadSafeDataTransport::setData(SharedBuffer* buffer, bool allDataReceived ) |
| 46 { | 47 { |
| 47 ASSERT(buffer->size() >= m_readPosition); | 48 ASSERT(buffer->size() >= m_readPosition); |
| 48 Vector<RefPtr<SharedBuffer>> newBufferQueue; | 49 Vector<RefPtr<SharedBuffer>> newBufferQueue; |
| 49 | 50 |
| 50 const char* segment = 0; | 51 const char* segment = 0; |
| 51 while (size_t length = buffer->getSomeData(segment, m_readPosition)) { | 52 while (size_t length = buffer->getSomeData(segment, m_readPosition)) { |
| 52 m_readPosition += length; | 53 m_readPosition += length; |
| 53 newBufferQueue.append(SharedBuffer::create(segment, length)); | 54 newBufferQueue.append(SharedBuffer::create(segment, length)); |
| 54 } | 55 } |
| 55 | 56 |
| 56 MutexLocker locker(m_mutex); | 57 MutexLocker locker(m_mutex); |
| 57 m_newBufferQueue.appendVector(newBufferQueue); | 58 m_newBufferQueue.appendVector(newBufferQueue); |
| 58 newBufferQueue.clear(); | 59 newBufferQueue.clear(); |
| 59 m_allDataReceived = allDataReceived; | 60 m_newAllDataReceived = allDataReceived; |
| 60 } | 61 } |
| 61 | 62 |
| 62 void ThreadSafeDataTransport::data(SharedBuffer** buffer, bool* allDataReceived) | 63 void ThreadSafeDataTransport::data(SharedBuffer** buffer, bool* allDataReceived) |
| 63 { | 64 { |
| 64 ASSERT(buffer); | 65 ASSERT(buffer); |
| 65 ASSERT(allDataReceived); | 66 ASSERT(allDataReceived); |
| 66 Vector<RefPtr<SharedBuffer>> newBufferQueue; | 67 Vector<RefPtr<SharedBuffer>> newBufferQueue; |
| 67 { | 68 { |
| 68 MutexLocker lock(m_mutex); | 69 MutexLocker lock(m_mutex); |
| 69 m_newBufferQueue.swap(newBufferQueue); | 70 m_newBufferQueue.swap(newBufferQueue); |
| 70 *allDataReceived = m_allDataReceived; | 71 if (m_allDataReceived && newBufferQueue.size()) { |
|
aleksandar.stojiljkovic
2015/12/02 20:33:34
Nice find. This was handled here, but after ref co
| |
| 72 // This prevents from unexisting use case now - if alldata was previ ously | |
| 73 // received, don't append but start new buffer and leave reference c ounting | |
| 74 // to handle previous buffer disposal. | |
| 75 ASSERT(false); | |
| 76 m_readBuffer = SharedBuffer::create(); | |
| 77 } | |
| 78 *allDataReceived = m_allDataReceived = m_newAllDataReceived; | |
| 71 } | 79 } |
| 72 for (size_t i = 0; i < newBufferQueue.size(); ++i) | 80 for (size_t i = 0; i < newBufferQueue.size(); ++i) |
| 73 m_readBuffer->append(newBufferQueue[i].get()); | 81 m_readBuffer->append(newBufferQueue[i].get()); |
| 74 *buffer = m_readBuffer.get(); | 82 *buffer = m_readBuffer.get(); |
| 75 } | 83 } |
| 76 | 84 |
| 77 bool ThreadSafeDataTransport::hasNewData() | 85 bool ThreadSafeDataTransport::hasNewData() |
| 78 { | 86 { |
| 79 MutexLocker lock(m_mutex); | 87 MutexLocker lock(m_mutex); |
| 80 return !m_newBufferQueue.isEmpty(); | 88 return !m_newBufferQueue.isEmpty(); |
| 81 } | 89 } |
| 82 | 90 |
| 83 } // namespace blink | 91 } // namespace blink |
| OLD | NEW |