1/* 2 * Copyright (C) 2013 Company 100 Inc. 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Lesser General Public 6 * License as published by the Free Software Foundation; either 7 * version 2 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public 15 * License along with this library; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 */ 18 19#include "config.h" 20 21#if USE(SOUP) 22 23#include "SharedBuffer.h" 24 25#include "PurgeableBuffer.h" 26#include <libsoup/soup.h> 27 28namespace WebCore { 29 30SharedBuffer::SharedBuffer(SoupBuffer* soupBuffer) 31 : m_size(0) 32 , m_soupBuffer(soupBuffer) 33{ 34 ASSERT(soupBuffer); 35} 36 37PassRefPtr<SharedBuffer> SharedBuffer::wrapSoupBuffer(SoupBuffer* soupBuffer) 38{ 39 return adoptRef(new SharedBuffer(soupBuffer)); 40} 41 42void SharedBuffer::clearPlatformData() 43{ 44 m_soupBuffer.reset(); 45} 46 47void SharedBuffer::tryReplaceContentsWithPlatformBuffer(SharedBuffer*) 48{ 49 ASSERT_NOT_REACHED(); 50} 51 52void SharedBuffer::maybeTransferPlatformData() 53{ 54 if (!m_soupBuffer) 55 return; 56 57 ASSERT(!m_size); 58 59 // Hang on to the m_soupBuffer pointer in a local pointer as append() will re-enter maybeTransferPlatformData() 60 // and we need to make sure to early return when it does. 61 GUniquePtr<SoupBuffer> soupBuffer; 62 soupBuffer.swap(m_soupBuffer); 63 64 append(soupBuffer->data, soupBuffer->length); 65} 66 67bool SharedBuffer::hasPlatformData() const 68{ 69 return m_soupBuffer.get(); 70} 71 72const char* SharedBuffer::platformData() const 73{ 74 return m_soupBuffer->data; 75} 76 77unsigned SharedBuffer::platformDataSize() const 78{ 79 return m_soupBuffer->length; 80} 81 82bool SharedBuffer::maybeAppendPlatformData(SharedBuffer*) 83{ 84 return false; 85} 86 87} // namespace WebCore 88 89#endif 90